Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[196847] No validate end date for existing programmes #3847

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -47,6 +47,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 @@ -90,6 +91,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 @@ -47,6 +47,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 @@ -106,6 +107,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 @@ -88,6 +88,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 @@ -126,6 +127,7 @@ export const EditProgramPage = (): ReactElement => {
};

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