index.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import React, { useState } from 'react';
  2. import { View, Text, FlatList, TouchableOpacity, StyleSheet, Dimensions } from 'react-native';
  3. import { useNavigation } from '@react-navigation/native';
  4. import { Colors } from '../../../theme';
  5. import { WarningModal } from '../../../components';
  6. import { NAVIGATION_PAGES } from 'src/types';
  7. import { storage, StoreType } from '../../../storage';
  8. import FlagsIcon from '../../../../assets/icons/travels-section/flags.svg';
  9. import RegionsIcon from '../../../../assets/icons/travels-section/regions.svg';
  10. import CompassIcon from '../../../../assets/icons/travels-section/compass.svg';
  11. import SeriesIcon from '../../../../assets/icons/travels-section/series.svg';
  12. import EarthIcon from '../../../../assets/icons/travels-section/earth.svg';
  13. import TripIcon from '../../../../assets/icons/travels-section/trip.svg';
  14. import ImagesIcon from '../../../../assets/icons/travels-section/images.svg';
  15. import FixersIcon from '../../../../assets/icons/travels-section/fixers.svg';
  16. import CalendarIcon from 'assets/icons/events/calendar-solid.svg';
  17. import InfoIcon from 'assets/icons/info-solid.svg';
  18. import { getFontSize } from 'src/utils';
  19. import { useSafeAreaInsets } from 'react-native-safe-area-context';
  20. const TravelsScreen = () => {
  21. const [isModalVisible, setIsModalVisible] = useState(false);
  22. const insets = useSafeAreaInsets();
  23. const token = storage.get('token', StoreType.STRING);
  24. const navigation = useNavigation();
  25. const buttons = [
  26. { label: 'Countries', icon: FlagsIcon, page: NAVIGATION_PAGES.COUNTRIES },
  27. { label: 'Regions', icon: RegionsIcon, page: NAVIGATION_PAGES.REGIONS },
  28. { label: 'DARE', icon: CompassIcon, page: NAVIGATION_PAGES.DARE },
  29. { label: 'Series', icon: SeriesIcon, page: NAVIGATION_PAGES.SERIES },
  30. { label: 'Earth', icon: EarthIcon, page: NAVIGATION_PAGES.EARTH },
  31. { label: 'Trips', icon: TripIcon, page: NAVIGATION_PAGES.TRIPS },
  32. { label: 'Photos', icon: ImagesIcon, page: NAVIGATION_PAGES.PHOTOS },
  33. { label: 'Fixers', icon: FixersIcon, page: NAVIGATION_PAGES.FIXERS },
  34. { label: 'Events', icon: CalendarIcon, page: NAVIGATION_PAGES.EVENTS }
  35. ];
  36. const handlePress = (page: string) => {
  37. if (
  38. !token &&
  39. (page === NAVIGATION_PAGES.TRIPS ||
  40. page === NAVIGATION_PAGES.PHOTOS ||
  41. page === NAVIGATION_PAGES.FIXERS)
  42. ) {
  43. setIsModalVisible(true);
  44. } else {
  45. navigation.navigate(page as never);
  46. }
  47. };
  48. const renderItem = ({ item }: { item: { label: string; icon: any; page: string } }) => (
  49. <TouchableOpacity style={{ alignItems: 'center' }} onPress={() => handlePress(item.page)}>
  50. <View style={styles.button}>
  51. <item.icon
  52. fill={Colors.ORANGE}
  53. width={Dimensions.get('window').width < 380 ? 105 : 110}
  54. height={32}
  55. />
  56. <Text style={styles.label}>{item.label}</Text>
  57. </View>
  58. </TouchableOpacity>
  59. );
  60. return (
  61. <View style={{ paddingTop: insets.top, marginLeft: '5%', marginRight: '5%', height: '100%' }}>
  62. <View style={styles.header}>
  63. <View style={{ width: 30 }} />
  64. <Text style={styles.title}>Travels</Text>
  65. <TouchableOpacity
  66. onPress={() => navigation.navigate(NAVIGATION_PAGES.PLAN_INFO as never)}
  67. style={{ width: 30 }}
  68. >
  69. <InfoIcon />
  70. </TouchableOpacity>
  71. </View>
  72. <FlatList
  73. data={buttons}
  74. renderItem={renderItem}
  75. keyExtractor={(item, index) => 'key' + index}
  76. numColumns={2}
  77. contentContainerStyle={styles.container}
  78. style={{ flex: 1 }}
  79. columnWrapperStyle={{ justifyContent: 'space-between' }}
  80. />
  81. <WarningModal
  82. type="unauthorized"
  83. isVisible={isModalVisible}
  84. onClose={() => setIsModalVisible(false)}
  85. />
  86. </View>
  87. );
  88. };
  89. const styles = StyleSheet.create({
  90. container: {
  91. justifyContent: 'space-between',
  92. paddingHorizontal: Dimensions.get('window').width < 380 ? '5%' : 24,
  93. paddingVertical: 8,
  94. gap: 32,
  95. width: '100%'
  96. },
  97. button: {
  98. alignItems: 'center',
  99. justifyContent: 'center',
  100. paddingVertical: 16,
  101. paddingHorizontal: 8,
  102. backgroundColor: Colors.FILL_LIGHT,
  103. borderRadius: 16,
  104. gap: 12
  105. },
  106. label: {
  107. color: Colors.DARK_BLUE,
  108. fontSize: 13,
  109. fontWeight: 'bold'
  110. },
  111. title: { color: Colors.DARK_BLUE, fontFamily: 'redhat-700', fontSize: getFontSize(14) },
  112. header: {
  113. alignItems: 'center',
  114. paddingVertical: 16,
  115. flexDirection: 'row',
  116. justifyContent: 'space-between'
  117. }
  118. });
  119. export default TravelsScreen;