|
|
@@ -20,13 +20,14 @@ import ChevronLeftIcon from 'assets/icons/chevron-left.svg';
|
|
|
import { getFontSize } from 'src/utils';
|
|
|
import { FlashList, FlashListRef } from '@shopify/flash-list';
|
|
|
import WarningIcon from 'assets/icons/warning.svg';
|
|
|
+import moment from 'moment';
|
|
|
|
|
|
const TripsScreen = ({ route }: { route: any }) => {
|
|
|
const token = storage.get('token', StoreType.STRING) as string;
|
|
|
const navigation = useNavigation();
|
|
|
const [isDatePickerVisible, setDatePickerVisible] = useState(false);
|
|
|
const { data: years, refetch } = useGetTripsYearsQuery(token, true);
|
|
|
- const [selectedYear, setSelectedYear] = useState<string | null>('2025');
|
|
|
+ const [selectedYear, setSelectedYear] = useState<string | null>(moment().year().toString());
|
|
|
const { data: tripsData, refetch: refetchTrips } = useGetTripsForYearQuery(
|
|
|
token,
|
|
|
selectedYear as string,
|
|
|
@@ -86,7 +87,7 @@ const TripsScreen = ({ route }: { route: any }) => {
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (years && years.data && !selectedYear) {
|
|
|
- // setSelectedYear(years.data[0]);
|
|
|
+ setSelectedYear(years.data[0]);
|
|
|
}
|
|
|
}, [years]);
|
|
|
|
|
|
@@ -104,13 +105,19 @@ const TripsScreen = ({ route }: { route: any }) => {
|
|
|
}, [tripsData]);
|
|
|
|
|
|
const renderItem = useCallback(
|
|
|
- ({ item }: { item: TripsData }) => <TripItem item={item} isNew={true} />,
|
|
|
- []
|
|
|
+ ({ item }: { item: TripsData }) => (
|
|
|
+ <TripItem item={item} isNew={Number(selectedYear) >= 2025} />
|
|
|
+ ),
|
|
|
+ [selectedYear]
|
|
|
);
|
|
|
|
|
|
const onAddNewTripPress = useCallback(() => {
|
|
|
- navigation.navigate(NAVIGATION_PAGES.ADD_TRIP_2025 as never);
|
|
|
- }, [navigation]);
|
|
|
+ if (Number(selectedYear) >= 2025) {
|
|
|
+ navigation.navigate(NAVIGATION_PAGES.ADD_TRIP_2025 as never);
|
|
|
+ } else {
|
|
|
+ navigation.navigate(NAVIGATION_PAGES.ADD_TRIP as never);
|
|
|
+ }
|
|
|
+ }, [navigation, selectedYear]);
|
|
|
|
|
|
const handleScrollToTrip = () => {
|
|
|
if (!flashListRef?.current) return;
|
|
|
@@ -139,17 +146,13 @@ const TripsScreen = ({ route }: { route: any }) => {
|
|
|
<Text
|
|
|
style={{ color: Colors.DARK_BLUE, fontFamily: 'redhat-700', fontSize: getFontSize(14) }}
|
|
|
>
|
|
|
- Trips 2025 BETA
|
|
|
+ Trips
|
|
|
</Text>
|
|
|
</View>
|
|
|
<View style={styles.tabContainer}>
|
|
|
- <TouchableOpacity
|
|
|
- style={styles.regionSelector}
|
|
|
- onPress={() => setDatePickerVisible(true)}
|
|
|
- disabled
|
|
|
- >
|
|
|
+ <TouchableOpacity style={styles.regionSelector} onPress={() => setDatePickerVisible(true)}>
|
|
|
<Text style={[styles.regionText]}>{selectedYear}</Text>
|
|
|
- {/* <ChevronIcon /> */}
|
|
|
+ <ChevronIcon />
|
|
|
</TouchableOpacity>
|
|
|
<TouchableOpacity style={styles.addNewTab} onPress={onAddNewTripPress}>
|
|
|
<AddIcon />
|
|
|
@@ -174,74 +177,78 @@ const TripsScreen = ({ route }: { route: any }) => {
|
|
|
contentContainerStyle={styles.tripsListContentContainer}
|
|
|
showsVerticalScrollIndicator={false}
|
|
|
ListHeaderComponent={
|
|
|
- <View
|
|
|
- style={{
|
|
|
- marginTop: 12,
|
|
|
- marginBottom: 8,
|
|
|
- backgroundColor: Colors.FILL_LIGHT,
|
|
|
- borderRadius: 8,
|
|
|
- paddingHorizontal: 16,
|
|
|
- paddingVertical: 12,
|
|
|
- gap: 6
|
|
|
- }}
|
|
|
- >
|
|
|
- <Text style={{ fontSize: 14, fontWeight: '600', color: Colors.DARK_BLUE }}>
|
|
|
- {statistics?.general}
|
|
|
- </Text>
|
|
|
-
|
|
|
- <TouchableOpacity
|
|
|
- onPress={() =>
|
|
|
- navigation.navigate(
|
|
|
- ...([
|
|
|
- NAVIGATION_PAGES.REGIONS_VISITED,
|
|
|
- {
|
|
|
- title: statistics?.countries?.description,
|
|
|
- isRegion: false,
|
|
|
- data: statistics?.countries?.list
|
|
|
- }
|
|
|
- ] as never)
|
|
|
- )
|
|
|
- }
|
|
|
- hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
|
|
|
+ Number(selectedYear) >= 2025 ? (
|
|
|
+ <View
|
|
|
+ style={{
|
|
|
+ marginTop: 12,
|
|
|
+ marginBottom: 8,
|
|
|
+ backgroundColor: Colors.FILL_LIGHT,
|
|
|
+ borderRadius: 8,
|
|
|
+ paddingHorizontal: 16,
|
|
|
+ paddingVertical: 12,
|
|
|
+ gap: 6
|
|
|
+ }}
|
|
|
>
|
|
|
- <Text style={{ fontSize: 14, fontWeight: '600', color: Colors.ORANGE }}>
|
|
|
- {statistics?.countries?.description}
|
|
|
- </Text>
|
|
|
- </TouchableOpacity>
|
|
|
+ {statistics?.general ? (
|
|
|
+ <Text style={{ fontSize: 14, fontWeight: '600', color: Colors.DARK_BLUE }}>
|
|
|
+ {statistics.general}
|
|
|
+ </Text>
|
|
|
+ ) : null}
|
|
|
|
|
|
- <TouchableOpacity
|
|
|
- onPress={() =>
|
|
|
- navigation.navigate(
|
|
|
- ...([
|
|
|
- NAVIGATION_PAGES.REGIONS_VISITED,
|
|
|
- {
|
|
|
- title: statistics?.regions?.description,
|
|
|
- isRegion: true,
|
|
|
- data: statistics?.regions?.list
|
|
|
- }
|
|
|
- ] as never)
|
|
|
- )
|
|
|
- }
|
|
|
- hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
|
|
|
- >
|
|
|
- <Text style={{ fontSize: 14, fontWeight: '600', color: Colors.ORANGE }}>
|
|
|
- {statistics?.regions?.description}
|
|
|
- </Text>
|
|
|
- </TouchableOpacity>
|
|
|
+ <TouchableOpacity
|
|
|
+ onPress={() =>
|
|
|
+ navigation.navigate(
|
|
|
+ ...([
|
|
|
+ NAVIGATION_PAGES.REGIONS_VISITED,
|
|
|
+ {
|
|
|
+ title: statistics?.countries?.description,
|
|
|
+ isRegion: false,
|
|
|
+ data: statistics?.countries?.list
|
|
|
+ }
|
|
|
+ ] as never)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
|
|
|
+ >
|
|
|
+ <Text style={{ fontSize: 14, fontWeight: '600', color: Colors.ORANGE }}>
|
|
|
+ {statistics?.countries?.description}
|
|
|
+ </Text>
|
|
|
+ </TouchableOpacity>
|
|
|
|
|
|
- {statistics?.dates_missing ? (
|
|
|
<TouchableOpacity
|
|
|
- onPress={handleScrollToTrip}
|
|
|
+ onPress={() =>
|
|
|
+ navigation.navigate(
|
|
|
+ ...([
|
|
|
+ NAVIGATION_PAGES.REGIONS_VISITED,
|
|
|
+ {
|
|
|
+ title: statistics?.regions?.description,
|
|
|
+ isRegion: true,
|
|
|
+ data: statistics?.regions?.list
|
|
|
+ }
|
|
|
+ ] as never)
|
|
|
+ )
|
|
|
+ }
|
|
|
hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
|
|
|
- style={{ marginTop: 8, flexDirection: 'row', gap: 8, alignItems: 'center' }}
|
|
|
>
|
|
|
- <WarningIcon color={Colors.RED} width={20} height={20} />
|
|
|
- <Text style={{ fontSize: 14, fontWeight: '600', color: Colors.RED }}>
|
|
|
- For accurate annual statistics, please enter exact dates for all trips.
|
|
|
+ <Text style={{ fontSize: 14, fontWeight: '600', color: Colors.ORANGE }}>
|
|
|
+ {statistics?.regions?.description}
|
|
|
</Text>
|
|
|
</TouchableOpacity>
|
|
|
- ) : null}
|
|
|
- </View>
|
|
|
+
|
|
|
+ {statistics?.dates_missing ? (
|
|
|
+ <TouchableOpacity
|
|
|
+ onPress={handleScrollToTrip}
|
|
|
+ hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
|
|
|
+ style={{ marginTop: 8, flexDirection: 'row', gap: 8, alignItems: 'center' }}
|
|
|
+ >
|
|
|
+ <WarningIcon color={Colors.RED} width={20} height={20} />
|
|
|
+ <Text style={{ fontSize: 14, fontWeight: '600', color: Colors.RED }}>
|
|
|
+ For accurate annual statistics, please enter exact dates for all trips.
|
|
|
+ </Text>
|
|
|
+ </TouchableOpacity>
|
|
|
+ ) : null}
|
|
|
+ </View>
|
|
|
+ ) : null
|
|
|
}
|
|
|
/>
|
|
|
)}
|