"use client"; import { format } from "date-fns"; import * as React from "react"; import type { DateRange } from "react-day-picker"; import { classNames as cn } from "@calcom/lib"; import { Button } from "../../button"; import { Popover, PopoverContent, PopoverTrigger } from "../../popover"; import { Calendar } from "./Calendar"; type DatePickerWithRangeProps = { dates: { startDate: Date; endDate?: Date }; onDatesChange: ({ startDate, endDate }: { startDate?: Date; endDate?: Date }) => void; disabled?: boolean; }; export function DatePickerWithRange({ className, dates, onDatesChange, disabled, }: React.HTMLAttributes & DatePickerWithRangeProps) { // Even though this is uncontrolled we need to do a bit of logic to improve the UX when selecting dates function _onDatesChange(onChangeValues: DateRange | undefined) { if (onChangeValues?.from && !onChangeValues?.to) { onDatesChange({ startDate: onChangeValues.from, endDate: onChangeValues.from }); } else { onDatesChange({ startDate: onChangeValues?.from, endDate: onChangeValues?.to }); } } return (
_onDatesChange(values)} numberOfMonths={1} disabled={disabled} />
); }