rdv: reset calendar after all promises are done

This commit is contained in:
nobohan 2021-09-13 13:43:39 +02:00
parent c82efc4fd5
commit 813da1f9e0

View File

@ -47,11 +47,6 @@
</li>
</ul>
</div>
<div>
<p>{{ $t('copy_range_how_to')}}</p>
</div>
<div>
<div v-if="newCalendarRanges.length > 0">
<h4>{{ $t('new_range_to_save') }}</h4>
@ -334,7 +329,7 @@ export default {
onClickSave(payload) {
this.flag.loading = true;
if (this.$store.state.newCalendarRanges.length > 0){
this.$store.state.newCalendarRanges.map(cr => {
Promise.all(this.$store.state.newCalendarRanges.map(cr => {
postCalendarRange({
user: {
type: 'user',
@ -346,12 +341,14 @@ export default {
endDate: {
datetime: `${cr.end.toISOString().split('.')[0]}+0000`, // TODO check if OK with time zone
},
}).then((_r) => this.resetCalendar());
});
})
})
).then((_r) => this.resetCalendar());
this.$store.dispatch('clearNewCalendarRanges', payload);
}
if (this.$store.state.updateCalendarRanges.length > 0){
this.$store.state.updateCalendarRanges.map(cr => {
Promise.all(this.$store.state.updateCalendarRanges.map(cr => {
patchCalendarRange(cr.id,
{
startDate: {
@ -360,14 +357,16 @@ export default {
endDate: {
datetime: `${cr.end.toISOString().split('.')[0]}+0000`, // TODO check if OK with time zone
},
}).then((_r) => this.resetCalendar());
})
})
})
).then((_r) => this.resetCalendar());
this.$store.dispatch('clearUpdateCalendarRanges', payload);
}
if (this.$store.state.deleteCalendarRanges.length > 0){
this.$store.state.deleteCalendarRanges.map(cr => {
deleteCalendarRange(cr.id).then((_r) => this.resetCalendar());;
})
Promise.all(this.$store.state.deleteCalendarRanges.map(cr => {
deleteCalendarRange(cr.id)
})
).then((_r) => this.resetCalendar());
this.$store.dispatch('clearDeleteCalendarRanges', payload);
}