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,
},
computed: mapState([
'accompanyingCourse'
'accompanyingCourse',
'addressContext'
])
};
</script>

View File

@ -27,8 +27,8 @@
<ul class="record_actions">
<li>
<add-address
v-bind:key="addAddress.type"
v-bind:context="context"
v-bind:key="addAddress.type"
v-bind:options="addAddress.options"
v-bind:result="addAddress.result"
ref="addAddress">
@ -41,6 +41,7 @@
</template>
<script>
import { mapState } from "vuex";
import AddAddress from 'ChillMainAssets/vuejs/Address/components/AddAddress.vue';
export default {
@ -50,25 +51,21 @@ export default {
},
data() {
return {
context: {
edit: true, //dynamic //window.mode === 'edit',
personId: null, //window.personId,
addressId: null, //window.addressId,
backUrl: null //window.backUrl,
},
addAddress: {
options: {
/// Options override default.
/// null value take default component value
button: {
text: { create: null, edit: null },
type: null,
size: null,
//display: false
text: {
create: 'courselocation.add_temporary_address',
edit: 'courselocation.edit_temporary_address'
},
},
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
bindModal: {
//step1: false, step2: false
@ -77,15 +74,39 @@ export default {
displayResult: true,
redirectToBackUrl: false
},
type: 'courseLocation',
type: 'accompanying_course_location',
result: null // <== returned from addAddress component
}
}
},
computed: {
...mapState({
accompanyingCourse: state => state.accompanyingCourse,
context: state => state.addressContext
})
},
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() {
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>

View File

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

View File

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