|
@@ -63,7 +63,7 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
|
|
|
const [showDatePicker, setShowDatePicker] = useState<DatePickerState | null>(null);
|
|
const [showDatePicker, setShowDatePicker] = useState<DatePickerState | null>(null);
|
|
const actionSheetRef = useRef<any>(null);
|
|
const actionSheetRef = useRef<any>(null);
|
|
- const [selectedYear, setSelectedYear] = useState<number>(new Date().getFullYear());
|
|
|
|
|
|
+ const [selectedYear, setSelectedYear] = useState<number | null>(new Date().getFullYear());
|
|
const [selectedMonth, setSelectedMonth] = useState<number | null>(new Date().getMonth() + 1);
|
|
const [selectedMonth, setSelectedMonth] = useState<number | null>(new Date().getMonth() + 1);
|
|
const [selectedDay, setSelectedDay] = useState<number | null>(null);
|
|
const [selectedDay, setSelectedDay] = useState<number | null>(null);
|
|
|
|
|
|
@@ -197,10 +197,11 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
}, [regions, selectedDates]);
|
|
}, [regions, selectedDates]);
|
|
|
|
|
|
const currentYear = new Date().getFullYear();
|
|
const currentYear = new Date().getFullYear();
|
|
- const years = Array.from({ length: 120 }, (_, i) => currentYear - 80 + i);
|
|
|
|
|
|
+ const years = ['-', ...Array.from({ length: 120 }, (_, i) => (currentYear - 80 + i).toString())];
|
|
|
|
|
|
- const getAvailableMonths = (year: number) => {
|
|
|
|
|
|
+ const getAvailableMonths = (year: number | null) => {
|
|
const allMonths = [
|
|
const allMonths = [
|
|
|
|
+ { label: '-', value: null },
|
|
{ label: 'Jan', value: 1 },
|
|
{ label: 'Jan', value: 1 },
|
|
{ label: 'Feb', value: 2 },
|
|
{ label: 'Feb', value: 2 },
|
|
{ label: 'Mar', value: 3 },
|
|
{ label: 'Mar', value: 3 },
|
|
@@ -221,10 +222,10 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
const months = getAvailableMonths(selectedYear);
|
|
const months = getAvailableMonths(selectedYear);
|
|
|
|
|
|
const getDaysInMonth = (
|
|
const getDaysInMonth = (
|
|
- year: number,
|
|
|
|
|
|
+ year: number | null,
|
|
month: number | null
|
|
month: number | null
|
|
): Array<{ label: string; value: number | null }> => {
|
|
): Array<{ label: string; value: number | null }> => {
|
|
- if (!month) return [{ label: '-', value: null }];
|
|
|
|
|
|
+ if (!year || !month) return [{ label: '-', value: null }];
|
|
|
|
|
|
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 }];
|
|
@@ -245,27 +246,25 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
) => {
|
|
) => {
|
|
setShowDatePicker({ regionId, field });
|
|
setShowDatePicker({ regionId, field });
|
|
|
|
|
|
- if (initialDate && initialDate.year && initialDate.month) {
|
|
|
|
- setSelectedYear(initialDate.year);
|
|
|
|
- setSelectedMonth(initialDate.month);
|
|
|
|
|
|
+ if (initialDate && initialDate.year) {
|
|
|
|
+ setSelectedYear(initialDate.year || null);
|
|
|
|
+ setSelectedMonth(initialDate.month || null);
|
|
setSelectedDay(initialDate.day || null);
|
|
setSelectedDay(initialDate.day || null);
|
|
} else {
|
|
} else {
|
|
- const today = new Date();
|
|
|
|
-
|
|
|
|
- setSelectedYear(today.getFullYear());
|
|
|
|
- setSelectedMonth(today.getMonth() + 1);
|
|
|
|
- setSelectedDay(today.getDate());
|
|
|
|
|
|
+ setSelectedYear(null);
|
|
|
|
+ setSelectedMonth(null);
|
|
|
|
+ setSelectedDay(null);
|
|
}
|
|
}
|
|
|
|
|
|
actionSheetRef.current?.show();
|
|
actionSheetRef.current?.show();
|
|
};
|
|
};
|
|
|
|
|
|
const handleDateConfirm = () => {
|
|
const handleDateConfirm = () => {
|
|
- if (showDatePicker && selectedMonth) {
|
|
|
|
|
|
+ if (showDatePicker) {
|
|
const dateValue: DateValue = {
|
|
const dateValue: DateValue = {
|
|
- year: selectedYear,
|
|
|
|
- month: selectedMonth,
|
|
|
|
- day: selectedDay
|
|
|
|
|
|
+ year: selectedYear || null,
|
|
|
|
+ month: selectedMonth || null,
|
|
|
|
+ day: selectedDay || null
|
|
};
|
|
};
|
|
|
|
|
|
setRegions(
|
|
setRegions(
|
|
@@ -337,10 +336,10 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
id: region.id,
|
|
id: region.id,
|
|
quality: region.quality ?? 3,
|
|
quality: region.quality ?? 3,
|
|
hidden: region.hidden,
|
|
hidden: region.hidden,
|
|
- year_from: region.visitStartDate?.year || new Date().getFullYear(),
|
|
|
|
- year_to: region.visitEndDate?.year || new Date().getFullYear(),
|
|
|
|
- month_from: region.visitStartDate?.month || new Date().getMonth() + 1,
|
|
|
|
- month_to: region.visitEndDate?.month || new Date().getMonth() + 1,
|
|
|
|
|
|
+ year_from: region.visitStartDate?.year || null,
|
|
|
|
+ year_to: region.visitEndDate?.year || null,
|
|
|
|
+ month_from: region.visitStartDate?.month || null,
|
|
|
|
+ month_to: region.visitEndDate?.month || null,
|
|
day_from: region.visitStartDate?.day || null,
|
|
day_from: region.visitStartDate?.day || null,
|
|
day_to: region.visitEndDate?.day || null
|
|
day_to: region.visitEndDate?.day || null
|
|
};
|
|
};
|
|
@@ -372,10 +371,10 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
id: region.id,
|
|
id: region.id,
|
|
quality: region.quality ?? 3,
|
|
quality: region.quality ?? 3,
|
|
hidden: region.hidden,
|
|
hidden: region.hidden,
|
|
- year_from: region.visitStartDate?.year || new Date().getFullYear(),
|
|
|
|
- year_to: region.visitEndDate?.year || new Date().getFullYear(),
|
|
|
|
- month_from: region.visitStartDate?.month || new Date().getMonth() + 1,
|
|
|
|
- month_to: region.visitEndDate?.month || new Date().getMonth() + 1,
|
|
|
|
|
|
+ year_from: region.visitStartDate?.year || null,
|
|
|
|
+ year_to: region.visitEndDate?.year || null,
|
|
|
|
+ month_from: region.visitStartDate?.month || null,
|
|
|
|
+ month_to: region.visitEndDate?.month || null,
|
|
day_from: region.visitStartDate?.day || null,
|
|
day_from: region.visitStartDate?.day || null,
|
|
day_to: region.visitEndDate?.day || null
|
|
day_to: region.visitEndDate?.day || null
|
|
};
|
|
};
|
|
@@ -542,10 +541,11 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
fontFamily: 'montserrat-600'
|
|
fontFamily: 'montserrat-600'
|
|
}}
|
|
}}
|
|
pickerData={months ? months?.map((m) => m.label) : []}
|
|
pickerData={months ? months?.map((m) => m.label) : []}
|
|
- selectedValue={months?.find((m) => m.value === selectedMonth)?.label || 'Jan'}
|
|
|
|
|
|
+ selectedValue={months.find((m) => m.value === selectedMonth)?.label || '-'}
|
|
onValueChange={(value: string) => {
|
|
onValueChange={(value: string) => {
|
|
const month = months?.find((m) => m.label === value);
|
|
const month = months?.find((m) => m.label === value);
|
|
setSelectedMonth(month?.value || null);
|
|
setSelectedMonth(month?.value || null);
|
|
|
|
+ if (!month?.value) setSelectedDay(null);
|
|
}}
|
|
}}
|
|
/>
|
|
/>
|
|
</View>
|
|
</View>
|
|
@@ -558,9 +558,15 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
itemStyle={{ fontSize: 16, fontFamily: 'montserrat-600' }}
|
|
itemStyle={{ fontSize: 16, fontFamily: 'montserrat-600' }}
|
|
isCyclic={true}
|
|
isCyclic={true}
|
|
pickerData={years}
|
|
pickerData={years}
|
|
- selectedValue={selectedYear.toString()}
|
|
|
|
- onValueChange={(value: number) => {
|
|
|
|
- setSelectedYear(value);
|
|
|
|
|
|
+ selectedValue={selectedYear ? selectedYear.toString() : '-'}
|
|
|
|
+ onValueChange={(value: string) => {
|
|
|
|
+ if (value === '-') {
|
|
|
|
+ setSelectedYear(null);
|
|
|
|
+ setSelectedMonth(null);
|
|
|
|
+ setSelectedDay(null);
|
|
|
|
+ } else {
|
|
|
|
+ setSelectedYear(Number(value));
|
|
|
|
+ }
|
|
}}
|
|
}}
|
|
/>
|
|
/>
|
|
</View>
|
|
</View>
|