mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
patch Address to accompanyingPeriod: build payload for differents cases
use uniq patch api endpoint, build payload body in action, call updateAddress action when submitting, assigning or removing.
This commit is contained in:
parent
966292cdd5
commit
107699ec31
@ -9,12 +9,26 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import {mapState} from "vuex";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "ButtonLocation",
|
name: "ButtonLocation",
|
||||||
props: ['person'],
|
props: ['person'],
|
||||||
|
computed: {
|
||||||
|
...mapState({
|
||||||
|
context: state => state.addressContext
|
||||||
|
}),
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
assignAddress() {
|
assignAddress() {
|
||||||
console.log('assignAddress id', this.person.current_household_address.address_id);
|
console.log('assignAddress id', this.person.current_household_address);
|
||||||
|
let payload = {
|
||||||
|
entity: this.context.entity.type,
|
||||||
|
entityId: this.context.entity.id,
|
||||||
|
addressToPatch: 'person',
|
||||||
|
personId: this.person.id
|
||||||
|
};
|
||||||
|
this.$store.dispatch('updateLocation', payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
<ul class="record_actions">
|
<ul class="record_actions">
|
||||||
<li>
|
<li>
|
||||||
<add-address
|
<add-address
|
||||||
v-if="hasTemporaryAddressButton"
|
v-if="!isPersonLocation"
|
||||||
:context="context"
|
:context="context"
|
||||||
:key="addAddress.type"
|
:key="addAddress.type"
|
||||||
:options="addAddress.options"
|
:options="addAddress.options"
|
||||||
@ -32,11 +32,12 @@
|
|||||||
ref="addAddress">
|
ref="addAddress">
|
||||||
</add-address>
|
</add-address>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li v-if="isContextEdit && isPersonLocation">
|
||||||
<button v-if="isContextEdit"
|
<button
|
||||||
class="btn btn-remove"
|
class="btn btn-remove"
|
||||||
@click="removeAddress"
|
@click="removeAddress"
|
||||||
:title="$t('courselocation.remove_button')"></button>
|
:title="$t('courselocation.remove_button')">
|
||||||
|
</button>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
@ -85,12 +86,12 @@ export default {
|
|||||||
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';
|
|
||||||
},
|
|
||||||
isTemporaryAddress() {
|
isTemporaryAddress() {
|
||||||
return this.accompanyingCourse.locationStatus === 'address';
|
return this.accompanyingCourse.locationStatus === 'address';
|
||||||
},
|
},
|
||||||
|
isPersonLocation() {
|
||||||
|
return this.accompanyingCourse.locationStatus === 'person';
|
||||||
|
},
|
||||||
isContextEdit() {
|
isContextEdit() {
|
||||||
return this.context.edit;
|
return this.context.edit;
|
||||||
}
|
}
|
||||||
@ -117,6 +118,12 @@ export default {
|
|||||||
},
|
},
|
||||||
removeAddress() {
|
removeAddress() {
|
||||||
console.log('remove address');
|
console.log('remove address');
|
||||||
|
let payload = {
|
||||||
|
entity: this.context.entity.type,
|
||||||
|
entityId: this.context.entity.id,
|
||||||
|
addressToPatch: 'none'
|
||||||
|
};
|
||||||
|
this.$store.dispatch('updateLocation', payload);
|
||||||
},
|
},
|
||||||
displayErrors() {
|
displayErrors() {
|
||||||
return this.$refs.addAddress.errorMsg;
|
return this.$refs.addAddress.errorMsg;
|
||||||
@ -125,7 +132,9 @@ export default {
|
|||||||
console.log('@@@ click on Submit Address Button');
|
console.log('@@@ click on Submit Address Button');
|
||||||
|
|
||||||
let payload = this.$refs.addAddress.submitNewAddress();
|
let payload = this.$refs.addAddress.submitNewAddress();
|
||||||
console.log('payload from parent', payload);
|
|
||||||
|
// precise in payload that it is a temporary address
|
||||||
|
payload['addressToPatch'] = 'address';
|
||||||
|
|
||||||
this.$store.dispatch('updateLocation', payload);
|
this.$store.dispatch('updateLocation', payload);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
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,
|
||||||
@ -225,7 +224,21 @@ let initPromise = getAccompanyingCourse(id)
|
|||||||
/////
|
/////
|
||||||
updateLocation({ commit }, payload) {
|
updateLocation({ commit }, payload) {
|
||||||
console.log('## action: updateLocation', payload);
|
console.log('## action: updateLocation', payload);
|
||||||
patchAddressToAccompanyingPeriod(payload.entityId, payload.addressId)
|
let body = { 'type': payload.entity, 'id': payload.entityId };
|
||||||
|
let location = {};
|
||||||
|
if (payload.addressToPatch === 'person') {
|
||||||
|
// payload to patch person address (don't remove addressLocation)
|
||||||
|
location = { 'personLocation': { 'type': 'person', 'id': payload.personId }};
|
||||||
|
}
|
||||||
|
else if(payload.addressToPatch === 'address') {
|
||||||
|
// payload to patch temporary address
|
||||||
|
location = { 'personLocation': null, 'addressLocation': { 'id': payload.addressId }};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
location = { 'personLocation': null };
|
||||||
|
}
|
||||||
|
Object.assign(body, location);
|
||||||
|
patchAccompanyingCourse(payload.entityId, body)
|
||||||
.then(accompanyingCourse => new Promise((resolve, reject) => {
|
.then(accompanyingCourse => new Promise((resolve, reject) => {
|
||||||
commit('updateLocation', {
|
commit('updateLocation', {
|
||||||
location: accompanyingCourse.location,
|
location: accompanyingCourse.location,
|
||||||
|
@ -48,32 +48,4 @@ const postAddressToHousehold = (householdId, addressId) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
export { postAddressToPerson, postAddressToHousehold };
|
||||||
* Endpoint AccompanyingPeriod
|
|
||||||
* method POST, post AccompanyingPeriod AddressLocation (temporary address)
|
|
||||||
*
|
|
||||||
* @id integer - id of AccompanyingPeriod
|
|
||||||
* @body Object - dictionary with changes to post
|
|
||||||
*/
|
|
||||||
const patchAddressToAccompanyingPeriod = (accompanyingPeriodId, addressId) => {
|
|
||||||
const body = {
|
|
||||||
'type': 'accompanying_period',
|
|
||||||
'id': accompanyingPeriodId,
|
|
||||||
'personLocation': null,
|
|
||||||
'addressLocation': {
|
|
||||||
'id': addressId
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const url = `/api/1.0/person/accompanying-course/${accompanyingPeriodId}.json`;
|
|
||||||
return fetch (url, {
|
|
||||||
method: 'PATCH',
|
|
||||||
headers: {'Content-Type': 'application/json;charset=utf-8'},
|
|
||||||
body: JSON.stringify(body)
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response.ok) { return response.json(); }
|
|
||||||
throw Error('Error with request resource response');
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export { postAddressToPerson, postAddressToHousehold, patchAddressToAccompanyingPeriod };
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user