Skip to content

Commit

Permalink
ADH-4843 [UI] Set default values for DateRangePicker
Browse files Browse the repository at this point in the history
  • Loading branch information
rimakan committed Aug 8, 2024
1 parent d80bab6 commit 48746a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -32,8 +32,8 @@ interface CalendarTabProps {

const CalendarTab = ({ rangeFrom, rangeTo, onApply, onRevert }: CalendarTabProps) => {
const [localDate, setLocalDate] = useState<Date | undefined>(undefined);
const [localRangeFrom, setLocalRangeFrom] = useState<Date | undefined>(rangeFrom);
const [localRangeTo, setLocalRangeTo] = useState<Date | undefined>(rangeTo);
const [localRangeFrom, setLocalRangeFrom] = useState<Date | undefined>(() => rangeFrom ?? startOfDay(getToday()));
const [localRangeTo, setLocalRangeTo] = useState<Date | undefined>(() => rangeTo ?? endOfDay(getToday()));

useEffect(() => {
if (localRangeFrom && localRangeTo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ interface RangesTabProps {
}

const RangesTab = ({ range, onApply, onRevert, rangesPreset }: RangesTabProps) => {
const [selectedRangeId, setSelectedRangeId] = useState<DynamicDateRange | undefined>(range);
const [selectedRangeId, setSelectedRangeId] = useState<DynamicDateRange>(range ?? rangesPreset[0].id);

const handleClick = (item: RangePreset) => {
setSelectedRangeId(item.id);
};

const handleApply = () => {
selectedRangeId && onApply(selectedRangeId);
onApply(selectedRangeId);
};

return (
Expand All @@ -61,10 +61,10 @@ const RangesTab = ({ range, onApply, onRevert, rangesPreset }: RangesTabProps) =
<div className={ts.dateRangePickerTab__right}>
<div className={ts.dateRangePickerTab__rightInputs}>
<FormField label="From">
<Input size="small" value={selectedRangeId ?? ''} readOnly />
<Input size="small" value={selectedRangeId} readOnly />
</FormField>
<FormField label="To">
<Input size="small" value={selectedRangeId ? 'now' : ''} readOnly disabled={!!selectedRangeId} />
<Input size="small" value="now" readOnly />
</FormField>
</div>
<TabActions onApply={handleApply} onRevert={onRevert} />
Expand Down

0 comments on commit 48746a2

Please sign in to comment.