diff --git a/frontend/src/components/programs/CreateProgram/programValidationSchema.ts b/frontend/src/components/programs/CreateProgram/programValidationSchema.ts index 19a03ab1b8..3eebf69ba8 100644 --- a/frontend/src/components/programs/CreateProgram/programValidationSchema.ts +++ b/frontend/src/components/programs/CreateProgram/programValidationSchema.ts @@ -7,6 +7,7 @@ export const programValidationSchema = ( t: TFunction<'translation', undefined>, ): Yup.ObjectSchema => Yup.object().shape({ + editMode: Yup.boolean(), name: Yup.string() .required(t('Programme Name is required')) .min(3, t('Too short')) @@ -14,7 +15,10 @@ export const programValidationSchema = ( programmeCode: Yup.string() .min(4, t('Programme code has to be 4 characters')) .max(4, t('Programme code has to be 4 characters')) - .matches(/^[A-Za-z0-9\-/.]{4}$/, t('Programme code may only contain letters, digits and \'-\', \'/\', \'.\'.')) + .matches( + /^[A-Za-z0-9\-/.]{4}$/, + t("Programme code may only contain letters, digits and '-', '/', '.'."), + ) .nullable(), startDate: Yup.date() .required(t('Start Date is required')) @@ -22,7 +26,6 @@ export const programValidationSchema = ( endDate: Yup.date() .transform((curr, orig) => (orig === '' ? null : curr)) .required(t('End Date is required')) - .min(today, t('End Date cannot be in the past')) .when('startDate', (startDate, schema) => startDate instanceof Date && !isNaN(startDate.getTime()) ? schema.min( @@ -32,7 +35,12 @@ export const programValidationSchema = ( ).format('YYYY-MM-DD')}`, ) : schema, - ), + ) + .when('editMode', ([editMode], schema) => { + return editMode + ? schema + : schema.min(today, t('End Date cannot be in the past')); + }), sector: Yup.string().required(t('Sector is required')), dataCollectingTypeCode: Yup.string().required( t('Data Collecting Type is required'), diff --git a/frontend/src/containers/forms/ProgramForm.tsx b/frontend/src/containers/forms/ProgramForm.tsx index 0ae50862eb..942b77fed4 100644 --- a/frontend/src/containers/forms/ProgramForm.tsx +++ b/frontend/src/containers/forms/ProgramForm.tsx @@ -79,7 +79,7 @@ export const ProgramForm = ({ values }: ProgramFormPropTypes): ReactElement => { initialFocusedDate={values.startDate} fullWidth decoratorEnd={} - minDate={today} + minDate={values.startDate} data-cy="input-end-date" /> diff --git a/frontend/src/containers/pages/program/CreateProgramPage.tsx b/frontend/src/containers/pages/program/CreateProgramPage.tsx index 09e8525dd3..4de542ee3f 100644 --- a/frontend/src/containers/pages/program/CreateProgramPage.tsx +++ b/frontend/src/containers/pages/program/CreateProgramPage.tsx @@ -47,6 +47,7 @@ export const CreateProgramPage = (): ReactElement => { }); const handleSubmit = async (values): Promise => { + delete values.editMode; const budgetValue = parseFloat(values.budget) ?? 0; const budgetToFixed = !Number.isNaN(budgetValue) ? budgetValue.toFixed(2) @@ -90,6 +91,7 @@ export const CreateProgramPage = (): ReactElement => { }; const initialValues = { + editMode: false, name: '', programmeCode: '', startDate: '', diff --git a/frontend/src/containers/pages/program/DuplicateProgramPage.tsx b/frontend/src/containers/pages/program/DuplicateProgramPage.tsx index a1ab3cbcd9..ebabedf0b5 100644 --- a/frontend/src/containers/pages/program/DuplicateProgramPage.tsx +++ b/frontend/src/containers/pages/program/DuplicateProgramPage.tsx @@ -47,6 +47,7 @@ export const DuplicateProgramPage = (): ReactElement => { useUserPartnerChoicesQuery(); const handleSubmit = async (values): Promise => { + delete values.editMode; const budgetValue = parseFloat(values.budget) ?? 0; const budgetToFixed = !Number.isNaN(budgetValue) ? budgetValue.toFixed(2) @@ -106,6 +107,7 @@ export const DuplicateProgramPage = (): ReactElement => { } = data.program; const initialValues = { + editMode: false, name: `Copy of Programme: (${name})`, programmeCode: '', startDate, diff --git a/frontend/src/containers/pages/program/EditProgramPage.tsx b/frontend/src/containers/pages/program/EditProgramPage.tsx index 255d021898..9e6687bddb 100644 --- a/frontend/src/containers/pages/program/EditProgramPage.tsx +++ b/frontend/src/containers/pages/program/EditProgramPage.tsx @@ -88,6 +88,7 @@ export const EditProgramPage = (): ReactElement => { } = data.program; const handleSubmit = async (values): Promise => { + delete values.editMode; const budgetValue = parseFloat(values.budget) ?? 0; const budgetToFixed = !Number.isNaN(budgetValue) ? budgetValue.toFixed(2) @@ -126,6 +127,7 @@ export const EditProgramPage = (): ReactElement => { }; const initialValues = { + editMode: true, name, programmeCode, startDate,