From 98aad8c4b6355d90f6afef837384b9d0243d1990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 11 Apr 2023 10:45:10 +0200 Subject: [PATCH] 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 --- .../AccompanyingPeriodWork.php | 4 +-- .../AccompanyingCourseWorkCreate/index.js | 25 ++++++++++++------- .../AccompanyingCourseWorkCreate/store.js | 6 ++++- .../vuejs/AccompanyingCourseWorkEdit/App.vue | 9 ++++++- .../vuejs/AccompanyingCourseWorkEdit/index.js | 2 +- .../vuejs/AccompanyingCourseWorkEdit/store.js | 3 +-- .../translations/validators.fr.yml | 3 +++ 7 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php index adb5ca358..5361012b3 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod/AccompanyingPeriodWork.php @@ -94,8 +94,8 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues * @Serializer\Groups({"accompanying_period_work:create"}) * @Serializer\Groups({"accompanying_period_work:edit"}) * @Serializer\Groups({"read", "docgen:read", "read:accompanyingPeriodWork:light"}) - * @Assert\GreaterThan(propertyPath="startDate", - * message="accompanying_course_work.The endDate should be greater than the start date" + * @Assert\GreaterThanOrEqual(propertyPath="startDate", + * message="accompanying_course_work.The endDate should be greater or equal than the start date" * ) */ private ?DateTimeImmutable $endDate = null; diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/index.js index 7e54e2b0b..1f8a25d3a 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/index.js @@ -1,15 +1,22 @@ -import { createApp } from 'vue'; -import { _createI18n } from 'ChillMainAssets/vuejs/_js/i18n'; -import { store } from './store'; -import { personMessages } from 'ChillPersonAssets/vuejs/_js/i18n' +import {createApp} from 'vue'; +import {_createI18n} from 'ChillMainAssets/vuejs/_js/i18n'; +import {store} from './store'; +import {personMessages} from 'ChillPersonAssets/vuejs/_js/i18n' import App from './App.vue'; +import VueToast from "vue-toast-notification"; const i18n = _createI18n(personMessages); const app = createApp({ - template: ``, + template: ``, }) -.use(store) -.use(i18n) -.component('app', App) -.mount('#accompanying_course_work_create'); + .use(store) + .use(i18n) + .use(VueToast, { + position: "bottom-right", + type: "error", + duration: 10000, + dismissible: true, + }) + .component('app', App) + .mount('#accompanying_course_work_create'); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/store.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/store.js index 3eee7c56a..138e6f6ed 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/store.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkCreate/store.js @@ -107,6 +107,9 @@ const store = createStore({ setPostingWork(state) { state.isPostingWork = true; }, + setPostingWorkDone(state) { + state.isPostingWork = false; + }, setStartDate(state, date) { state.startDate = date; }, @@ -150,11 +153,12 @@ const store = createStore({ const url = `/api/1.0/person/accompanying-course/${state.accompanyingCourse.id}/work.json`; commit('setPostingWork'); - makeFetch('POST', url, payload) + return makeFetch('POST', url, payload) .then((response) => { window.location.assign(`/fr/person/accompanying-period/work/${response.id}/edit`) }) .catch((error) => { + commit('setPostingWorkDone'); throw error; }); }, diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue index 9a105dd8d..755e4455c 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/App.vue @@ -549,7 +549,14 @@ export default { .catch(e => { console.log(e); throw e; }); }, 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) { console.log('saveFormOnTheFly: type', payload.type, ', data', payload.data); diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/index.js index 143d34215..b0868b48b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/index.js @@ -15,7 +15,7 @@ const app = createApp({ .use(VueToast, { position: "bottom-right", type: "error", - duration: 5000, + duration: 10000, dismissible: true }) .use(i18n) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js index e075e65bc..47e4b2d3f 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourseWorkEdit/store.js @@ -500,9 +500,8 @@ const store = createStore({ window.location.assign(`/fr/person/accompanying-period/${state.work.accompanyingPeriod.id}/work`); } }).catch(error => { - console.log('error on submit', error); commit('setIsPosting', false); - commit('setErrors', error.violations); + throw error; }); }, updateDocumentTitle({commit}, payload) { diff --git a/src/Bundle/ChillPersonBundle/translations/validators.fr.yml b/src/Bundle/ChillPersonBundle/translations/validators.fr.yml index 8fcda47aa..f005755b1 100644 --- a/src/Bundle/ChillPersonBundle/translations/validators.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/validators.fr.yml @@ -71,3 +71,6 @@ relationship: 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 + +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