2022-01-24 21:16:50 +05:00
|
|
|
import { memo } from 'react'
|
2021-12-13 10:19:57 +05:00
|
|
|
import { DatePicker } from 'antd'
|
2022-01-24 21:16:50 +05:00
|
|
|
import { PickerDateProps } from 'antd/lib/date-picker/generatePicker'
|
|
|
|
import moment, { Moment } from 'moment'
|
2021-12-13 10:19:57 +05:00
|
|
|
|
2022-01-24 21:16:50 +05:00
|
|
|
import { defaultFormat } from '@utils'
|
|
|
|
|
|
|
|
export type DatePickerWrapperProps = PickerDateProps<Moment> & {
|
2022-03-16 16:10:28 +05:00
|
|
|
value?: Moment,
|
|
|
|
onChange?: (date: Moment | null) => any
|
2022-01-24 21:16:50 +05:00
|
|
|
isUTC?: boolean
|
2021-12-13 10:19:57 +05:00
|
|
|
}
|
|
|
|
|
2022-01-24 21:16:50 +05:00
|
|
|
export const DatePickerWrapper = memo<DatePickerWrapperProps>(({ value, onChange, isUTC, ...other }) => (
|
2021-12-13 10:19:57 +05:00
|
|
|
<DatePicker
|
2022-01-24 21:16:50 +05:00
|
|
|
showTime
|
2021-12-13 10:19:57 +05:00
|
|
|
allowClear={false}
|
2021-12-27 15:18:20 +05:00
|
|
|
format={defaultFormat}
|
2022-01-24 21:16:50 +05:00
|
|
|
defaultValue={moment()}
|
2022-03-16 16:10:28 +05:00
|
|
|
onChange={(date) => onChange?.(date)}
|
2022-04-18 10:51:50 +05:00
|
|
|
value={value && (isUTC ? moment.utc(value).local() : moment(value))}
|
2021-12-13 10:19:57 +05:00
|
|
|
{...other}
|
|
|
|
/>
|
2022-01-24 21:16:50 +05:00
|
|
|
))
|
2021-12-13 10:19:57 +05:00
|
|
|
|
|
|
|
export default DatePickerWrapper
|