Skip to content

Commit

Permalink
No validate end date for existing programmes (#3847)
Browse files Browse the repository at this point in the history
  • Loading branch information
patryk-dabrowski authored May 13, 2024
1 parent 77d943e commit 67d8ccc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ export const programValidationSchema = (
t: TFunction<'translation', undefined>,
): Yup.ObjectSchema<any, any, any, any> =>
Yup.object().shape({
editMode: Yup.boolean(),
name: Yup.string()
.required(t('Programme Name is required'))
.min(3, t('Too short'))
.max(150, t('Too long')),
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'))
.transform((v) => (v instanceof Date && !isNaN(v.getTime()) ? v : null)),
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(
Expand All @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/containers/forms/ProgramForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const ProgramForm = ({ values }: ProgramFormPropTypes): ReactElement => {
initialFocusedDate={values.startDate}
fullWidth
decoratorEnd={<CalendarTodayRoundedIcon color="disabled" />}
minDate={today}
minDate={values.startDate}
data-cy="input-end-date"
/>
</Grid>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/containers/pages/program/CreateProgramPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const CreateProgramPage = (): ReactElement => {
});

const handleSubmit = async (values): Promise<void> => {
delete values.editMode;
const budgetValue = parseFloat(values.budget) ?? 0;
const budgetToFixed = !Number.isNaN(budgetValue)
? budgetValue.toFixed(2)
Expand Down Expand Up @@ -86,6 +87,7 @@ export const CreateProgramPage = (): ReactElement => {
};

const initialValues = {
editMode: false,
name: '',
programmeCode: '',
startDate: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const DuplicateProgramPage = (): ReactElement => {
useUserPartnerChoicesQuery();

const handleSubmit = async (values): Promise<void> => {
delete values.editMode;
const budgetValue = parseFloat(values.budget) ?? 0;
const budgetToFixed = !Number.isNaN(budgetValue)
? budgetValue.toFixed(2)
Expand Down Expand Up @@ -103,6 +104,7 @@ export const DuplicateProgramPage = (): ReactElement => {
} = data.program;

const initialValues = {
editMode: false,
name: `Copy of Programme: (${name})`,
programmeCode: '',
startDate,
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/containers/pages/program/EditProgramPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const EditProgramPage = (): ReactElement => {
} = data.program;

const handleSubmit = async (values): Promise<void> => {
delete values.editMode;
const budgetValue = parseFloat(values.budget) ?? 0;
const budgetToFixed = !Number.isNaN(budgetValue)
? budgetValue.toFixed(2)
Expand Down Expand Up @@ -123,6 +124,7 @@ export const EditProgramPage = (): ReactElement => {
};

const initialValues = {
editMode: true,
name,
programmeCode,
startDate,
Expand Down

0 comments on commit 67d8ccc

Please sign in to comment.