updating openingdate parcours fixed

This commit is contained in:
Julie Lenaerts 2022-04-19 15:09:25 +02:00
parent 65e6471a02
commit bc550ea42a
3 changed files with 21 additions and 13 deletions

View File

@ -5,9 +5,9 @@
</h2> </h2>
<div> <div>
<div class="mb-3 row"> <div class="mb-3 row">
<label class="col-form-label col-sm-4">{{ $t('startdate.date') }}</label> <div class="col-sm-12 date-update">
<div class="col-sm-8"> <input class="form-control" type="date" id="startDate" v-model="startDate">
<input class="form-control" type="date" v-model="startDate" @change="updateStartDate" /> <button class="btn btn-save date-update-btn" type="submit" @click="updateStartDate"></button>
</div> </div>
</div> </div>
</div> </div>
@ -23,10 +23,12 @@ import { mapState, mapGetters } from 'vuex';
export default { export default {
name: 'startDate', name: 'startDate',
methods: { methods: {
updateStartDate(event) { updateStartDate(e) {
const date = event.target.value; e.preventDefault();
// console.log(date) const date = e.target.previousSibling.value;
this.$store.dispatch('updateStartDate', date) this.$store.dispatch('updateStartDate', date)
.then(this.$toast.open({type: 'success', message: this.$t('startdate.update')}))
.catch(({name, violations}) => { .catch(({name, violations}) => {
if (name === 'ValidationException' || name === 'AccessException') { if (name === 'ValidationException' || name === 'AccessException') {
violations.forEach((violation) => this.$toast.open({message: violation})); violations.forEach((violation) => this.$toast.open({message: violation}));
@ -43,4 +45,14 @@ export default {
} }
} }
</script> </script>
<style lang="scss" scoped>
.date-update {
display: flex;
justify-content: space-between;
&-btn {
margin-left: 1rem;
}
}
</style>

View File

@ -153,7 +153,7 @@ const appMessages = {
}, },
startdate: { startdate: {
change: "Date d'ouverture", change: "Date d'ouverture",
date: "Date d'ouverture", update: "La nouvelle date d'ouverture a été bien enregistrée"
}, },
// catch errors // catch errors
'Error while updating AccompanyingPeriod Course.': "Erreur du serveur lors de la mise à jour du parcours d'accompagnement.", 'Error while updating AccompanyingPeriod Course.': "Erreur du serveur lors de la mise à jour du parcours d'accompagnement.",

View File

@ -322,7 +322,6 @@ let initPromise = (root) => Promise.all([getScopesPromise(root), accompanyingCou
} }
}, },
updateStartDate(state, date) { updateStartDate(state, date) {
console.log('new state date', date)
state.accompanyingCourse.openingDate = date; state.accompanyingCourse.openingDate = date;
} }
}, },
@ -814,11 +813,8 @@ let initPromise = (root) => Promise.all([getScopesPromise(root), accompanyingCou
}) })
}, },
updateStartDate({commit}, payload) { updateStartDate({commit}, payload) {
console.log('payload', payload)
const date = ISOToDate(payload);
const url = `/api/1.0/person/accompanying-course/${id}.json`; const url = `/api/1.0/person/accompanying-course/${id}.json`;
const body = { type: "accompanying_period", openingDate: { datetime: datetimeToISO(date) }}; const body = { type: "accompanying_period", openingDate: { datetime: datetimeToISO(ISOToDate(payload)) }};
console.log('body', body)
return makeFetch('PATCH', url, body) return makeFetch('PATCH', url, body)
.then((response) => { .then((response) => {
commit('updateStartDate', response.openingDate); commit('updateStartDate', response.openingDate);