import Calendar from 'assets/calendar-alt.svg'; import DatePickerForm from 'components/forms/DatePickerForm'; import { endOfYear, isSameDay } from 'date-fns'; import useLocale from 'hooks/useLocale'; import { dateFormat } from 'lib/date'; import PropTypes from 'prop-types'; import React, { useState } from 'react'; import { Icon, Modal } from 'react-basics'; import { FormattedMessage } from 'react-intl'; import DropDown from './DropDown'; export const filterOptions = [ { label: , value: '1day' }, { label: ( ), value: '24hour', }, { label: , value: '-1day', }, { label: , value: '1week', divider: true, }, { label: ( ), value: '7day', }, { label: , value: '1month', divider: true, }, { label: ( ), value: '30day', }, { label: ( ), value: '90day', }, { label: , value: '1year' }, { label: , value: 'all', divider: true, }, { label: , value: 'custom', divider: true, }, ]; function DateFilter({ value, startDate, endDate, onChange, className, options }) { const [showPicker, setShowPicker] = useState(false); const displayValue = value === 'custom' ? ( handleChange('custom')} /> ) : ( value ); async function handleChange(value) { if (value === 'custom') { setShowPicker(true); return; } onChange(value); } function handlePickerChange(value) { setShowPicker(false); onChange(value); } return ( <> {showPicker && ( setShowPicker(false)} /> )} ); } const CustomRange = ({ startDate, endDate, onClick }) => { const { locale } = useLocale(); function handleClick(e) { e.stopPropagation(); onClick(); } return ( <> {dateFormat(startDate, 'd LLL y', locale)} {!isSameDay(startDate, endDate) && ` — ${dateFormat(endDate, 'd LLL y', locale)}`} ); }; DateFilter.propTypes = { value: PropTypes.string, startDate: PropTypes.instanceOf(Date), endDate: PropTypes.instanceOf(Date), onChange: PropTypes.func, className: PropTypes.string, }; export default DateFilter;