From 7ddcddcde54b264badaebdedc7e0948b81352dca Mon Sep 17 00:00:00 2001 From: Hristo Nedelkov Date: Sat, 16 Sep 2023 06:25:26 +0300 Subject: [PATCH] Add calendar filter --- .../Dashboard/DeviceUptime/DeviceUptime.tsx | 80 +++++++++++++++++-- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/src/pages/Dashboard/DeviceUptime/DeviceUptime.tsx b/src/pages/Dashboard/DeviceUptime/DeviceUptime.tsx index 1412e295..1b2acd1a 100644 --- a/src/pages/Dashboard/DeviceUptime/DeviceUptime.tsx +++ b/src/pages/Dashboard/DeviceUptime/DeviceUptime.tsx @@ -1,7 +1,10 @@ -import { Shadow, Text } from '@status-im/components'; +import { Calendar, Shadow, Text } from '@status-im/components'; import { Stack, XStack, YStack } from 'tamagui'; import UptimeChart from '../UptimeChart/UptimeChart'; import Icon from '../../../components/General/Icon'; +import { useState } from 'react'; +import { DateRange } from 'react-day-picker' +import { getMonthIndicesFromRange } from '../../../utilities'; const data: DataItem[] = [ @@ -71,7 +74,26 @@ interface DataItem { pa: number; pv: number; } + const DeviceUptime = () => { + const [isCalendarVisible, setIsCalendarVisible] = useState(false) + const [dateRange, setDateRange] = useState({ from: undefined, to: undefined }) + const [startMonth, endMonth] = getMonthIndicesFromRange(dateRange) + + const handleRangeSelect = ( + range: DateRange | undefined, + // @NOTE: You can take selectedDay: Date, + ) => { + if (!range) { + setDateRange({ from: undefined, to: undefined }) + return + } + setDateRange(range) + if (range.from && range.to) { + setIsCalendarVisible(false) + } + } + return ( { }} > - - Device Uptime - - 98% - - 1.56% + + + + Balance + + setIsCalendarVisible(true)} + > + + 24,273 + + + 1.56% + + + + setIsCalendarVisible(prev => !prev)} + style={{ + border: '2px solid #09101C14', + height: 'fit-content', + padding: '3px', + borderRadius: '10px', + }} + > + + {dateRange?.from ? dateRange.from.toLocaleDateString() + ' ->' : 'Start Date -> '}{' '} + + + {dateRange?.to ? dateRange.to.toLocaleDateString() : ' End Date'} + + - + {isCalendarVisible && ( + + )} +