mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-06 22:56:27 +00:00
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
'use client'
|
|
|
|
import { FC } from 'react';
|
|
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
|
import dayjs from 'dayjs';
|
|
import { DatePicker } from 'antd';
|
|
|
|
type Props = {};
|
|
|
|
const DateRangePicker: FC<Props> = () => {
|
|
const searchParams = useSearchParams();
|
|
const router = useRouter()
|
|
const path = usePathname()
|
|
|
|
const startDate = searchParams!.get('start_date') as string || dayjs().subtract(1, 'month')
|
|
const endDate = searchParams!.get('end_date') as string || dayjs()
|
|
|
|
const handleChange = (values: any) => {
|
|
if (values) {
|
|
const url = `${path}?start_date=${dayjs(values[0]).format('YYYY-MM-DD')}&end_date=${dayjs(values[1]).format('YYYY-MM-DD')}`
|
|
router.replace(url)
|
|
} else {
|
|
const url = `${path}`
|
|
router.replace(url)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<DatePicker.RangePicker size='small' className='p-2 rounded-lg' picker='date' format='MMM DD, YYYY'
|
|
onChange={handleChange} defaultValue={[dayjs(startDate), dayjs(endDate)]}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default DateRangePicker; |