From be4334f6a2bb5328fede5a5740426ad3eadc6261 Mon Sep 17 00:00:00 2001 From: Adam Leskis Date: Tue, 6 Jul 2021 12:58:40 +0100 Subject: [PATCH] update Project data model to use "Present" if no end date selected Sometimes, projects are ongoing, and it would be helpful to be able to show that, similar to how it's done in the Work section. This is what's expected in the `formatDateRange` function, and it's more consistent with the way things are done in other parts of the application. --- src/modals/sections/ProjectModal.js | 13 ++++++++++--- src/templates/blocks/Projects/ProjectsA.js | 4 ++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/modals/sections/ProjectModal.js b/src/modals/sections/ProjectModal.js index 05788bae3..024da74a3 100644 --- a/src/modals/sections/ProjectModal.js +++ b/src/modals/sections/ProjectModal.js @@ -10,7 +10,8 @@ import ModalEvents from '../../constants/ModalEvents'; const initialValues = { title: '', link: '', - date: '', + startDate: '', + endDate: '', summary: '', }; @@ -20,7 +21,13 @@ const ProjectModal = () => { const schema = Yup.object().shape({ title: Yup.string().required(t('shared.forms.validation.required')), link: Yup.string().url(t('shared.forms.validation.url')), - date: Yup.date().max(new Date()), + startDate: Yup.date(), + endDate: Yup.date().when( + 'startDate', + (startDate, yupSchema) => + startDate && + yupSchema.min(startDate, t('shared.forms.validation.dateRange')), + ), summary: Yup.string(), }); @@ -54,7 +61,7 @@ const ProjectModal = () => { type="date" label={t('shared.forms.startDate')} placeholder="6th August 208" - {...getFieldProps(formik, schema, 'date')} + {...getFieldProps(formik, schema, 'startDate')} /> { )} - {item.date && ( + {item.startDate && (
( {formatDateRange( { - startDate: item.date, + startDate: item.startDate, endDate: item.endDate, language, },