1- import { useTranslation } from 'react-i18next ' ;
1+ import { Button } from '@mui/material ' ;
22import { addDays , endOfDay , startOfDay } from 'date-fns' ;
3- import { useFormContext } from 'react-hook-form' ;
43import { 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' ;
97import { DatePicker } from 'shared/components/DatePicker' ;
8+ import { DateType } from 'shared/components/DatePicker/DatePicker.types' ;
9+ import { CheckboxController , SelectController } from 'shared/components/FormComponents' ;
1010import { Modal } from 'shared/components/Modal' ;
11+ import { Svg } from 'shared/components/Svg' ;
1112import {
1213 StyledBodyLarge ,
1314 StyledFlexAllCenter ,
@@ -17,15 +18,14 @@ import {
1718 theme ,
1819} from 'shared/styles' ;
1920import { 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' ;
2422import {
2523 ExportDataFormValues ,
2624 ExportDateType ,
2725 SupplementaryFilesFormValues ,
2826} from '../../ExportDataSetting.types' ;
27+ import { ExportSettingsPopupProps } from './ExportSettingsPopup.types' ;
28+ import { getDataExportedOptions , getDateTypeOptions } from './ExportSettingsPopup.utils' ;
2929
3030export 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