|
@@ -31,7 +31,9 @@ import {
|
|
|
usePostAddSharedTripMutation,
|
|
|
usePostCancelEventMutation,
|
|
|
usePostGetPhotosForRegionMutation,
|
|
|
- usePostUpdateEventMutation
|
|
|
+ usePostSetFullMutation,
|
|
|
+ usePostUpdateEventMutation,
|
|
|
+ usePostUpdateSharedTripMutation
|
|
|
} from '@api/events';
|
|
|
import { SheetManager } from 'react-native-actions-sheet';
|
|
|
import PhotosForRegionModal from '../Components/PhotosForRegionModal/PhotosForRegionModal';
|
|
@@ -39,6 +41,7 @@ import { API_HOST } from 'src/constants';
|
|
|
import AddMapPinModal from '../Components/AddMapPinModal';
|
|
|
import { NAVIGATION_PAGES } from 'src/types';
|
|
|
import TrashSvg from 'assets/icons/travels-screens/trash-solid.svg';
|
|
|
+import { useGetRegionsWithFlagQuery } from '@api/regions';
|
|
|
|
|
|
const EventSchema = yup.object({
|
|
|
title: yup.string().required().min(3),
|
|
@@ -51,7 +54,6 @@ const EventSchema = yup.object({
|
|
|
|
|
|
const CreateSharedTripScreen = ({ route }: { route: any }) => {
|
|
|
const eventId = route.params?.eventId;
|
|
|
- // TO DO
|
|
|
const eventData = route.params?.event;
|
|
|
const token = (storage.get('token', StoreType.STRING) as string) ?? null;
|
|
|
const navigation = useNavigation();
|
|
@@ -59,8 +61,10 @@ const CreateSharedTripScreen = ({ route }: { route: any }) => {
|
|
|
const richText = useRef<RichEditor | null>(null);
|
|
|
const { mutateAsync: getPhotosForRegion } = usePostGetPhotosForRegionMutation();
|
|
|
const { mutateAsync: addSharedTrip } = usePostAddSharedTripMutation();
|
|
|
- const { mutateAsync: updateEvent } = usePostUpdateEventMutation();
|
|
|
+ const { mutateAsync: updateEvent } = usePostUpdateSharedTripMutation();
|
|
|
const { mutateAsync: cancelEvent } = usePostCancelEventMutation();
|
|
|
+ const { mutateAsync: setFull } = usePostSetFullMutation();
|
|
|
+ const { data: regionslist } = useGetRegionsWithFlagQuery(true);
|
|
|
|
|
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
|
const [calendarVisible, setCalendarVisible] = useState<'start_date' | 'end_date' | null>(null);
|
|
@@ -119,9 +123,9 @@ const CreateSharedTripScreen = ({ route }: { route: any }) => {
|
|
|
|
|
|
const initialData: any = {
|
|
|
title: eventData?.title ?? '',
|
|
|
- start_date: eventData?.start_date ?? '',
|
|
|
- end_date: eventData?.end_date ?? '',
|
|
|
- tentative: eventData?.tentative ?? 0,
|
|
|
+ start_date: eventData?.date_from ?? '',
|
|
|
+ end_date: eventData?.date_to ?? '',
|
|
|
+ tentative: eventData?.date_tentative ?? 0,
|
|
|
photo: null,
|
|
|
details: eventData?.details ?? ''
|
|
|
};
|
|
@@ -136,10 +140,21 @@ const CreateSharedTripScreen = ({ route }: { route: any }) => {
|
|
|
});
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (eventData && eventData.regions) {
|
|
|
- setRegions(eventData.regions);
|
|
|
+ if (eventData && eventData.regions && regionslist && regionslist.data) {
|
|
|
+ const parsedRegions = JSON.parse(eventData.regions);
|
|
|
+ let regionsData: any = [];
|
|
|
+ parsedRegions.forEach((region: any) => {
|
|
|
+ const regionWithFlag = regionslist.data?.find((r: any) => r.id === +region);
|
|
|
+ regionsData.push({
|
|
|
+ flag1: regionWithFlag?.flag ?? '',
|
|
|
+ flag2: null,
|
|
|
+ region_name: regionWithFlag?.name ?? '',
|
|
|
+ id: regionWithFlag?.id ?? region.id
|
|
|
+ });
|
|
|
+ });
|
|
|
+ setRegions(regionsData);
|
|
|
}
|
|
|
- }, [eventData]);
|
|
|
+ }, [eventData, regionslist]);
|
|
|
|
|
|
const handleCancelTrip = () => {
|
|
|
setModalInfo({
|
|
@@ -201,7 +216,7 @@ const CreateSharedTripScreen = ({ route }: { route: any }) => {
|
|
|
|
|
|
if (eventId) {
|
|
|
await updateEvent(
|
|
|
- { token, event_id: eventId, event: JSON.stringify(newTrip) },
|
|
|
+ { token, trip_id: eventId, trip: JSON.stringify(newTrip) },
|
|
|
{
|
|
|
onSuccess: (res) => {
|
|
|
setIsSubmitting(false);
|
|
@@ -213,7 +228,6 @@ const CreateSharedTripScreen = ({ route }: { route: any }) => {
|
|
|
}
|
|
|
);
|
|
|
} else {
|
|
|
- console.log('newTrip', newTrip);
|
|
|
await addSharedTrip(
|
|
|
{ token, trip: JSON.stringify(newTrip) },
|
|
|
{
|
|
@@ -292,92 +306,83 @@ const CreateSharedTripScreen = ({ route }: { route: any }) => {
|
|
|
/>
|
|
|
</TouchableOpacity>
|
|
|
|
|
|
- {eventId ? (
|
|
|
- <Input
|
|
|
- header={'NomadMania region'}
|
|
|
- inputMode={'none'}
|
|
|
- editable={false}
|
|
|
- value={eventData?.region_name}
|
|
|
- />
|
|
|
- ) : (
|
|
|
- <View>
|
|
|
- <Text
|
|
|
- style={{
|
|
|
- color: Colors.DARK_BLUE,
|
|
|
- fontSize: getFontSize(14),
|
|
|
- fontFamily: 'redhat-700',
|
|
|
- marginBottom: 8
|
|
|
- }}
|
|
|
- >
|
|
|
- NomadMania regions
|
|
|
- </Text>
|
|
|
-
|
|
|
- <TouchableOpacity
|
|
|
- style={styles.addRegionBtn}
|
|
|
- onPress={() =>
|
|
|
- navigation.navigate(
|
|
|
- ...([
|
|
|
- NAVIGATION_PAGES.ADD_REGIONS,
|
|
|
- { regionsParams: regions, editId: eventId, isSharedTrip: true }
|
|
|
- ] as never)
|
|
|
- )
|
|
|
- }
|
|
|
- >
|
|
|
- <Text style={styles.addRegionBtntext}>Add Region</Text>
|
|
|
- </TouchableOpacity>
|
|
|
-
|
|
|
- {regions && regions.length ? (
|
|
|
- <View style={styles.regionsContainer}>
|
|
|
- {regions.map((region) => {
|
|
|
- const [name, ...rest] = region.region_name?.split(/ – | - /);
|
|
|
- const subname = rest?.join(' - ');
|
|
|
+ <View>
|
|
|
+ <Text
|
|
|
+ style={{
|
|
|
+ color: Colors.DARK_BLUE,
|
|
|
+ fontSize: getFontSize(14),
|
|
|
+ fontFamily: 'redhat-700',
|
|
|
+ marginBottom: 8
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ NomadMania regions
|
|
|
+ </Text>
|
|
|
|
|
|
- return (
|
|
|
- <View key={region.id} style={styles.regionItem}>
|
|
|
- <View style={styles.regionHeader}>
|
|
|
+ <TouchableOpacity
|
|
|
+ style={styles.addRegionBtn}
|
|
|
+ onPress={() =>
|
|
|
+ navigation.navigate(
|
|
|
+ ...([
|
|
|
+ NAVIGATION_PAGES.ADD_REGIONS,
|
|
|
+ { regionsParams: regions, editId: eventId, isSharedTrip: true }
|
|
|
+ ] as never)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ >
|
|
|
+ <Text style={styles.addRegionBtntext}>Add Region</Text>
|
|
|
+ </TouchableOpacity>
|
|
|
+
|
|
|
+ {regions && regions.length ? (
|
|
|
+ <View style={styles.regionsContainer}>
|
|
|
+ {regions.map((region) => {
|
|
|
+ const [name, ...rest] = region.region_name?.split(/ – | - /);
|
|
|
+ const subname = rest?.join(' - ');
|
|
|
+
|
|
|
+ return (
|
|
|
+ <View key={region.id} style={styles.regionItem}>
|
|
|
+ <View style={styles.regionHeader}>
|
|
|
+ <Image
|
|
|
+ source={{ uri: `${API_HOST}/img/flags_new/${region.flag1}` }}
|
|
|
+ style={styles.flagStyle}
|
|
|
+ />
|
|
|
+ {region.flag2 && (
|
|
|
<Image
|
|
|
- source={{ uri: `${API_HOST}/img/flags_new/${region.flag1}` }}
|
|
|
- style={styles.flagStyle}
|
|
|
+ source={{
|
|
|
+ uri: `${API_HOST}/img/flags_new/${region.flag2}`
|
|
|
+ }}
|
|
|
+ style={[styles.flagStyle, { marginLeft: -17 }]}
|
|
|
/>
|
|
|
- {region.flag2 && (
|
|
|
- <Image
|
|
|
- source={{
|
|
|
- uri: `${API_HOST}/img/flags_new/${region.flag2}`
|
|
|
- }}
|
|
|
- style={[styles.flagStyle, { marginLeft: -17 }]}
|
|
|
- />
|
|
|
- )}
|
|
|
- <View style={styles.nameContainer}>
|
|
|
- <Text style={styles.regionName}>{name}</Text>
|
|
|
- <Text style={styles.regionSubname}>{subname}</Text>
|
|
|
- </View>
|
|
|
+ )}
|
|
|
+ <View style={styles.nameContainer}>
|
|
|
+ <Text style={styles.regionName}>{name}</Text>
|
|
|
+ <Text style={styles.regionSubname}>{subname}</Text>
|
|
|
</View>
|
|
|
- <TouchableOpacity
|
|
|
- style={styles.trashBtn}
|
|
|
- onPress={() => handleDeleteRegion(region.id)}
|
|
|
- >
|
|
|
- <TrashSvg fill={Colors.WHITE} />
|
|
|
- </TouchableOpacity>
|
|
|
</View>
|
|
|
- );
|
|
|
- })}
|
|
|
- </View>
|
|
|
- ) : regionsError ? (
|
|
|
- <Text
|
|
|
- style={{
|
|
|
- color: Colors.RED,
|
|
|
- fontSize: getFontSize(12),
|
|
|
- fontFamily: 'redhat-600',
|
|
|
- marginTop: 5
|
|
|
- }}
|
|
|
- >
|
|
|
- {regionsError}
|
|
|
- </Text>
|
|
|
- ) : (
|
|
|
- <Text style={styles.noRegiosText}>No regions at the moment</Text>
|
|
|
- )}
|
|
|
- </View>
|
|
|
- )}
|
|
|
+ <TouchableOpacity
|
|
|
+ style={styles.trashBtn}
|
|
|
+ onPress={() => handleDeleteRegion(region.id)}
|
|
|
+ >
|
|
|
+ <TrashSvg fill={Colors.WHITE} />
|
|
|
+ </TouchableOpacity>
|
|
|
+ </View>
|
|
|
+ );
|
|
|
+ })}
|
|
|
+ </View>
|
|
|
+ ) : regionsError ? (
|
|
|
+ <Text
|
|
|
+ style={{
|
|
|
+ color: Colors.RED,
|
|
|
+ fontSize: getFontSize(12),
|
|
|
+ fontFamily: 'redhat-600',
|
|
|
+ marginTop: 5
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {regionsError}
|
|
|
+ </Text>
|
|
|
+ ) : (
|
|
|
+ <Text style={styles.noRegiosText}>No regions at the moment</Text>
|
|
|
+ )}
|
|
|
+ </View>
|
|
|
|
|
|
{regions && regions.length > 0 && photos.length > 0 ? (
|
|
|
<Input
|
|
@@ -538,6 +543,21 @@ const CreateSharedTripScreen = ({ route }: { route: any }) => {
|
|
|
Update trip
|
|
|
</Button>
|
|
|
|
|
|
+ <Button
|
|
|
+ variant={ButtonVariants.OPACITY}
|
|
|
+ containerStyles={{
|
|
|
+ backgroundColor: Colors.WHITE,
|
|
|
+ borderColor: Colors.BORDER_LIGHT
|
|
|
+ }}
|
|
|
+ textStyles={{ color: Colors.DARK_BLUE }}
|
|
|
+ onPress={async () => {
|
|
|
+ await setFull({ token, id: eventId, full: 1 });
|
|
|
+ navigation.goBack();
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ Set Full
|
|
|
+ </Button>
|
|
|
+
|
|
|
<Button
|
|
|
variant={ButtonVariants.OPACITY}
|
|
|
containerStyles={{
|