Skip to content
Snippets Groups Projects
Commit e9032607 authored by Timothee P's avatar Timothee P :sunflower:
Browse files

Display message and redirect only after all features have been modified

parent b51079d5
Branches
Tags
No related merge requests found
......@@ -191,7 +191,8 @@ const feature = {
},
SEND_FEATURE({ state, rootState, commit, dispatch }, routeName) {
function redirect(featureId, featureName) {
function redirect(featureId, featureName, response) {
if (routeName === 'editer-attribut-signalement') return response; // exit function to avoid conflict with next feature call to GET_PROJECT_FEATURE when modifying more than 2 features
commit(
'DISPLAY_MESSAGE',
{
......@@ -202,7 +203,6 @@ const feature = {
},
{ root: true },
);
if (routeName.includes('editer-attribut-signalement')) return; // exit function to avoid conflict with next feature call to GET_PROJECT_FEATURE when modifying more than 2 features
dispatch(
'GET_PROJECT_FEATURE',
{
......@@ -210,7 +210,7 @@ const feature = {
feature_id: featureId
})
.then(() => {
if (routeName.includes('details-signalement')) return;
if (routeName === 'details-signalement') return response;
router.push({
name: 'details-signalement',
params: {
......@@ -219,12 +219,13 @@ const feature = {
},
});
});
return response;
}
async function handleOtherForms(featureId, featureName) {
async function handleOtherForms(featureId, featureName, response) {
await dispatch('SEND_ATTACHMENTS', featureId);
await dispatch('PUT_LINKED_FEATURES', featureId);
redirect(featureId, featureName);
return redirect(featureId, featureName, response);
}
function createGeojson() { //* prepare feature data to send
......@@ -270,9 +271,9 @@ const feature = {
if (state.attachmentFormset.length > 0 ||
state.linkedFormset.length > 0 ||
state.attachmentsToDelete.length > 0) {
handleOtherForms(featureId, featureName);
return handleOtherForms(featureId, featureName, response);
} else {
redirect(featureId, featureName);
return redirect(featureId, featureName, response);
}
}
})
......
......
......@@ -797,8 +797,9 @@ export default {
}
},
postForm() {
async postForm() {
let is_valid = true;
let response;
is_valid =
this.checkFormGeom() &&
this.checkAddedForm();
......@@ -817,13 +818,16 @@ export default {
this.updateStore();
}
this.sendingFeature = true;
return this.$store.dispatch('feature/SEND_FEATURE', this.currentRouteName)
.then(() => this.sendingFeature = false);
response = await this.$store.dispatch('feature/SEND_FEATURE', this.currentRouteName);
this.sendingFeature = false;
return response;
}
},
async postMultipleFeatures() {
this.$store.commit('DISPLAY_LOADER', 'Envoi des signalements en cours...');
const extraForms = [...this.extra_forms];// store extra forms for multiple features to not be overide by current feature
let results = [];
for (const featureId of this.checkedFeatures) {
const response = await this.$store.dispatch('feature/GET_PROJECT_FEATURE', {
project_slug: this.$route.params.slug,
......@@ -837,8 +841,28 @@ export default {
await this.$store.commit('feature/UPDATE_EXTRA_FORM', xtraForm);
}
}
this.postForm();
const result = await this.postForm();
results.push(result);
}
}
this.$store.commit('DISCARD_LOADER');
const errors = results.filter((res) => res === undefined || res.status !== 200);
if (errors.length > 0) {
this.$store.commit(
'DISPLAY_MESSAGE',
{
comment: 'Des signalements n\'ont pas pu être mis à jour',
level: 'negative'
},
);
} else {
this.$store.commit(
'DISPLAY_MESSAGE',
{
comment: 'Les signalements ont été mis à jour',
level: 'positive'
},
);
}
this.$router.push({
name: 'liste-signalements',
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment