Skip to content

Commit 659761a

Browse files
committed
feat: Add date processing to onCloseCallback to both custom date datepickers
1 parent efd1b82 commit 659761a

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

src/shared/features/AppletSettings/ExportDataSetting/Popups/ExportSettingsPopup/ExportSettingsPopup.tsx

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
import { useTranslation } from 'react-i18next';
1+
import { Button } from '@mui/material';
22
import { addDays, endOfDay, startOfDay } from 'date-fns';
3-
import { useFormContext } from 'react-hook-form';
43
import { useMemo } from 'react';
5-
import { Button } from '@mui/material';
4+
import { useFormContext } from 'react-hook-form';
5+
import { useTranslation } from 'react-i18next';
66

7-
import { Svg } from 'shared/components/Svg';
8-
import { CheckboxController, SelectController } from 'shared/components/FormComponents';
97
import { DatePicker } from 'shared/components/DatePicker';
8+
import { DateType } from 'shared/components/DatePicker/DatePicker.types';
9+
import { CheckboxController, SelectController } from 'shared/components/FormComponents';
1010
import { Modal } from 'shared/components/Modal';
11+
import { Svg } from 'shared/components/Svg';
1112
import {
1213
StyledBodyLarge,
1314
StyledFlexAllCenter,
@@ -17,15 +18,14 @@ import {
1718
theme,
1819
} from 'shared/styles';
1920
import { SelectEvent } from 'shared/types';
20-
import { DateType } from 'shared/components/DatePicker/DatePicker.types';
2121

22-
import { ExportSettingsPopupProps } from './ExportSettingsPopup.types';
23-
import { getDataExportedOptions, getDateTypeOptions } from './ExportSettingsPopup.utils';
2422
import {
2523
ExportDataFormValues,
2624
ExportDateType,
2725
SupplementaryFilesFormValues,
2826
} from '../../ExportDataSetting.types';
27+
import { ExportSettingsPopupProps } from './ExportSettingsPopup.types';
28+
import { getDataExportedOptions, getDateTypeOptions } from './ExportSettingsPopup.utils';
2929

3030
export const ExportSettingsPopup = ({
3131
isOpen,
@@ -57,19 +57,22 @@ export const ExportSettingsPopup = ({
5757
},
5858
};
5959

60-
const onFromDateSubmit = (date: DateType) => {
60+
const processFromDate = (date: DateType | undefined) => {
6161
if (!date) return;
6262
setValue('fromDate', startOfDay(date));
6363
};
64-
const onToDateSubmit = (date: DateType) => {
64+
65+
const processToDate = (date: DateType | undefined) => {
6566
if (!date) return;
6667
setValue('toDate', endOfDay(date));
6768
};
69+
6870
const onDatePickerClose = () => {
6971
if (toDate < fromDate) {
7072
setValue('toDate', addDays(fromDate, 1));
7173
}
7274
};
75+
7376
const onDateTypeChange = (e: SelectEvent) => {
7477
const dateType = e.target.value as ExportDateType;
7578
const maxDate = getMaxDate();
@@ -144,8 +147,11 @@ export const ExportSettingsPopup = ({
144147
<DatePicker
145148
{...commonProps}
146149
name="fromDate"
147-
onCloseCallback={onDatePickerClose}
148-
onSubmitCallback={onFromDateSubmit}
150+
onCloseCallback={(date) => {
151+
processFromDate(date);
152+
onDatePickerClose();
153+
}}
154+
onSubmitCallback={processFromDate}
149155
label={t('startDate')}
150156
minDate={minDate}
151157
data-testid={`${dataTestId}-from-date`}
@@ -157,7 +163,8 @@ export const ExportSettingsPopup = ({
157163
<DatePicker
158164
{...commonProps}
159165
name="toDate"
160-
onSubmitCallback={onToDateSubmit}
166+
onCloseCallback={processToDate}
167+
onSubmitCallback={processToDate}
161168
minDate={fromDate}
162169
label={t('endDate')}
163170
data-testid={`${dataTestId}-to-date`}

0 commit comments

Comments
 (0)