implements max holder and validation on UI

This commit is contained in:
2021-06-11 17:58:09 +02:00
parent af740fd87d
commit 807d3674fc
8 changed files with 50 additions and 38 deletions

View File

@@ -16,32 +16,13 @@ const householdMove = (payload) => {
if (response.ok) {
return response.json();
}
throw Error('Error with testing move');
});
};
const householdMoveTest = (payload) => {
const url = `/api/1.0/person/household/members/move/test.json`;
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
})
.then(response => {
if (response.status === 422) {
return response.json();
}
if (response.ok) {
// return an empty array if ok
return new Promise((resolve, reject) => resolve({ violations: [] }) );
}
throw Error('Error with testing move');
});
};
export {
householdMove,
householdMoveTest
};

View File

@@ -12,6 +12,9 @@
<li v-for="(msg, index) in warnings">
{{ $t(msg.m, msg.a) }}
</li>
<li v-for="msg in errors">
{{ msg }}
</li>
</ul>
<ul class="record_actions sticky-form-buttons">
@@ -34,8 +37,9 @@ export default {
computed: {
...mapState({
warnings: (state) => state.warnings,
hasNoWarnings: (state) => state.warnings.length === 0,
hasWarnings: (state) => state.warnings.length > 0,
errors: (state) => state.errors,
hasNoWarnings: (state) => state.warnings.length === 0 && state.errors.length === 0,
hasWarnings: (state) => state.warnings.length > 0 || state.errors.length > 0,
}),
},
methods: {

View File

@@ -26,6 +26,7 @@ const store = createStore({
allowLeaveWithoutHousehold: window.household_members_editor_data.allowLeaveWithoutHousehold,
forceLeaveWithoutHousehold: false,
warnings: [],
errors: []
},
getters: {
isHouseholdNew(state) {
@@ -162,6 +163,9 @@ const store = createStore({
setWarnings(state, warnings) {
state.warnings = warnings;
},
setErrors(state, errors) {
state.errors = errors;
},
},
actions: {
addConcerned({ commit, dispatch }, person) {
@@ -216,19 +220,33 @@ const store = createStore({
commit('setWarnings', warnings);
},
confirm({ getters, state }) {
confirm({ getters, state, commit }) {
let payload = getters.buildPayload,
errors = [],
person_id,
household_id;
householdMove(payload).then(household => {
if (household === null) {
person_id = getters.persons[0].id;
window.location.replace(`/fr/person/${person_id}/general`);
} else {
household_id = household.id;
// nothing to do anymore here, bye-bye !
window.location.replace(`/fr/person/household/${household_id}/members`);
}
household_id,
error
;
householdMove(payload).then(household => {
if (household === null) {
person_id = getters.persons[0].id;
window.location.replace(`/fr/person/${person_id}/general`);
} else {
if (household.type === 'household') {
household_id = household.id;
// nothing to do anymore here, bye-bye !
window.location.replace(`/fr/person/household/${household_id}/members`);
} else {
// we assume the answer was 422...
error = household;
for (let e in error.violations) {
errors.push('TODO');
}
commit('setErrors', errors);
}
}
});
},
}