瀏覽代碼

range calendar fix

Viktoriia 1 月之前
父節點
當前提交
3b900ec92c

+ 24 - 3
src/components/Calendars/RangeCalendar/index.tsx

@@ -32,7 +32,9 @@ export default function RangeCalendar({
   minDate: externalMinDate,
   maxDate: externalMaxDate,
   initialStartDate,
-  initialEndDate
+  initialEndDate,
+  initialYear,
+  initialMonth
 }: {
   isModalVisible: boolean;
   closeModal: (startDate?: string | null, endDate?: string | null) => void;
@@ -45,6 +47,8 @@ export default function RangeCalendar({
   maxDate?: string | Date | dayjs.Dayjs;
   initialStartDate?: string | null;
   initialEndDate?: string | null;
+  initialYear?: number;
+  initialMonth?: number;
 }) {
   const [selectedStartDate, setSelectedStartDate] = useState<string | null>(null);
   const [selectedEndDate, setSelectedEndDate] = useState<string | null>(null);
@@ -53,7 +57,6 @@ export default function RangeCalendar({
   const [endDate, setEndDate] = useState<DateType>(undefined);
   const [currentMonth, setCurrentMonth] = useState<number | undefined>(undefined);
   const [currentYear, setCurrentYear] = useState<number | undefined>(undefined);
-  const [toolTipVisible, setToolTipVisible] = useState<boolean>(false);
 
   const computedMinDate = externalMinDate
     ? dayjs(externalMinDate)
@@ -68,6 +71,8 @@ export default function RangeCalendar({
       : undefined;
 
   useEffect(() => {
+    if (!isModalVisible) return;
+
     if (allowRangeSelection) {
       if (initialStartDate) {
         const startDateObj = dayjs(initialStartDate);
@@ -75,6 +80,14 @@ export default function RangeCalendar({
         setStartDate(startDateObj);
         setCurrentMonth(startDateObj.month());
         setCurrentYear(startDateObj.year());
+      } else {
+        if (typeof initialYear === 'number' && initialYear !== 1) {
+          setCurrentYear(initialYear);
+        }
+
+        if (typeof initialMonth === 'number') {
+          setCurrentMonth(initialMonth - 1);
+        }
       }
       if (initialEndDate) {
         setSelectedEndDate(initialEndDate);
@@ -87,7 +100,15 @@ export default function RangeCalendar({
       setCurrentMonth(dateObj.month());
       setCurrentYear(dateObj.year());
     }
-  }, [isModalVisible, initialStartDate, initialEndDate, selectedDate, allowRangeSelection]);
+  }, [
+    isModalVisible,
+    initialStartDate,
+    initialEndDate,
+    selectedDate,
+    allowRangeSelection,
+    initialYear,
+    initialMonth
+  ]);
 
   const getDisabledDates = (date: DateType) => {
     const dateString = dayjs(date).format('YYYY-MM-DD');

+ 12 - 0
src/screens/InAppScreens/TravelsScreen/AddNewTrip2025Screen/index.tsx

@@ -729,6 +729,18 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
             ? `${regions[calendarVisibleForIndex].visitEndDate.year}-${regions[calendarVisibleForIndex].visitEndDate.month}-${regions[calendarVisibleForIndex].visitEndDate.day}`
             : undefined
         }
+        initialYear={
+          calendarVisibleForIndex !== null &&
+          regions?.[calendarVisibleForIndex]?.visitStartDate?.year
+            ? regions[calendarVisibleForIndex].visitStartDate.year
+            : undefined
+        }
+        initialMonth={
+          calendarVisibleForIndex !== null &&
+          regions?.[calendarVisibleForIndex]?.visitStartDate?.month
+            ? regions[calendarVisibleForIndex].visitStartDate.month
+            : undefined
+        }
       />
       <WarningModal
         type={'delete'}