Bläddra i källkod

add visit calendar fixes

Viktoriia 1 månad sedan
förälder
incheckning
cdb2efdbc3
1 ändrade filer med 4 tillägg och 90 borttagningar
  1. 4 90
      src/screens/InAppScreens/TravelsScreen/EditNmDataScreen/index.tsx

+ 4 - 90
src/screens/InAppScreens/TravelsScreen/EditNmDataScreen/index.tsx

@@ -288,9 +288,8 @@ const EditNmDataScreen = ({ navigation, route }: { navigation: any; route: any }
         day: endDate.day || 31
       });
 
-      if (startDate.year <= endDate.year) {
-        return true;
-      }
+      if (!start || !end) return true;
+
       return start.isSameOrBefore(end);
     },
     []
@@ -361,12 +360,8 @@ const EditNmDataScreen = ({ navigation, route }: { navigation: any; route: any }
   }, [validateVisits, visits, navigation]);
 
   const currentYear = new Date().getFullYear();
-  const years = Array.from({ length: 100 }, (_, i) => currentYear - 99 + i);
+  const years = Array.from({ length: 120 }, (_, i) => currentYear - 80 + i);
   const getAvailableMonths = (year: number) => {
-    const currentDate = new Date();
-    const currentYear = currentDate.getFullYear();
-    const currentMonth = currentDate.getMonth() + 1;
-
     const allMonths = [
       { label: '-', value: null },
       { label: 'Jan', value: 1 },
@@ -383,10 +378,6 @@ const EditNmDataScreen = ({ navigation, route }: { navigation: any; route: any }
       { label: 'Dec', value: 12 }
     ];
 
-    if (year == currentYear) {
-      return allMonths.filter((month) => month.value === null || month.value <= currentMonth);
-    }
-
     return allMonths;
   };
 
@@ -398,20 +389,10 @@ const EditNmDataScreen = ({ navigation, route }: { navigation: any; route: any }
   ): Array<{ label: string; value: number | null }> => {
     if (!month) return [{ label: '-', value: null }];
 
-    const currentDate = new Date();
-    const currentYear = currentDate.getFullYear();
-    const currentMonth = currentDate.getMonth() + 1;
-    const currentDay = currentDate.getDate();
-
     const daysCount = moment(`${year}-${month}`, 'YYYY-M').daysInMonth();
     const days = [{ label: '-', value: null }];
 
-    let maxDay = daysCount;
-    if (year == currentYear && month == currentMonth) {
-      maxDay = currentDay;
-    }
-
-    for (let i = 1; i <= maxDay; i++) {
+    for (let i = 1; i <= daysCount; i++) {
       days.push({ label: i.toString(), value: i as never });
     }
 
@@ -420,34 +401,6 @@ const EditNmDataScreen = ({ navigation, route }: { navigation: any; route: any }
 
   const days = getDaysInMonth(selectedYear, selectedMonth);
 
-  useEffect(() => {
-    const currentDate = new Date();
-    const currentYear = currentDate.getFullYear();
-    const currentMonth = currentDate.getMonth() + 1;
-    const currentDay = currentDate.getDate();
-
-    if (selectedDay && selectedMonth) {
-      const maxDays = moment(`${selectedYear}-${selectedMonth}`, 'YYYY-M').daysInMonth();
-
-      if (selectedDay > maxDays) {
-        setSelectedDay(currentDay);
-      }
-
-      if (
-        selectedYear === currentYear &&
-        selectedMonth === currentMonth &&
-        selectedDay > currentDay
-      ) {
-        setSelectedDay(currentDay);
-      }
-    }
-
-    if (selectedYear === currentYear && selectedMonth && selectedMonth > currentMonth) {
-      setSelectedMonth(currentMonth);
-      setSelectedDay(currentDay);
-    }
-  }, [selectedYear, selectedMonth, selectedDay]);
-
   const openDatePicker = (
     visitId: number,
     field: 'startDate' | 'endDate',
@@ -686,20 +639,6 @@ const EditNmDataScreen = ({ navigation, route }: { navigation: any; route: any }
 
                 if (!month?.value) {
                   setSelectedDay(null);
-                } else {
-                  const currentDate = new Date();
-                  const currentYear = currentDate.getFullYear();
-                  const currentMonth = currentDate.getMonth() + 1;
-
-                  if (selectedDay) {
-                    const maxDaysInMonth = moment(
-                      `${selectedYear}-${month.value}`,
-                      'YYYY-M'
-                    ).daysInMonth();
-                    if (selectedDay > maxDaysInMonth) {
-                      setSelectedDay(maxDaysInMonth);
-                    }
-                  }
                 }
               }}
             />
@@ -716,31 +655,6 @@ const EditNmDataScreen = ({ navigation, route }: { navigation: any; route: any }
               selectedValue={selectedYear}
               onValueChange={(value: number) => {
                 setSelectedYear(value);
-
-                const currentDate = new Date();
-                const currentYear = currentDate.getFullYear();
-                const currentMonth = currentDate.getMonth() + 1;
-
-                if (value == currentYear && selectedMonth && selectedMonth > currentMonth) {
-                  setSelectedMonth(currentMonth);
-                  setSelectedDay(currentDate.getDate());
-                } else if (selectedMonth) {
-                  const maxDaysInMonth = moment(
-                    `${value}-${selectedMonth}`,
-                    'YYYY-M'
-                  ).daysInMonth();
-                  if (selectedDay && selectedDay > maxDaysInMonth) {
-                    setSelectedDay(maxDaysInMonth);
-                  }
-                  if (
-                    value === currentYear &&
-                    selectedMonth === currentMonth &&
-                    selectedDay &&
-                    selectedDay > currentDate.getDate()
-                  ) {
-                    setSelectedDay(currentDate.getDate());
-                  }
-                }
               }}
             />
           </View>