location: code refactoring: move saveNewLocation + order of fields

This commit is contained in:
nobohan
2021-11-03 11:34:52 +01:00
committed by Julien Fastré
parent e52880bb53
commit 4e72bdead5
2 changed files with 110 additions and 84 deletions

View File

@@ -20,7 +20,7 @@
v-model="location">
</VueMultiselect>
<new-location @saveNewLocation="saveNewLocation"></new-location>
<new-location v-bind:locations="locations"></new-location>
</div>
</div>
</teleport>
@@ -30,7 +30,7 @@
import { mapState } from "vuex";
import VueMultiselect from 'vue-multiselect';
import NewLocation from './Location/NewLocation.vue';
import { getLocations, postLocation } from '../api.js';
import { getLocations } from '../api.js';
export default {
name: "Location",
@@ -67,29 +67,6 @@ export default {
},
customLabel(value) {
return `${value.locationType.title.fr} ${value.name}`;
},
saveNewLocation(selected) {
console.log('saveNewLocation', selected);
let body = {
type: 'location',
name: selected.name,
address: {
id: selected.addressId
},
locationType: {
id: selected.type,
type: 'location-type'
},
phonenumber1: selected.phonenumber1,
phonenumber2: selected.phonenumber2,
email: selected.email,
}
postLocation(body).then(location => new Promise(resolve => {
console.log('postLocation', location);
this.locations.push(location);
this.$store.dispatch('updateLocation', location);
resolve();
}));
}
}
}