diff --git a/src/store/modules/feature.js b/src/store/modules/feature.js index 67079e83ac176f0bbc48a085eb788aef6630ef37..eb6646b5572a64e0d9522d9d31122dc395d63a71 100644 --- a/src/store/modules/feature.js +++ b/src/store/modules/feature.js @@ -103,9 +103,12 @@ const feature = { }); }, - SEND_FEATURE({ state, rootState, dispatch }, routeName) { + SEND_FEATURE({ state, rootState, commit, dispatch }, routeName) { + commit("DISPLAY_LOADER", "Le signalement est en cours de création", { root: true }) const message = routeName === "editer-signalement" ? "Le signalement a été mis à jour" : "Le signalement a été crée"; + function redirect(featureId) { + commit("DISCARD_LOADER", null, { root: true }) router.push({ name: "details-signalement", params: { @@ -115,12 +118,14 @@ const feature = { }, }); } + async function handleOtherForms(featureId) { await dispatch("SEND_ATTACHMENTS", featureId) await dispatch("PUT_LINKED_FEATURES", featureId) redirect(featureId); } + //* prepare feature data to send let extraFormObject = {}; //* prepare an object to be flatten in properties of geojson for (const field of state.extra_form) { extraFormObject[field.name] = field.value; @@ -138,8 +143,9 @@ const feature = { ...extraFormObject } } + if (routeName === "editer-signalement") { - axios + return axios .put(`${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/${state.form.feature_id}/?` + `feature_type__slug=${rootState.feature_type.current_feature_type_slug}` + `&project__slug=${rootState.project_slug}` @@ -154,10 +160,11 @@ const feature = { } }) .catch((error) => { + commit("DISCARD_LOADER", null, { root: true }) throw error; }); } else { - axios + return axios .post(`${rootState.configuration.VUE_APP_DJANGO_API_BASE}features/`, geojson) .then((response) => { if (response.status === 201 && response.data) { @@ -169,6 +176,7 @@ const feature = { } }) .catch((error) => { + commit("DISCARD_LOADER", null, { root: true }) throw error; }); }