fix: Date Range Picker behavior (#17914)

* fix: Date Range Picker behaviour

* remove console log

* update

* update

* update css

---------

Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
Anik Dhabal BabuandPeer Richelsen authored and GitHub committed 2024-12-03 02:10:23 +05:30
1 parent 58b77b2a16
commit 0aa58c1095
4 files changed
+27 -26

No files matched your search

@@ -1,5 +1,6 @@
import { useState } from "react";
import type { Dayjs } from "@calcom/dayjs";
import dayjs from "@calcom/dayjs";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { DateRangePicker } from "@calcom/ui";
@@ -22,10 +23,10 @@ export const DateSelect = () => {
const { filter, setConfigFilters } = useFilterContext();
const currentDate = dayjs();
const [initialStartDate, initialEndDate, range] = filter?.dateRange || [null, null, null];
const [startDate, setStartDate] = useState(initialStartDate);
const [endDate, setEndDate] = useState(initialEndDate);
const startValue = startDate?.toDate() || null;
const endValue = endDate?.toDate() || null;
const [startDate, setStartDate] = useState<Dayjs>(initialStartDate);
const [endDate, setEndDate] = useState<Dayjs | undefined>(initialEndDate);
const startValue = startDate.toDate();
const endValue = endDate?.toDate();
const [selectedPreset, setSelectedPreset] = useState(presetOptions.find((c) => c.value === range));
const updateDateRange = (val: string | null) => {
@@ -77,11 +78,13 @@ export const DateSelect = () => {
maxDate={currentDate.toDate()}
disabled={false}
onDatesChange={({ startDate, endDate }) => {
setConfigFilters({
dateRange: [dayjs(startDate), dayjs(endDate), null],
});
if (startDate && endDate) {
setConfigFilters({
dateRange: [dayjs(startDate), dayjs(endDate), null],
});
}
setStartDate(dayjs(startDate));
setEndDate(dayjs(endDate));
setEndDate(endDate ? dayjs(endDate) : endDate);
setSelectedPreset(presetOptions.find((c) => c.value === null));
}}
/>