mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
household address: chain API call
This commit is contained in:
parent
e14a125bf3
commit
1b36d9b1ab
@ -91,7 +91,7 @@ const postAddress = (address) => {
|
|||||||
* @body Object - dictionary with changes to post
|
* @body Object - dictionary with changes to post
|
||||||
*/
|
*/
|
||||||
const patchAddress = (id, body) => {
|
const patchAddress = (id, body) => {
|
||||||
console.log('body', body);
|
|
||||||
const url = `/api/1.0/main/address/${id}.json`;
|
const url = `/api/1.0/main/address/${id}.json`;
|
||||||
return fetch(url, {
|
return fetch(url, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
|
@ -38,22 +38,13 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
householdId: window.householdId,
|
householdId: window.householdId,
|
||||||
validFrom: new Date()
|
validFrom: new Date().toISOString().split('T')[0]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
newAddress() {
|
newAddress() {
|
||||||
return this.$store.state.newAddress;
|
return this.$store.state.newAddress;
|
||||||
},
|
},
|
||||||
validFrom: {
|
|
||||||
set(value) {
|
|
||||||
console.log('value', value);
|
|
||||||
this.validFrom = value;
|
|
||||||
},
|
|
||||||
get() {
|
|
||||||
return this.validFrom;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
addNewAddress({ address, modal }) {
|
addNewAddress({ address, modal }) {
|
||||||
@ -82,21 +73,11 @@ export default {
|
|||||||
modal.showModal = false;
|
modal.showModal = false;
|
||||||
},
|
},
|
||||||
addToHousehold() {
|
addToHousehold() {
|
||||||
const householdId = this.householdId;
|
this.$store.dispatch('addDateToAddressAndAddressToHousehold', {
|
||||||
const addressId = this.$store.state.newAddress.address_id;
|
householdId: this.householdId,
|
||||||
console.log(householdId);
|
addressId: this.$store.state.newAddress.address_id,
|
||||||
console.log(addressId);
|
body: { validFrom: {datetime: `${this.validFrom}T00:00:00+0100`}}
|
||||||
console.log(this.validFrom)
|
})
|
||||||
// TODO: Chainer l'ajout de la date puis l'ajout de l'addresse au ménage
|
|
||||||
this.$store.dispatch('addDateToAddress', {
|
|
||||||
addressId,
|
|
||||||
body: {
|
|
||||||
validFrom: {datetime: `${this.validFrom}T00:00:00+0100`}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
this.$store.dispatch('addAddressToHousehold', {householdId, addressId});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -4,7 +4,8 @@ const appMessages = {
|
|||||||
fr: {
|
fr: {
|
||||||
select_a_existing_address: 'Sélectionner une adresse existante',
|
select_a_existing_address: 'Sélectionner une adresse existante',
|
||||||
create_a_new_address: 'Créer une nouvelle adresse',
|
create_a_new_address: 'Créer une nouvelle adresse',
|
||||||
add_an_address_to_household: 'Ajouter l\'adresse au ménage'
|
add_an_address_to_household: 'Ajouter l\'adresse au ménage',
|
||||||
|
validFrom: 'Date du déménagement'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ const store = createStore({
|
|||||||
state: {
|
state: {
|
||||||
newAddress: {},
|
newAddress: {},
|
||||||
household: {},
|
household: {},
|
||||||
|
validFrom: {},
|
||||||
errorMsg: []
|
errorMsg: []
|
||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
@ -46,24 +47,22 @@ const store = createStore({
|
|||||||
commit('catchError', error);
|
commit('catchError', error);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
addAddressToHousehold({ commit }, payload) {
|
addDateToAddressAndAddressToHousehold({ commit }, payload) {
|
||||||
console.log('@A addAddressToHousehold payload', payload);
|
console.log('@A addDateToAddressAndAddressToHousehold payload', payload);
|
||||||
|
|
||||||
postAddressToHousehold(payload.householdId, payload.addressId)
|
|
||||||
.then(household => new Promise((resolve, reject) => {
|
|
||||||
commit('addAddressToHousehold', household);
|
|
||||||
resolve();
|
|
||||||
}))
|
|
||||||
.catch((error) => {
|
|
||||||
commit('catchError', error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
addDateToAddress({ commit }, payload) {
|
|
||||||
console.log('@A addAddressToHousehold payload', payload);
|
|
||||||
patchAddress(payload.addressId, payload.body)
|
patchAddress(payload.addressId, payload.body)
|
||||||
.then(address => new Promise((resolve, reject) => {
|
.then(address => new Promise((resolve, reject) => {
|
||||||
commit('addDateToAddress', address.validFrom);
|
commit('addDateToAddress', address.validFrom);
|
||||||
resolve();
|
resolve().then(
|
||||||
|
postAddressToHousehold(payload.householdId, payload.addressId)
|
||||||
|
.then(household => new Promise((resolve, reject) => {
|
||||||
|
commit('addAddressToHousehold', household);
|
||||||
|
resolve();
|
||||||
|
}))
|
||||||
|
.catch((error) => {
|
||||||
|
commit('catchError', error);
|
||||||
|
})
|
||||||
|
);
|
||||||
}))
|
}))
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
commit('catchError', error);
|
commit('catchError', error);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user