浏览代码

trips25 fixes

Viktoriia 1 月之前
父节点
当前提交
8653dda40c

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

@@ -51,6 +51,8 @@ export default function RangeCalendar({
   const [singleDate, setSingleDate] = useState<DateType>(undefined);
   const [startDate, setStartDate] = useState<DateType>(undefined);
   const [endDate, setEndDate] = useState<DateType>(undefined);
+  const [currentMonth, setCurrentMonth] = useState<number | undefined>(undefined);
+  const [currentYear, setCurrentYear] = useState<number | undefined>(undefined);
 
   const computedMinDate = externalMinDate
     ? dayjs(externalMinDate)
@@ -67,18 +69,24 @@ export default function RangeCalendar({
   useEffect(() => {
     if (allowRangeSelection) {
       if (initialStartDate) {
+        const startDateObj = dayjs(initialStartDate);
         setSelectedStartDate(initialStartDate);
-        setStartDate(dayjs(initialStartDate));
+        setStartDate(startDateObj);
+        setCurrentMonth(startDateObj.month());
+        setCurrentYear(startDateObj.year());
       }
       if (initialEndDate) {
         setSelectedEndDate(initialEndDate);
         setEndDate(dayjs(initialEndDate));
       }
     } else if (selectedDate) {
+      const dateObj = dayjs(selectedDate);
       setSelectedStartDate(selectedDate);
-      setSingleDate(dayjs(selectedDate));
+      setSingleDate(dateObj);
+      setCurrentMonth(dateObj.month());
+      setCurrentYear(dateObj.year());
     }
-  }, [initialStartDate, initialEndDate, selectedDate, allowRangeSelection]);
+  }, [isModalVisible, initialStartDate, initialEndDate, selectedDate, allowRangeSelection]);
 
   const getDisabledDates = (date: DateType) => {
     const dateString = dayjs(date).format('YYYY-MM-DD');
@@ -128,6 +136,10 @@ export default function RangeCalendar({
     setStartDate(undefined);
     setEndDate(undefined);
     setSingleDate(undefined);
+    setTimeout(() => {
+      setCurrentMonth(undefined);
+      setCurrentYear(undefined);
+    }, 200);
   };
 
   const handleClose = () => {
@@ -137,6 +149,10 @@ export default function RangeCalendar({
     setStartDate(undefined);
     setEndDate(undefined);
     setSingleDate(undefined);
+    setTimeout(() => {
+      setCurrentMonth(undefined);
+      setCurrentYear(undefined);
+    }, 200);
   };
 
   return (
@@ -148,10 +164,13 @@ export default function RangeCalendar({
     >
       <View style={styles.modalContent}>
         <DateTimePicker
+          key={`${currentMonth}-${currentYear}`}
           mode={allowRangeSelection ? 'range' : 'single'}
           date={singleDate}
           startDate={startDate}
           endDate={endDate}
+          month={currentMonth}
+          year={currentYear}
           onChange={handleDateChange}
           minDate={computedMinDate}
           maxDate={computedMaxDate}

+ 16 - 9
src/screens/InAppScreens/TravelsScreen/AddNewTrip2025Screen/index.tsx

@@ -143,7 +143,14 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
     };
   };
 
-  const autoFillAfterAppend = (list: RegionWithDates[]) => {
+  const normalizeRegion = (r: RegionWithDates): RegionWithDates => ({
+    ...r,
+    _instanceId: r._instanceId ?? `r-${instanceCounterRef.current++}`,
+    visitStartDate: r.visitStartDate ? { ...r.visitStartDate } : null,
+    visitEndDate: r.visitEndDate ? { ...r.visitEndDate } : null
+  });
+
+  const autoFillAfterAppend = (list: RegionWithDates[], oldCount: number) => {
     if (!list || list.length === 0) return list;
 
     const updated = [...list];
@@ -165,18 +172,15 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
       }
     }
 
-    if (lastWithDateIndex === null) return updated;
+    if (lastWithDateIndex === null || lastWithDateIndex < oldCount - 1) return updated;
 
     const lastDate: DateValue = updated[lastWithDateIndex].visitEndDate as DateValue;
 
     for (let i = lastWithDateIndex + 1; i < updated.length; i++) {
       const r = updated[i];
-      const hasStart = !!(
-        r.visitStartDate?.year &&
-        r.visitStartDate?.month &&
-        r.visitStartDate?.day
-      );
-      const hasEnd = !!(r.visitEndDate?.year && r.visitEndDate?.month && r.visitEndDate?.day);
+
+      const hasStart = isFullDate(r.visitStartDate);
+      const hasEnd = isFullDate(r.visitEndDate);
 
       if (!hasStart || !hasEnd) {
         updated[i] = {
@@ -203,7 +207,10 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
 
   useEffect(() => {
     if (route.params?.regionsToSave) {
-      const filled = autoFillAfterAppend(route.params.regionsToSave);
+      const oldRegions = route.params.regionsToSave.filter((r: any) => r._instanceId);
+      const oldCount = oldRegions.length;
+      const normalized = route.params.regionsToSave.map(normalizeRegion);
+      const filled = autoFillAfterAppend(normalized, oldCount);
 
       setRegions(filled);
       setShouldScrollToEmpty(true);