2019-05-22 21:43:04 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { parse, stringify } from 'qs';
|
2020-08-13 02:05:22 +00:00
|
|
|
import { DateRangeFilterPicker } from '@woocommerce/components';
|
|
|
|
import { useSettings } from '@woocommerce/data';
|
2020-02-14 02:23:21 +00:00
|
|
|
import {
|
|
|
|
getCurrentDates,
|
|
|
|
getDateParamsFromQuery,
|
|
|
|
isoDateFormat,
|
2020-08-17 21:53:13 +00:00
|
|
|
} from '@woocommerce/date';
|
2019-05-22 21:43:04 +00:00
|
|
|
|
|
|
|
const DefaultDate = ( { value, onChange } ) => {
|
2020-03-25 03:20:17 +00:00
|
|
|
const { wcAdminSettings } = useSettings( 'wc_admin', [
|
|
|
|
'wcAdminSettings',
|
|
|
|
] );
|
|
|
|
const {
|
|
|
|
woocommerce_default_date_range: defaultDateRange,
|
|
|
|
} = wcAdminSettings;
|
2020-02-14 02:23:21 +00:00
|
|
|
const change = ( query ) => {
|
2019-05-22 21:43:04 +00:00
|
|
|
onChange( {
|
|
|
|
target: {
|
|
|
|
name: 'woocommerce_default_date_range',
|
|
|
|
value: stringify( query ),
|
|
|
|
},
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
const query = parse( value.replace( /&/g, '&' ) );
|
2020-03-25 03:20:17 +00:00
|
|
|
const { period, compare, before, after } = getDateParamsFromQuery(
|
|
|
|
query,
|
|
|
|
defaultDateRange
|
|
|
|
);
|
2020-02-14 02:23:21 +00:00
|
|
|
const { primary: primaryDate, secondary: secondaryDate } = getCurrentDates(
|
2020-03-25 03:20:17 +00:00
|
|
|
query,
|
|
|
|
defaultDateRange
|
2020-02-14 02:23:21 +00:00
|
|
|
);
|
2019-11-26 19:39:40 +00:00
|
|
|
const dateQuery = {
|
|
|
|
period,
|
|
|
|
compare,
|
|
|
|
before,
|
|
|
|
after,
|
|
|
|
primaryDate,
|
|
|
|
secondaryDate,
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<DateRangeFilterPicker
|
|
|
|
query={ query }
|
|
|
|
onRangeSelect={ change }
|
|
|
|
dateQuery={ dateQuery }
|
|
|
|
isoDateFormat={ isoDateFormat }
|
|
|
|
/>
|
|
|
|
);
|
2019-05-22 21:43:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default DefaultDate;
|