woocommerce/plugins/woocommerce-admin/client/analytics/settings/default-date.js

53 lines
999 B
JavaScript
Raw Normal View History

2019-05-22 21:43:04 +00:00
/**
* External dependencies
*/
import { parse, stringify } from 'qs';
/**
* Internal dependencies
*/
import {
getCurrentDates,
getDateParamsFromQuery,
isoDateFormat,
} from 'lib/date';
2019-05-22 21:43:04 +00:00
/**
* WooCommerce dependencies
*/
import { DateRangeFilterPicker } from '@woocommerce/components';
const DefaultDate = ( { value, onChange } ) => {
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, '&' ) );
const { period, compare, before, after } = getDateParamsFromQuery( query );
const { primary: primaryDate, secondary: secondaryDate } = getCurrentDates(
query
);
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;