CourseLocation: action and mutation for updateLocation, hide button if personLocation

This commit is contained in:
Mathieu Jaumotte 2021-08-13 16:08:42 +02:00
parent f535e794a7
commit 5e0c930087
4 changed files with 51 additions and 16 deletions

View File

@ -27,10 +27,12 @@
<ul class="record_actions"> <ul class="record_actions">
<li> <li>
<add-address <add-address
v-if="hasTemporaryAddressButton"
v-bind:context="context" v-bind:context="context"
v-bind:key="addAddress.type" 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"
@submitAddress="submitAddress"
ref="addAddress"> ref="addAddress">
</add-address> </add-address>
</li> </li>
@ -52,8 +54,8 @@ export default {
data() { data() {
return { return {
addAddress: { addAddress: {
type: 'accompanying_course_location',
options: { options: {
/// Options override default. /// Options override default.
/// null value take default component value /// null value take default component value
button: { button: {
@ -69,13 +71,8 @@ export default {
/// Display each step in page or Modal /// Display each step in page or Modal
bindModal: { bindModal: {
//step1: false, step2: false //step1: false, step2: false
}, }
// Options only for root parent component }
displayResult: true,
redirectToBackUrl: false
},
type: 'accompanying_course_location',
result: null // <== returned from addAddress component
} }
} }
}, },
@ -83,27 +80,43 @@ export default {
...mapState({ ...mapState({
accompanyingCourse: state => state.accompanyingCourse, accompanyingCourse: state => state.accompanyingCourse,
context: state => state.addressContext context: state => state.addressContext
}) }),
hasTemporaryAddressButton() { // return true if locationStatus equal 'none' or 'address'
return this.accompanyingCourse.locationStatus !== 'person';
}
}, },
methods: { methods: {
initAddressContext() { initAddressContext() {
let ac = { let context = {
entity: { entity: {
type: this.accompanyingCourse.type, type: this.accompanyingCourse.type,
id: this.accompanyingCourse.id id: this.accompanyingCourse.id
}, },
edit: false, edit: false,
addressId: null, addressId: null
backUrl: null
} }
this.$store.commit('setAddressContext', ac); if (this.accompanyingCourse.location) {
context['edit'] = true;
context['addressId'] = this.accompanyingCourse.location.address_id
}
this.$store.commit('setAddressContext', context);
}, },
displayErrors() { displayErrors() {
return this.$refs.addAddress.errorMsg; return this.$refs.addAddress.errorMsg;
},
submitAddress() {
console.log('@@@ click on Submit Address Button');
let payload = this.$refs.addAddress.submitNewAddress();
console.log('payload from parent', payload);
this.$store.dispatch('updateLocation', payload);
} }
}, },
mounted() { mounted() {
this.initAddressContext(); this.initAddressContext();
console.log('ac.locationStatus', this.accompanyingCourse.locationStatus); console.log('ac.locationStatus', this.accompanyingCourse.locationStatus);
console.log('ac.location (temporary location)', this.accompanyingCourse.location); console.log('ac.location (temporary location)', this.accompanyingCourse.location);
console.log('ac.personLocation', this.accompanyingCourse.personLocation); console.log('ac.personLocation', this.accompanyingCourse.personLocation);

View File

@ -1,4 +1,5 @@
import { personMessages } from 'ChillPersonAssets/vuejs/_js/i18n' import { personMessages } from 'ChillPersonAssets/vuejs/_js/i18n'
import { addressMessages } from 'ChillMainAssets/vuejs/Address/i18n';
const appMessages = { const appMessages = {
fr: { fr: {
@ -100,7 +101,7 @@ const appMessages = {
} }
}; };
Object.assign(appMessages.fr, personMessages.fr); Object.assign(appMessages.fr, personMessages.fr, addressMessages.fr);
export { export {
appMessages appMessages

View File

@ -1,5 +1,6 @@
import 'es6-promise/auto'; import 'es6-promise/auto';
import { createStore } from 'vuex'; import { createStore } from 'vuex';
import { patchAddressToAccompanyingPeriod } from "../../_api/AddAddress.js";
import { getAccompanyingCourse, import { getAccompanyingCourse,
patchAccompanyingCourse, patchAccompanyingCourse,
confirmAccompanyingCourse, confirmAccompanyingCourse,
@ -8,6 +9,7 @@ import { getAccompanyingCourse,
postResource, postResource,
postSocialIssue } from '../api'; postSocialIssue } from '../api';
const debug = process.env.NODE_ENV !== 'production'; const debug = process.env.NODE_ENV !== 'production';
const id = window.accompanyingCourseId; const id = window.accompanyingCourseId;
@ -97,6 +99,12 @@ let initPromise = getAccompanyingCourse(id)
setAddressContext(state, context) { setAddressContext(state, context) {
//console.log('define location context'); //console.log('define location context');
state.addressContext = context; state.addressContext = context;
},
updateLocation(state, r) {
console.log('### mutation: set location attributes', r);
state.accompanyingCourse.location = r.location;
state.accompanyingCourse.locationStatus = r.locationStatus;
state.accompanyingCourse.personLocation = r.personLocation;
} }
}, },
actions: { actions: {
@ -214,6 +222,20 @@ let initPromise = getAccompanyingCourse(id)
resolve(); resolve();
})).catch((error) => { commit('catchError', error) }); })).catch((error) => { commit('catchError', error) });
}, },
/////
updateLocation({ commit }, payload) {
console.log('## action: updateLocation', payload);
patchAddressToAccompanyingPeriod(payload.entityId, payload.addressId)
.then(accompanyingCourse => new Promise((resolve, reject) => {
commit('updateLocation', {
location: accompanyingCourse.location,
locationStatus: accompanyingCourse.locationStatus,
personLocation: accompanyingCourse.personLocation
});
resolve();
})).catch((error) => { commit('catchError', error) });
},
/////
confirmAccompanyingCourse({ commit }) { confirmAccompanyingCourse({ commit }) {
//console.log('## action: confirmAccompanyingCourse'); //console.log('## action: confirmAccompanyingCourse');
confirmAccompanyingCourse(id) confirmAccompanyingCourse(id)

View File

@ -205,8 +205,7 @@ This view should receive those arguments:
mode: 'edit', mode: 'edit',
address_id: person.lastAddress.id, address_id: person.lastAddress.id,
backUrl: path('chill_person_view', { 'person_id': person.id }), backUrl: path('chill_person_view', { 'person_id': person.id }),
modalTitle: 'Edit address', modalTitle: 'Edit address', buttonText: 'Edit address',
buttonText: 'Edit address',
buttonType: 'btn-update', buttonType: 'btn-update',
buttonSize: 'btn-sm', buttonSize: 'btn-sm',
buttonDisplay: false buttonDisplay: false