Fixed: [accompanying period work / edit] allow endDate to be equal to startDate, and show validation errors to users

Fix https://gitlab.com/Chill-Projet/chill-bundles/-/issues/79
This commit is contained in:
Julien Fastré 2023-04-11 10:45:10 +02:00
parent ef13833966
commit 98aad8c4b6
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
7 changed files with 36 additions and 16 deletions

View File

@ -94,8 +94,8 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
* @Serializer\Groups({"accompanying_period_work:create"}) * @Serializer\Groups({"accompanying_period_work:create"})
* @Serializer\Groups({"accompanying_period_work:edit"}) * @Serializer\Groups({"accompanying_period_work:edit"})
* @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light"}) * @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light"})
* @Assert\GreaterThan(propertyPath="startDate", * @Assert\GreaterThanOrEqual(propertyPath="startDate",
* message="accompanying_course_work.The endDate should be greater than the start date" * message="accompanying_course_work.The endDate should be greater or equal than the start date"
* ) * )
*/ */
private ?DateTimeImmutable $endDate = null; private ?DateTimeImmutable $endDate = null;

View File

@ -3,6 +3,7 @@ import { _createI18n } from 'ChillMainAssets/vuejs/_js/i18n';
import {store} from './store'; import {store} from './store';
import {personMessages} from 'ChillPersonAssets/vuejs/_js/i18n' import {personMessages} from 'ChillPersonAssets/vuejs/_js/i18n'
import App from './App.vue'; import App from './App.vue';
import VueToast from "vue-toast-notification";
const i18n = _createI18n(personMessages); const i18n = _createI18n(personMessages);
@ -11,5 +12,11 @@ const app = createApp({
}) })
.use(store) .use(store)
.use(i18n) .use(i18n)
.use(VueToast, {
position: "bottom-right",
type: "error",
duration: 10000,
dismissible: true,
})
.component('app', App) .component('app', App)
.mount('#accompanying_course_work_create'); .mount('#accompanying_course_work_create');

View File

@ -107,6 +107,9 @@ const store = createStore({
setPostingWork(state) { setPostingWork(state) {
state.isPostingWork = true; state.isPostingWork = true;
}, },
setPostingWorkDone(state) {
state.isPostingWork = false;
},
setStartDate(state, date) { setStartDate(state, date) {
state.startDate = date; state.startDate = date;
}, },
@ -150,11 +153,12 @@ const store = createStore({
const url = `/api/1.0/person/accompanying-course/${state.accompanyingCourse.id}/work.json`; const url = `/api/1.0/person/accompanying-course/${state.accompanyingCourse.id}/work.json`;
commit('setPostingWork'); commit('setPostingWork');
makeFetch('POST', url, payload) return makeFetch('POST', url, payload)
.then((response) => { .then((response) => {
window.location.assign(`/fr/person/accompanying-period/work/${response.id}/edit`) window.location.assign(`/fr/person/accompanying-period/work/${response.id}/edit`)
}) })
.catch((error) => { .catch((error) => {
commit('setPostingWorkDone');
throw error; throw error;
}); });
}, },

View File

@ -549,7 +549,14 @@ export default {
.catch(e => { console.log(e); throw e; }); .catch(e => { console.log(e); throw e; });
}, },
submit() { submit() {
this.$store.dispatch('submit'); this.$store.dispatch('submit').catch((error) => {
if (error.name === 'ValidationException' || error.name === 'AccessException') {
error.violations.forEach((violation) => this.$toast.open({message: violation}));
} else {
this.$toast.open({message: 'An error occurred'});
throw error;
}
});
}, },
saveFormOnTheFly(payload) { saveFormOnTheFly(payload) {
console.log('saveFormOnTheFly: type', payload.type, ', data', payload.data); console.log('saveFormOnTheFly: type', payload.type, ', data', payload.data);

View File

@ -15,7 +15,7 @@ const app = createApp({
.use(VueToast, { .use(VueToast, {
position: "bottom-right", position: "bottom-right",
type: "error", type: "error",
duration: 5000, duration: 10000,
dismissible: true dismissible: true
}) })
.use(i18n) .use(i18n)

View File

@ -500,9 +500,8 @@ const store = createStore({
window.location.assign(`/fr/person/accompanying-period/${state.work.accompanyingPeriod.id}/work`); window.location.assign(`/fr/person/accompanying-period/${state.work.accompanyingPeriod.id}/work`);
} }
}).catch(error => { }).catch(error => {
console.log('error on submit', error);
commit('setIsPosting', false); commit('setIsPosting', false);
commit('setErrors', error.violations); throw error;
}); });
}, },
updateDocumentTitle({commit}, payload) { updateDocumentTitle({commit}, payload) {

View File

@ -71,3 +71,6 @@ relationship:
person_creation: person_creation:
If you want to create an household, an address is required: Pour la création d'un ménage, une adresse est requise If you want to create an household, an address is required: Pour la création d'un ménage, une adresse est requise
accompanying_course_work:
The endDate should be greater or equal than the start date: La date de fin doit être égale ou supérieure à la date de début