Skip to content

Commit

Permalink
feat: remove validation enforcing edited applicationClose to not be past
Browse files Browse the repository at this point in the history
  • Loading branch information
kriscooke committed Nov 30, 2020
1 parent 115ff32 commit 95f5832
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
11 changes: 5 additions & 6 deletions app/containers/Admin/ReportingYear/ReportingYearFormDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ function transformUiSchema(json, formFields) {

Object.keys(json).forEach((field) => {
const d = defaultMoment(formFields[field]);
json[field]['ui:disabled'] = d < now;
// Disable editing past dates, except for applicationCloseTime to enable them to extend it
// (interface is only displayed for the most recent period):
json[field]['ui:disabled'] =
field === 'applicationCloseTime' ? false : d.isBefore(now);
});

return json;
Expand Down Expand Up @@ -92,11 +95,7 @@ const ReportingYearFormDialog: React.FunctionComponent<Props> = ({
errors,
uiSchema
);
return validateExclusiveDateRanges(
year,
formData,
errors
);
return validateExclusiveDateRanges(year, formData, errors);
}}
onSubmit={handleSubmit}
>
Expand Down
18 changes: 14 additions & 4 deletions app/containers/Admin/ReportingYear/reportingYearValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ function validateExclusiveDateRanges(
return errors;
}

function validateApplicationDates(existingData, formData, errors, uiSchema) {
function validateApplicationDates(
existingData,
formData,
errors,
uiSchema,
// only the validation for creating new reporting periods sets this to true
// (so closed application windows can be re-opened by editing the reporting period):
validateFutureApplicationClose = false
) {
const openDate = formData.applicationOpenTime
? defaultMoment(formData.applicationOpenTime)
: undefined;
Expand All @@ -105,10 +113,12 @@ function validateApplicationDates(existingData, formData, errors, uiSchema) {
errors.addError(`${ERRORS.PAST_DATE} Application open time`);
}

const closeDateIsPast =
validateFutureApplicationClose && isPastDate(closeDate);
if (
Boolean(closeDate) &&
isPastDate(closeDate) &&
!uiSchema.applicationCloseTime['ui:disabled']
!uiSchema.applicationCloseTime['ui:disabled'] &&
closeDateIsPast
) {
errors.addError(`${ERRORS.PAST_DATE} Application close time`);
}
Expand Down Expand Up @@ -161,7 +171,7 @@ function validateReportingDates(formData, errors) {

function validateAllDates(existingData, formData, errors, uiSchema) {
return (
validateApplicationDates(existingData, formData, errors, uiSchema) &&
validateApplicationDates(existingData, formData, errors, uiSchema, true) &&
validateReportingDates(formData, errors)
);
}
Expand Down

0 comments on commit 95f5832

Please sign in to comment.