location: treat 422 error when POSTing new location

This commit is contained in:
nobohan 2022-01-11 16:13:23 +01:00
parent c7b9a1a3fe
commit fa0b9271c2

View File

@ -78,7 +78,8 @@
import Modal from 'ChillMainAssets/vuejs/_components/Modal.vue'; import Modal from 'ChillMainAssets/vuejs/_components/Modal.vue';
import AddAddress from "ChillMainAssets/vuejs/Address/components/AddAddress.vue"; import AddAddress from "ChillMainAssets/vuejs/Address/components/AddAddress.vue";
import { mapState } from "vuex"; import { mapState } from "vuex";
import { getLocationTypes, postLocation } from "../../api"; import { getLocationTypes } from "../../api";
import { makeFetch } from 'ChillMainAssets/lib/api/apiMethods';
export default { export default {
name: "NewLocation", name: "NewLocation",
@ -220,7 +221,6 @@ export default {
}, },
saveNewLocation() { saveNewLocation() {
if (this.checkForm()) { if (this.checkForm()) {
console.log('saveNewLocation', this.selected);
let body = { let body = {
type: 'location', type: 'location',
name: this.selected.name, name: this.selected.name,
@ -239,29 +239,28 @@ export default {
} }
}); });
} }
postLocation(body)
.then(
location => new Promise(resolve => {
makeFetch('POST', '/api/1.0/main/location.json', body)
.then(response => {
this.$store.dispatch('addAvailableLocationGroup', { this.$store.dispatch('addAvailableLocationGroup', {
locationGroup: 'Localisations nouvellement créées', locationGroup: 'Localisations nouvellement créées',
locations: [location] locations: [response]
}); });
this.$store.dispatch('updateLocation', response);
this.$store.dispatch('updateLocation', location);
resolve();
this.modal.showModal = false; this.modal.showModal = false;
}) })
).catch( .catch((error) => {
err => { if (error.name === 'ValidationException') {
this.errors.push(err.message); for (let v of error.violations) {
this.errors.push(v);
} }
); } else {
this.errors.push('An error occurred');
}
})
}; };
}, },
submitNewAddress(payload) { submitNewAddress(payload) {
console.log('submitNewAddress', payload);
this.selected.addressId = payload.addressId; this.selected.addressId = payload.addressId;
this.addAddress.context.addressId = payload.addressId; this.addAddress.context.addressId = payload.addressId;
this.addAddress.context.edit = true; this.addAddress.context.edit = true;