courseLocation: init Address context in the store

This commit is contained in:
Mathieu Jaumotte 2021-08-12 15:42:48 +02:00
parent 368bbcf9b2
commit 205c48f58a
4 changed files with 53 additions and 26 deletions

View File

@ -47,7 +47,8 @@ export default {
Confirm, Confirm,
}, },
computed: mapState([ computed: mapState([
'accompanyingCourse' 'accompanyingCourse',
'addressContext'
]) ])
}; };
</script> </script>

View File

@ -27,8 +27,8 @@
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<add-address <add-address
v-bind:key="addAddress.type"
v-bind:context="context" v-bind:context="context"
v-bind:key="addAddress.type"
v-bind:options="addAddress.options" v-bind:options="addAddress.options"
v-bind:result="addAddress.result" v-bind:result="addAddress.result"
ref="addAddress"> ref="addAddress">
@ -41,6 +41,7 @@
</template> </template>
<script> <script>
import { mapState } from "vuex";
import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress.vue'; import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress.vue';
export default { export default {
@ -50,25 +51,21 @@ export default {
}, },
data() { data() {
return { return {
context: {
edit: true, //dynamic //window.mode === 'edit',
personId: null, //window.personId,
addressId: null, //window.addressId,
backUrl: null //window.backUrl,
},
addAddress: { addAddress: {
options: { options: {
/// Options override default. /// Options override default.
/// null value take default component value /// null value take default component value
button: { button: {
text: { create: null, edit: null }, text: {
type: null, create: 'courselocation.add_temporary_address',
size: null, edit: 'courselocation.edit_temporary_address'
//display: false },
},
title: {
create: 'courselocation.add_temporary_address',
edit: 'courselocation.edit_temporary_address'
}, },
/// Modal title text if create or edit address (trans chain, see i18n)
title: { create: null, edit: null },
/// Display each step in page or Modal /// Display each step in page or Modal
bindModal: { bindModal: {
//step1: false, step2: false //step1: false, step2: false
@ -77,15 +74,39 @@ export default {
displayResult: true, displayResult: true,
redirectToBackUrl: false redirectToBackUrl: false
}, },
type: 'courseLocation', type: 'accompanying_course_location',
result: null // <== returned from addAddress component result: null // <== returned from addAddress component
} }
} }
}, },
computed: {
...mapState({
accompanyingCourse: state => state.accompanyingCourse,
context: state => state.addressContext
})
},
methods: { methods: {
initAddressContext() {
let ac = {
entity: {
type: this.accompanyingCourse.type,
id: this.accompanyingCourse.id
},
edit: false,
addressId: null,
backUrl: null
}
this.$store.commit('setAddressContext', ac);
},
displayErrors() { displayErrors() {
return this.$refs.addAddress.errorMsg; return this.$refs.addAddress.errorMsg;
} }
},
mounted() {
this.initAddressContext();
console.log('ac.locationStatus', this.accompanyingCourse.locationStatus);
console.log('ac.location (temporary location)', this.accompanyingCourse.location);
console.log('ac.personLocation', this.accompanyingCourse.personLocation);
} }
} }
</script> </script>

View File

@ -65,8 +65,8 @@ const appMessages = {
}, },
courselocation: { courselocation: {
title: "Localisation du parcours", title: "Localisation du parcours",
add_temp_address: "Ajouter une adresse temporaire", add_temporary_address: "Ajouter une adresse temporaire",
edit_temp_address: "Modifier l'adresse temporaire", edit_temporary_address: "Modifier l'adresse temporaire",
assign_course_address: "Désigner comme l'adresse du parcours", assign_course_address: "Désigner comme l'adresse du parcours",
}, },
referrer: { referrer: {

View File

@ -1,9 +1,9 @@
import 'es6-promise/auto'; import 'es6-promise/auto';
import { createStore } from 'vuex'; import { createStore } from 'vuex';
import { getAccompanyingCourse, import { getAccompanyingCourse,
patchAccompanyingCourse, patchAccompanyingCourse,
confirmAccompanyingCourse, confirmAccompanyingCourse,
postParticipation, postParticipation,
postRequestor, postRequestor,
postResource, postResource,
postSocialIssue } from '../api'; postSocialIssue } from '../api';
@ -13,20 +13,21 @@ const id = window.accompanyingCourseId;
let initPromise = getAccompanyingCourse(id) let initPromise = getAccompanyingCourse(id)
.then(accompanying_course => new Promise((resolve, reject) => { .then(accompanying_course => new Promise((resolve, reject) => {
const store = createStore({ const store = createStore({
strict: debug, strict: debug,
modules: { modules: {
}, },
state: { state: {
accompanyingCourse: accompanying_course, accompanyingCourse: accompanying_course,
addressContext: {},
errorMsg: [] errorMsg: []
}, },
getters: { getters: {
}, },
mutations: { mutations: {
catchError(state, error) { catchError(state, error) {
state.errorMsg.push(error); state.errorMsg.push(error);
}, },
removeParticipation(state, participation) { removeParticipation(state, participation) {
//console.log('### mutation: remove participation', participation.id); //console.log('### mutation: remove participation', participation.id);
@ -77,7 +78,7 @@ let initPromise = getAccompanyingCourse(id)
postFirstComment(state, comment) { postFirstComment(state, comment) {
//console.log('### mutation: postFirstComment', comment); //console.log('### mutation: postFirstComment', comment);
state.accompanyingCourse.initialComment = comment; state.accompanyingCourse.initialComment = comment;
}, },
updateSocialIssues(state, value) { updateSocialIssues(state, value) {
state.accompanyingCourse.socialIssues = value; state.accompanyingCourse.socialIssues = value;
}, },
@ -92,6 +93,10 @@ let initPromise = getAccompanyingCourse(id)
confirmAccompanyingCourse(state, response) { confirmAccompanyingCourse(state, response) {
//console.log('### mutation: confirmAccompanyingCourse: response', response); //console.log('### mutation: confirmAccompanyingCourse: response', response);
state.accompanyingCourse.step = response.step; state.accompanyingCourse.step = response.step;
},
setAddressContext(state, context) {
//console.log('define location context');
state.addressContext = context;
} }
}, },
actions: { actions: {
@ -105,7 +110,7 @@ let initPromise = getAccompanyingCourse(id)
.then(participation => new Promise((resolve, reject) => { .then(participation => new Promise((resolve, reject) => {
commit('closeParticipation', { participation, payload }); commit('closeParticipation', { participation, payload });
resolve(); resolve();
})).catch((error) => { commit('catchError', error) }); })).catch((error) => { commit('catchError', error) });
}, },
addParticipation({ commit }, payload) { addParticipation({ commit }, payload) {
//console.log('## action: fetch post participation (select item): payload', payload); //console.log('## action: fetch post participation (select item): payload', payload);
@ -113,7 +118,7 @@ let initPromise = getAccompanyingCourse(id)
.then(participation => new Promise((resolve, reject) => { .then(participation => new Promise((resolve, reject) => {
commit('addParticipation', participation); commit('addParticipation', participation);
resolve(); resolve();
})).catch((error) => { commit('catchError', error) }); })).catch((error) => { commit('catchError', error) });
}, },
removeRequestor({ commit, dispatch }) { removeRequestor({ commit, dispatch }) {
//console.log('## action: fetch delete requestor'); //console.log('## action: fetch delete requestor');
@ -122,7 +127,7 @@ let initPromise = getAccompanyingCourse(id)
commit('removeRequestor'); commit('removeRequestor');
dispatch('requestorIsAnonymous', false); dispatch('requestorIsAnonymous', false);
resolve(); resolve();
})).catch((error) => { commit('catchError', error) }); })).catch((error) => { commit('catchError', error) });
}, },
addRequestor({ commit }, payload) { addRequestor({ commit }, payload) {
//console.log('## action: fetch post requestor: payload', payload); //console.log('## action: fetch post requestor: payload', payload);
@ -130,7 +135,7 @@ let initPromise = getAccompanyingCourse(id)
.then(requestor => new Promise((resolve, reject) => { .then(requestor => new Promise((resolve, reject) => {
commit('addRequestor', requestor); commit('addRequestor', requestor);
resolve(); resolve();
})).catch((error) => { commit('catchError', error) }); })).catch((error) => { commit('catchError', error) });
}, },
requestorIsAnonymous({ commit }, payload) { requestorIsAnonymous({ commit }, payload) {
//console.log('## action: fetch patch AccompanyingCourse: payload', payload); //console.log('## action: fetch patch AccompanyingCourse: payload', payload);