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