From 48746a2e6cdce7d6cfebd68a1b61eeb1ba10769c Mon Sep 17 00:00:00 2001 From: Kirill Date: Thu, 8 Aug 2024 13:15:48 +0300 Subject: [PATCH] ADH-4843 [UI] Set default values for DateRangePicker --- .../components/uikit/DateRangePicker/Tabs/CalendarTab.tsx | 6 +++--- .../components/uikit/DateRangePicker/Tabs/RangesTab.tsx | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/smart-frontend/app/src/components/uikit/DateRangePicker/Tabs/CalendarTab.tsx b/smart-frontend/app/src/components/uikit/DateRangePicker/Tabs/CalendarTab.tsx index 833774c648..fe8d369fe5 100644 --- a/smart-frontend/app/src/components/uikit/DateRangePicker/Tabs/CalendarTab.tsx +++ b/smart-frontend/app/src/components/uikit/DateRangePicker/Tabs/CalendarTab.tsx @@ -17,7 +17,7 @@ */ import { useEffect, useState } from 'react'; import Calendar from '@uikit/Calendar/Calendar'; -import { endOfDay, isBefore, startOfDay } from '@utils/date/calendarUtils'; +import { endOfDay, getToday, isBefore, startOfDay } from '@utils/date/calendarUtils'; import TabActions from './TabActions'; import ts from './Tabs.module.scss'; import FormField from '@uikit/FormField/FormField'; @@ -32,8 +32,8 @@ interface CalendarTabProps { const CalendarTab = ({ rangeFrom, rangeTo, onApply, onRevert }: CalendarTabProps) => { const [localDate, setLocalDate] = useState(undefined); - const [localRangeFrom, setLocalRangeFrom] = useState(rangeFrom); - const [localRangeTo, setLocalRangeTo] = useState(rangeTo); + const [localRangeFrom, setLocalRangeFrom] = useState(() => rangeFrom ?? startOfDay(getToday())); + const [localRangeTo, setLocalRangeTo] = useState(() => rangeTo ?? endOfDay(getToday())); useEffect(() => { if (localRangeFrom && localRangeTo) { diff --git a/smart-frontend/app/src/components/uikit/DateRangePicker/Tabs/RangesTab.tsx b/smart-frontend/app/src/components/uikit/DateRangePicker/Tabs/RangesTab.tsx index 9fe8989a12..0a50aadb60 100644 --- a/smart-frontend/app/src/components/uikit/DateRangePicker/Tabs/RangesTab.tsx +++ b/smart-frontend/app/src/components/uikit/DateRangePicker/Tabs/RangesTab.tsx @@ -33,14 +33,14 @@ interface RangesTabProps { } const RangesTab = ({ range, onApply, onRevert, rangesPreset }: RangesTabProps) => { - const [selectedRangeId, setSelectedRangeId] = useState(range); + const [selectedRangeId, setSelectedRangeId] = useState(range ?? rangesPreset[0].id); const handleClick = (item: RangePreset) => { setSelectedRangeId(item.id); }; const handleApply = () => { - selectedRangeId && onApply(selectedRangeId); + onApply(selectedRangeId); }; return ( @@ -61,10 +61,10 @@ const RangesTab = ({ range, onApply, onRevert, rangesPreset }: RangesTabProps) =
- + - +