/** * External dependencies */ import { __ } from '@wordpress/i18n'; import moment from 'moment'; import { SelectControl } from '@wordpress/components'; import { DatePicker } from '@woocommerce/components'; import { dateValidationMessages } from '@woocommerce/date'; import { IMPORT_STORE_NAME } from '@woocommerce/data'; import { withDispatch } from '@wordpress/data'; function HistoricalDataPeriodSelector( { dateFormat, disabled, setImportPeriod, value, } ) { const onSelectChange = ( val ) => { setImportPeriod( val ); }; const onDatePickerChange = ( val ) => { const dateModified = true; if ( val.date && val.date.isValid ) { setImportPeriod( val.date.format( dateFormat ), dateModified ); } else { setImportPeriod( val.text, dateModified ); } }; const getDatePickerError = ( momentDate ) => { if ( ! momentDate.isValid() || value.date.length !== dateFormat.length ) { return dateValidationMessages.invalid; } if ( momentDate.isAfter( new Date(), 'day' ) ) { return dateValidationMessages.future; } return null; }; const getDatePicker = () => { const momentDate = moment( value.date, dateFormat ); return (