|
@@ -288,9 +288,8 @@ const EditNmDataScreen = ({ navigation, route }: { navigation: any; route: any }
|
|
day: endDate.day || 31
|
|
day: endDate.day || 31
|
|
});
|
|
});
|
|
|
|
|
|
- if (startDate.year <= endDate.year) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
|
|
+ if (!start || !end) return true;
|
|
|
|
+
|
|
return start.isSameOrBefore(end);
|
|
return start.isSameOrBefore(end);
|
|
},
|
|
},
|
|
[]
|
|
[]
|
|
@@ -361,12 +360,8 @@ const EditNmDataScreen = ({ navigation, route }: { navigation: any; route: any }
|
|
}, [validateVisits, visits, navigation]);
|
|
}, [validateVisits, visits, navigation]);
|
|
|
|
|
|
const currentYear = new Date().getFullYear();
|
|
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 getAvailableMonths = (year: number) => {
|
|
- const currentDate = new Date();
|
|
|
|
- const currentYear = currentDate.getFullYear();
|
|
|
|
- const currentMonth = currentDate.getMonth() + 1;
|
|
|
|
-
|
|
|
|
const allMonths = [
|
|
const allMonths = [
|
|
{ label: '-', value: null },
|
|
{ label: '-', value: null },
|
|
{ label: 'Jan', value: 1 },
|
|
{ label: 'Jan', value: 1 },
|
|
@@ -383,10 +378,6 @@ const EditNmDataScreen = ({ navigation, route }: { navigation: any; route: any }
|
|
{ label: 'Dec', value: 12 }
|
|
{ label: 'Dec', value: 12 }
|
|
];
|
|
];
|
|
|
|
|
|
- if (year == currentYear) {
|
|
|
|
- return allMonths.filter((month) => month.value === null || month.value <= currentMonth);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
return allMonths;
|
|
return allMonths;
|
|
};
|
|
};
|
|
|
|
|
|
@@ -398,20 +389,10 @@ const EditNmDataScreen = ({ navigation, route }: { navigation: any; route: any }
|
|
): Array<{ label: string; value: number | null }> => {
|
|
): Array<{ label: string; value: number | null }> => {
|
|
if (!month) return [{ label: '-', value: 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 daysCount = moment(`${year}-${month}`, 'YYYY-M').daysInMonth();
|
|
const days = [{ label: '-', value: null }];
|
|
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 });
|
|
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);
|
|
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 = (
|
|
const openDatePicker = (
|
|
visitId: number,
|
|
visitId: number,
|
|
field: 'startDate' | 'endDate',
|
|
field: 'startDate' | 'endDate',
|
|
@@ -686,20 +639,6 @@ const EditNmDataScreen = ({ navigation, route }: { navigation: any; route: any }
|
|
|
|
|
|
if (!month?.value) {
|
|
if (!month?.value) {
|
|
setSelectedDay(null);
|
|
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}
|
|
selectedValue={selectedYear}
|
|
onValueChange={(value: number) => {
|
|
onValueChange={(value: number) => {
|
|
setSelectedYear(value);
|
|
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>
|
|
</View>
|