2022-03-01 11:34:15 +05:00
|
|
|
import { memo } from 'react'
|
|
|
|
import { DatePicker, } from 'antd'
|
|
|
|
import moment, { Moment } from 'moment'
|
|
|
|
import { RangeValue } from 'rc-picker/lib/interface'
|
|
|
|
import { RangePickerSharedProps } from 'rc-picker/lib/RangePicker'
|
|
|
|
|
|
|
|
import { defaultFormat } from '@utils'
|
|
|
|
|
|
|
|
const { RangePicker } = DatePicker
|
|
|
|
|
|
|
|
export type DateRangeWrapperProps = RangePickerSharedProps<Moment> & {
|
2022-05-31 17:18:05 +05:00
|
|
|
value?: RangeValue<Moment>,
|
2022-03-01 11:34:15 +05:00
|
|
|
isUTC?: boolean
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:18:05 +05:00
|
|
|
const normalizeDates = (value?: RangeValue<Moment>, isUTC?: boolean): RangeValue<Moment> => {
|
|
|
|
if (!value) return [null, null]
|
|
|
|
return [
|
|
|
|
value[0] ? (isUTC ? moment.utc(value[0]).local() : moment(value[0])) : null,
|
|
|
|
value[1] ? (isUTC ? moment.utc(value[1]).local() : moment(value[1])) : null,
|
|
|
|
]
|
|
|
|
}
|
2022-03-01 11:34:15 +05:00
|
|
|
|
2022-03-01 19:32:29 +05:00
|
|
|
export const DateRangeWrapper = memo<DateRangeWrapperProps>(({ value, isUTC, ...other }) => (
|
2022-03-01 11:34:15 +05:00
|
|
|
<RangePicker
|
|
|
|
showTime
|
|
|
|
allowClear={false}
|
|
|
|
format={defaultFormat}
|
2022-03-01 19:32:29 +05:00
|
|
|
defaultValue={[
|
|
|
|
moment().subtract(1, 'days').startOf('day'),
|
|
|
|
moment().startOf('day'),
|
|
|
|
]}
|
2022-03-01 11:34:15 +05:00
|
|
|
value={normalizeDates(value)}
|
|
|
|
{...other}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
|
|
|
|
export default DateRangeWrapper
|