From e35a0405412bcf5b8a7af5d029cf8d40cbd6ed90 Mon Sep 17 00:00:00 2001
From: Lukas <lukas.budginas@gmail.com>
Date: Mon, 25 Nov 2024 14:16:16 +0200
Subject: [PATCH] Update DateTimePicker component with first and last dates

---
 components/DateTimePicker.tsx               | 13 +++++++++----
 components/Witnesses/VotesHistoryDialog.tsx |  7 +++++--
 components/searchRanges/SearchRanges.tsx    |  3 ++-
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/components/DateTimePicker.tsx b/components/DateTimePicker.tsx
index 3241d826..63b84e4f 100644
--- a/components/DateTimePicker.tsx
+++ b/components/DateTimePicker.tsx
@@ -13,7 +13,8 @@ interface DateTimePickerProps {
   setDate: (date: Date) => void;
   side?: "left" | "top" | "right" | "bottom";
   disableFutureDates?: boolean;
-  endDate?: Date;
+  lastDate?: Date;
+  firstDate?: Date;
 }
 
 const DateTimePicker: React.FC<DateTimePickerProps> = ({
@@ -21,7 +22,8 @@ const DateTimePicker: React.FC<DateTimePickerProps> = ({
   setDate,
   side,
   disableFutureDates = true,
-  endDate,
+  lastDate,
+  firstDate,
 }) => {
   const handleSelect = (date: Date | undefined) => {
     if (date) {
@@ -39,8 +41,11 @@ const DateTimePicker: React.FC<DateTimePickerProps> = ({
 
   const disableFuture: Matcher | Matcher[] | undefined | any = (date: Date) => {
     if (disableFutureDates) {
-      if (endDate) {
-        return date > endDate || date < new Date("1900-01-01");
+      if (firstDate) {
+        return date < firstDate || date < new Date("1900-01-01");
+      }
+      if (lastDate) {
+        return date > lastDate || date < new Date("1900-01-01");
       }
       return date > new Date() || date < new Date("1900-01-01");
     }
diff --git a/components/Witnesses/VotesHistoryDialog.tsx b/components/Witnesses/VotesHistoryDialog.tsx
index c859c774..e41d0218 100644
--- a/components/Witnesses/VotesHistoryDialog.tsx
+++ b/components/Witnesses/VotesHistoryDialog.tsx
@@ -185,7 +185,7 @@ const VotesHistoryDialog: React.FC<VotersDialogProps> = ({
                   date={fromDate}
                   setDate={setFromDate}
                   side="bottom"
-                  endDate={toDate}
+                  lastDate={toDate}
                 />
               </div>
               <div>
@@ -194,6 +194,7 @@ const VotesHistoryDialog: React.FC<VotersDialogProps> = ({
                   date={toDate}
                   setDate={setToDate}
                   side="bottom"
+                  firstDate={fromDate}
                 />
               </div>
             </div>
@@ -273,7 +274,9 @@ const VotesHistoryDialog: React.FC<VotersDialogProps> = ({
                       <TableCell
                         className="text-right"
                         data-testid="current-voter-power"
-                      > {fetchHivePower(vote.vests.toString(), isHP)}
+                      >
+                        {" "}
+                        {fetchHivePower(vote.vests.toString(), isHP)}
                       </TableCell>
                     </TableRow>
                   ))}
diff --git a/components/searchRanges/SearchRanges.tsx b/components/searchRanges/SearchRanges.tsx
index 33e1a240..1830d852 100644
--- a/components/searchRanges/SearchRanges.tsx
+++ b/components/searchRanges/SearchRanges.tsx
@@ -175,7 +175,7 @@ const SearchRanges: React.FC<SearchRangesProps> = ({
             <DateTimePicker
               date={startDate || new Date()}
               setDate={setStartDate}
-              endDate={endDate}
+              lastDate={endDate}
             />
           </div>
           <div className="flex flex-col w-full">
@@ -183,6 +183,7 @@ const SearchRanges: React.FC<SearchRangesProps> = ({
             <DateTimePicker
               date={endDate || new Date()}
               setDate={setEndDate}
+              firstDate={startDate}
             />
           </div>
         </div>
-- 
GitLab