Skip to content

Commit

Permalink
Add date limit constant
Browse files Browse the repository at this point in the history
  • Loading branch information
NickPhura committed Mar 17, 2021
1 parent 24d1337 commit c622bc9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
14 changes: 13 additions & 1 deletion app/src/constants/dateFormats.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// See BC Gov standards: https://www2.gov.bc.ca/gov/content/governments/services-for-government/policies-procedures/web-content-development-guides/writing-for-the-web/web-style-guide/numbers
/**
* Date formats.
*
* See BC Gov standards: https://www2.gov.bc.ca/gov/content/governments/services-for-government/policies-procedures/web-content-development-guides/writing-for-the-web/web-style-guide/numbers
*/
export enum DATE_FORMAT {
ShortDateFormat = 'YYYY-MM-DD', //2020-01-05
ShortDateTimeFormat = 'YYYY-MM-DD, H:mm a', //2020-01-05, 3:30 pm
Expand All @@ -9,3 +13,11 @@ export enum DATE_FORMAT {
LongDateFormat = 'dddd, MMMM D, YYYY, H:mm a', //Monday, January 5, 2020, 3:30 pm
LongDateTimeFormat = 'dddd, MMMM D, YYYY, H:mm a' //Monday, January 5, 2020, 3:30 pm
}

/**
* Used to set the `min` and `max` values for `type="date"` fields.
*/
export enum DATE_LIMIT {
min = '1900-01-01',
max = '2100-12-31'
}
5 changes: 3 additions & 2 deletions app/src/features/projects/components/ProjectDetailsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FormControl, FormHelperText, Grid, InputLabel, MenuItem, Select, TextFi
import MultiAutocompleteFieldVariableSize, {
IMultiAutocompleteFieldOption
} from 'components/fields/MultiAutocompleteFieldVariableSize';
import { DATE_LIMIT } from 'constants/dateFormats';
import { useFormikContext } from 'formik';
import React from 'react';
import { getEndDateStringValidator, getStartDateStringValidator } from 'utils/YupValidations';
Expand Down Expand Up @@ -115,7 +116,7 @@ const ProjectDetailsForm: React.FC<IProjectDetailsFormProps> = (props) => {
required={true}
value={values.start_date}
type="date"
inputProps={{ min: '1900-01-01', max: '2100-12-31' }}
inputProps={{ min: DATE_LIMIT.min, max: DATE_LIMIT.max }}
onChange={handleChange}
error={touched.start_date && Boolean(errors.start_date)}
helperText={errors.start_date}
Expand All @@ -132,7 +133,7 @@ const ProjectDetailsForm: React.FC<IProjectDetailsFormProps> = (props) => {
variant="outlined"
value={values.end_date}
type="date"
inputProps={{ min: '1900-01-01', max: '2100-12-31' }}
inputProps={{ min: DATE_LIMIT.min, max: DATE_LIMIT.max }}
onChange={handleChange}
error={touched.end_date && Boolean(errors.end_date)}
helperText={errors.end_date}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
Typography
} from '@material-ui/core';
import { IMultiAutocompleteFieldOption } from 'components/fields/MultiAutocompleteFieldVariableSize';
import { DATE_LIMIT } from 'constants/dateFormats';
import { Formik, FormikHelpers } from 'formik';
import React from 'react';
import { getEndDateStringValidator, getStartDateStringValidator } from 'utils/YupValidations';
Expand Down Expand Up @@ -223,7 +224,7 @@ const ProjectFundingItemForm: React.FC<IProjectFundingItemFormProps> = (props) =
required={true}
value={values.start_date}
type="date"
inputProps={{ min: '1900-01-01', max: '2100-12-31' }}
inputProps={{ min: DATE_LIMIT.min, max: DATE_LIMIT.max }}
onChange={handleChange}
error={touched.start_date && Boolean(errors.start_date)}
helperText={errors.start_date}
Expand All @@ -241,7 +242,7 @@ const ProjectFundingItemForm: React.FC<IProjectFundingItemFormProps> = (props) =
required={true}
value={values.end_date}
type="date"
inputProps={{ min: '1900-01-01', max: '2100-12-31' }}
inputProps={{ min: DATE_LIMIT.min, max: DATE_LIMIT.max }}
onChange={handleChange}
error={touched.end_date && Boolean(errors.end_date)}
helperText={errors.end_date}
Expand Down

0 comments on commit c622bc9

Please sign in to comment.