|
|
@@ -15,12 +15,13 @@ import {
|
|
|
useGetTripQuery,
|
|
|
usePostDeleteTripMutation,
|
|
|
usePostUpdateTripMutation,
|
|
|
- usePostSetNewTripMutation
|
|
|
+ usePostSetNewTripMutation,
|
|
|
+ useGetRegionsForTripsQuery
|
|
|
} from '@api/trips';
|
|
|
import { styles } from './styles';
|
|
|
|
|
|
import { ActivityIndicator } from 'react-native-paper';
|
|
|
-import ActionSheet, { ActionSheetRef } from 'react-native-actions-sheet';
|
|
|
+import { ActionSheetRef } from 'react-native-actions-sheet';
|
|
|
import SummarySheet from '../Components/SummarySheet';
|
|
|
|
|
|
interface DateValue {
|
|
|
@@ -58,6 +59,9 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
const token = storage.get('token', StoreType.STRING) as string;
|
|
|
const { data: editData } = useGetTripQuery(token, editTripId, Boolean(editTripId));
|
|
|
const navigation = useNavigation();
|
|
|
+ const { defaultRegion, defaultYear } = route.params;
|
|
|
+ const [allRegions, setAllRegions] = useState<RegionAddData[] | null>([]);
|
|
|
+ const { data } = useGetRegionsForTripsQuery(true);
|
|
|
|
|
|
const [description, setDescription] = useState<string>('');
|
|
|
const [regions, setRegions] = useState<RegionWithDates[] | null>(null);
|
|
|
@@ -82,6 +86,16 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
const scrollRef = React.useRef<ScrollView>(null);
|
|
|
const instanceCounterRef = React.useRef(1);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ if (data && data.regions) {
|
|
|
+ setAllRegions(data.regions);
|
|
|
+ if (defaultRegion && !editTripId && !route.params?.regionsToSave) {
|
|
|
+ const regionFromApi = data.regions?.find((r) => r.id === defaultRegion.id);
|
|
|
+ regionFromApi && setRegions([normalizeRegion(regionFromApi)]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, [data]);
|
|
|
+
|
|
|
const getCalendarProps = (
|
|
|
index: number | null
|
|
|
): { defaultMode: CalendarMode; initialApproxYear: number | null } => {
|
|
|
@@ -484,7 +498,7 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
onSuccess: (res) => {
|
|
|
console.log('res', res)
|
|
|
if (res && res.result === 'OK') {
|
|
|
- navigation.popTo(...([NAVIGATION_PAGES.TRIPS_2025, { saved: true }] as never));
|
|
|
+ navigation.popTo(NAVIGATION_PAGES.TRIPS_2025, { saved: true });
|
|
|
}
|
|
|
setIsLoading(null);
|
|
|
},
|
|
|
@@ -520,7 +534,7 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
{
|
|
|
onSuccess: (res) => {
|
|
|
if (res && res.result === 'OK') {
|
|
|
- navigation.popTo(...([NAVIGATION_PAGES.TRIPS_2025, { updated: true }] as never));
|
|
|
+ navigation.popTo(NAVIGATION_PAGES.TRIPS_2025, { updated: true });
|
|
|
}
|
|
|
setIsLoading(null);
|
|
|
},
|
|
|
@@ -631,7 +645,7 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
navigation.navigate(
|
|
|
...([
|
|
|
NAVIGATION_PAGES.ADD_REGIONS_NEW,
|
|
|
- { regionsParams: regions, editId: editTripId }
|
|
|
+ { regionsParams: regions, editId: editTripId, defaultYear, allRegions }
|
|
|
] as never)
|
|
|
)
|
|
|
}
|
|
|
@@ -709,7 +723,10 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
}
|
|
|
initialYear={
|
|
|
calendarVisibleForIndex !== null
|
|
|
- ? regions?.[calendarVisibleForIndex]?.visitStartDate?.year ?? undefined
|
|
|
+ ? regions?.[calendarVisibleForIndex]?.visitStartDate?.year
|
|
|
+ ?? regions?.find((_, i) => i !== calendarVisibleForIndex && regions[i]?.visitStartDate?.year)
|
|
|
+ ?.visitStartDate?.year
|
|
|
+ ?? (defaultYear ? Number(defaultYear) : undefined)
|
|
|
: undefined
|
|
|
}
|
|
|
initialMonth={
|
|
|
@@ -739,7 +756,7 @@ const AddNewTripScreen = ({ route }: { route: any }) => {
|
|
|
onSuccess: (res) => {
|
|
|
if (res && res.result === 'OK') {
|
|
|
navigation.popTo(
|
|
|
- ...([NAVIGATION_PAGES.TRIPS_2025, { deleted: true }] as never)
|
|
|
+ NAVIGATION_PAGES.TRIPS_2025, { deleted: true }
|
|
|
);
|
|
|
}
|
|
|
setIsLoading(null);
|