mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 23:23:51 +00:00
address: edit household addresses
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
<div class='household__address-move'>
|
||||
<div class='household__address-move__create'>
|
||||
<div>
|
||||
<h2>{{ $t('create_a_new_address') }}</h2>
|
||||
<h2 v-if="!edit">{{ $t('create_a_new_address') }}</h2>
|
||||
<h2 v-else>{{ $t('edit_a_new_address') }}</h2>
|
||||
<add-address
|
||||
@addNewAddress="addNewAddress">
|
||||
</add-address>
|
||||
@@ -14,7 +15,7 @@
|
||||
</show-address>
|
||||
</div>
|
||||
</div>
|
||||
<div class='household__address-move__valid'>
|
||||
<div v-if="!edit" class='household__address-move__valid'>
|
||||
<h2>{{ $t('move_date') }}</h2>
|
||||
<input
|
||||
type="date"
|
||||
@@ -27,16 +28,19 @@
|
||||
<div v-if="loading">
|
||||
{{ $t('loading') }}
|
||||
</div>
|
||||
<div v-if="success">
|
||||
<div v-if="success && !edit">
|
||||
{{ $t('household_address_move_success') }}
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="success && edit">
|
||||
{{ $t('household_address_edit_success') }}
|
||||
</div>
|
||||
<div>
|
||||
<ul class="record_actions sticky-form-buttons">
|
||||
<li class="cancel">
|
||||
<a :href=backUrl class="sc-button bt-cancel">{{ $t('back_to_the_list') }}</a>
|
||||
</li>
|
||||
<li>
|
||||
<li v-if="!edit">
|
||||
<button type="submit" class="sc-button bt-update centered" @click="addToHousehold">
|
||||
{{ $t('add_an_address_to_household') }}
|
||||
</button>
|
||||
@@ -61,6 +65,7 @@ export default {
|
||||
return {
|
||||
edit: window.mode === 'edit',
|
||||
householdId: window.householdId,
|
||||
addressId: window.addressId,
|
||||
backUrl: `/fr/person/household/${householdId}/addresses`, //TODO better way to pass this
|
||||
validFrom: new Date().toISOString().split('T')[0]
|
||||
}
|
||||
@@ -113,7 +118,14 @@ export default {
|
||||
});
|
||||
}
|
||||
|
||||
this.$store.dispatch('addAddress', createdAddress);
|
||||
if (this.edit){
|
||||
this.$store.dispatch('updateAddress', {
|
||||
addressId: this.addressId,
|
||||
newAddress: createdAddress
|
||||
});
|
||||
} else {
|
||||
this.$store.dispatch('addAddress', createdAddress);
|
||||
}
|
||||
|
||||
modal.showModal = false;
|
||||
},
|
||||
@@ -124,8 +136,16 @@ export default {
|
||||
body: { validFrom: {datetime: `${this.validFrom}T00:00:00+0100`}},
|
||||
backUrl: this.backUrl
|
||||
})
|
||||
},
|
||||
getEditAddress() {
|
||||
this.$store.dispatch('getEditAddress', this.addressId);
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
if (this.edit) {
|
||||
this.getEditAddress();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
</script>
|
||||
|
@@ -9,6 +9,7 @@ const appMessages = {
|
||||
move_date: 'Date du déménagement',
|
||||
back_to_the_list: 'Retour à la liste',
|
||||
household_address_move_success: 'La nouvelle adresse du ménage est enregistrée',
|
||||
household_address_edit_success: 'L\'adresse du ménage a été mise à jour',
|
||||
loading: 'chargement en cours...'
|
||||
}
|
||||
};
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import 'es6-promise/auto';
|
||||
import { createStore } from 'vuex';
|
||||
|
||||
import { postAddress, postPostalCode, patchAddress } from 'ChillMainAssets/vuejs/_api/AddAddress';
|
||||
import { postAddress, postPostalCode, patchAddress, getAddress } from 'ChillMainAssets/vuejs/_api/AddAddress';
|
||||
import { postAddressToHousehold } from '../api';
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
@@ -10,6 +10,7 @@ const store = createStore({
|
||||
strict: debug,
|
||||
state: {
|
||||
newAddress: {},
|
||||
editAddress: {}, //TODO or should be newAddress?
|
||||
household: {},
|
||||
validFrom: {},
|
||||
errorMsg: [],
|
||||
@@ -26,6 +27,10 @@ const store = createStore({
|
||||
console.log('@M addAddress address', address);
|
||||
state.newAddress = address;
|
||||
},
|
||||
updateAddress(state, address) {
|
||||
console.log('@M updateAddress address', address);
|
||||
state.newAddress = address;
|
||||
},
|
||||
addAddressToHousehold(state, household) {
|
||||
console.log('@M addAddressToHousehold household', household);
|
||||
state.household = household;
|
||||
@@ -34,6 +39,10 @@ const store = createStore({
|
||||
console.log('@M addDateToAddress address.validFrom', validFrom);
|
||||
state.validFrom = validFrom;
|
||||
},
|
||||
getEditAddress(state, address) {
|
||||
console.log('@M getEditAddress address', address);
|
||||
state.editAddress = address;
|
||||
},
|
||||
setLoading(state, b) {
|
||||
state.loading = b;
|
||||
},
|
||||
@@ -101,6 +110,50 @@ const store = createStore({
|
||||
commit('setLoading', false);
|
||||
});
|
||||
},
|
||||
updateAddress({ commit }, payload) {
|
||||
console.log('@A updateAddress payload', payload);
|
||||
|
||||
if('newPostalCode' in payload.newAddress){ // TODO change the condition because it writes new postal code in edit mode now: !writeNewPostalCode
|
||||
let postalCodeBody = payload.newAddress.newPostalCode;
|
||||
postalCodeBody = Object.assign(postalCodeBody, {'origin': 3});
|
||||
postPostalCode(postalCodeBody)
|
||||
.then(postalCode => {
|
||||
let body = payload.newAddress;
|
||||
body.postcode = {'id': postalCode.id },
|
||||
patchAddress(payload.addressId, body)
|
||||
.then(address => new Promise((resolve, reject) => {
|
||||
commit('updateAddress', address);
|
||||
commit('setSuccess', true);
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
commit('catchError', error);
|
||||
});
|
||||
})
|
||||
|
||||
} else {
|
||||
patchAddress(payload.addressId, payload.newAddress)
|
||||
.then(address => new Promise((resolve, reject) => {
|
||||
commit('updateAddress', address);
|
||||
commit('setSuccess', true);
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
commit('catchError', error);
|
||||
});
|
||||
}
|
||||
},
|
||||
getEditAddress({ commit }, payload) {
|
||||
console.log('@A getEditAddress payload', payload);
|
||||
|
||||
getAddress(payload).then(address => new Promise((resolve, reject) => {
|
||||
commit('getEditAddress', address);
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => {
|
||||
commit('catchError', error);
|
||||
});
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user