Skip to content

Commit

Permalink
Merge pull request #33148 from DylanDylann/fix/33013
Browse files Browse the repository at this point in the history
Fix/33013: Add max date and min date for request
  • Loading branch information
tylerkaraszewski authored Dec 19, 2023
2 parents 0430482 + bb6e48c commit 8a283f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import dateAdd from 'date-fns/add';
import dateSubtract from 'date-fns/sub';
import Config from 'react-native-config';
import * as KeyCommand from 'react-native-key-command';
import * as Url from './libs/Url';
Expand All @@ -18,6 +20,8 @@ const PLATFORM_IOS = 'iOS';
const ANDROID_PACKAGE_NAME = 'com.expensify.chat';
const CURRENT_YEAR = new Date().getFullYear();
const PULL_REQUEST_NUMBER = Config?.PULL_REQUEST_NUMBER ?? '';
const MAX_DATE = dateAdd(new Date(), {years: 1});
const MIN_DATE = dateSubtract(new Date(), {years: 20});

const keyModifierControl = KeyCommand?.constants?.keyModifierControl ?? 'keyModifierControl';
const keyModifierCommand = KeyCommand?.constants?.keyModifierCommand ?? 'keyModifierCommand';
Expand Down Expand Up @@ -103,6 +107,8 @@ const CONST = {
// Numbers were arbitrarily picked.
MIN_YEAR: CURRENT_YEAR - 100,
MAX_YEAR: CURRENT_YEAR + 100,
MAX_DATE,
MIN_DATE,
},

DATE_BIRTH: {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/EditRequestCreatedPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

const propTypes = {
Expand Down Expand Up @@ -40,7 +41,8 @@ function EditRequestCreatedPage({defaultCreated, onSubmit}) {
inputID="created"
label={translate('common.date')}
defaultValue={defaultCreated}
maxDate={new Date()}
maxDate={CONST.CALENDAR_PICKER.MAX_DATE}
minDate={CONST.CALENDAR_PICKER.MIN_DATE}
/>
</FormProvider>
</ScreenWrapper>
Expand Down
7 changes: 3 additions & 4 deletions src/pages/iou/request/step/IOURequestStepDate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import dateAdd from 'date-fns/add';
import dateSubtract from 'date-fns/sub';
import React from 'react';
import DatePicker from '@components/DatePicker';
import FormProvider from '@components/Form/FormProvider';
Expand All @@ -11,6 +9,7 @@ import compose from '@libs/compose';
import * as IOUUtils from '@libs/IOUUtils';
import Navigation from '@libs/Navigation/Navigation';
import * as IOU from '@userActions/IOU';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import IOURequestStepRoutePropTypes from './IOURequestStepRoutePropTypes';
Expand Down Expand Up @@ -73,8 +72,8 @@ function IOURequestStepDate({
inputID="moneyRequestCreated"
label={translate('common.date')}
defaultValue={transaction.created}
maxDate={dateAdd(new Date(), {years: 1})}
minDate={dateSubtract(new Date(), {years: 20})}
maxDate={CONST.CALENDAR_PICKER.MAX_DATE}
minDate={CONST.CALENDAR_PICKER.MIN_DATE}
/>
</FormProvider>
</StepScreenWrapper>
Expand Down

0 comments on commit 8a283f0

Please sign in to comment.