index.tsx 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import React, { useState } from 'react';
  2. import { View, Image, Linking, Text } from 'react-native';
  3. import { CommonActions, useNavigation } from '@react-navigation/native';
  4. import { WarningModal } from '../WarningModal';
  5. import { MenuButton } from '../MenuButton';
  6. import { styles } from './styles';
  7. import { StoreType, storage } from 'src/storage';
  8. import { useDeleteUserMutation } from '@api/app';
  9. import { Colors } from 'src/theme';
  10. import { NAVIGATION_PAGES } from 'src/types';
  11. import MailIcon from '../../../assets/icons/mail.svg';
  12. import DocumentIcon from '../../../assets/icons/document.svg';
  13. import ExitIcon from '../../../assets/icons/exit.svg';
  14. import UserXMark from '../../../assets/icons/user-xmark.svg';
  15. import InfoIcon from 'assets/icons/info-solid.svg';
  16. import BellIcon from 'assets/icons/notifications/bell-solid.svg';
  17. import SharingIcon from 'assets/icons/location-sharing.svg';
  18. import { APP_VERSION, FASTEST_MAP_HOST } from 'src/constants';
  19. import { useNotification } from 'src/contexts/NotificationContext';
  20. import { useMessagesStore } from 'src/stores/unreadMessagesStore';
  21. import { SafeAreaView } from 'react-native-safe-area-context';
  22. import { usePostIsFeatureActiveQuery } from '@api/location';
  23. export const MenuDrawer = (props: any) => {
  24. const { mutate: deleteUser } = useDeleteUserMutation();
  25. const token = storage.get('token', StoreType.STRING) as string;
  26. const { data: isFeatureActive } = usePostIsFeatureActiveQuery(token, !!token);
  27. const navigation = useNavigation();
  28. const [modalInfo, setModalInfo] = useState({
  29. visible: false,
  30. type: 'confirm',
  31. message: '',
  32. action: () => {}
  33. });
  34. const { updateNotificationStatus } = useNotification();
  35. const updateUnreadMessagesCount = useMessagesStore((state) => state.updateUnreadMessagesCount);
  36. const openModal = (type: string, message: string, action: any) => {
  37. setModalInfo({
  38. visible: true,
  39. type,
  40. message,
  41. action
  42. });
  43. };
  44. const closeModal = () => {
  45. setModalInfo({ ...modalInfo, visible: false });
  46. };
  47. const handleLogout = () => {
  48. storage.remove('token');
  49. storage.remove('uid');
  50. storage.remove('currentUserData');
  51. storage.remove('showNomads');
  52. storage.remove('filterSettings');
  53. updateNotificationStatus();
  54. updateUnreadMessagesCount();
  55. navigation.dispatch(
  56. CommonActions.reset({
  57. index: 1,
  58. routes: [{ name: NAVIGATION_PAGES.WELCOME }]
  59. })
  60. );
  61. };
  62. const handleDeleteAccount = () => {
  63. deleteUser({ token }, { onSuccess: handleLogout });
  64. };
  65. return (
  66. <>
  67. <SafeAreaView style={styles.container}>
  68. <View style={{ flex: 1 }}>
  69. <View style={styles.logoContainer}>
  70. <Image source={require('../../../assets/logo-ua.png')} style={styles.logo} />
  71. </View>
  72. <MenuButton
  73. label="Info"
  74. icon={<InfoIcon fill={Colors.DARK_BLUE} width={20} height={20} />}
  75. red={false}
  76. buttonFn={() => navigation.navigate(NAVIGATION_PAGES.INFO as never)}
  77. />
  78. <MenuButton
  79. label="Contact Us"
  80. icon={<MailIcon fill={Colors.DARK_BLUE} width={20} height={20} />}
  81. red={false}
  82. buttonFn={() => Linking.openURL('https://nomadmania.com/contact/')}
  83. />
  84. <MenuButton
  85. label="Terms & Conditions"
  86. icon={<DocumentIcon fill={Colors.DARK_BLUE} width={20} height={20} />}
  87. red={false}
  88. buttonFn={() => Linking.openURL('https://nomadmania.com/terms/')}
  89. />
  90. {token && (
  91. <MenuButton
  92. label="Notifications"
  93. icon={<BellIcon fill={Colors.DARK_BLUE} width={20} height={20} />}
  94. red={false}
  95. buttonFn={() =>
  96. // todo: add types
  97. // @ts-ignore
  98. navigation.navigate(NAVIGATION_PAGES.MENU_DRAWER, {
  99. screen: NAVIGATION_PAGES.NOTIFICATIONS
  100. })
  101. }
  102. />
  103. )}
  104. {isFeatureActive && isFeatureActive.active && (
  105. <MenuButton
  106. label="Location sharing"
  107. icon={<SharingIcon fill={Colors.DARK_BLUE} width={20} height={20} />}
  108. red={false}
  109. buttonFn={() =>
  110. // @ts-ignore
  111. navigation.navigate(NAVIGATION_PAGES.MENU_DRAWER, {
  112. screen: NAVIGATION_PAGES.LOCATION_SHARING
  113. })
  114. }
  115. />
  116. )}
  117. </View>
  118. <View style={styles.bottomMenu}>
  119. {token ? (
  120. <>
  121. <MenuButton
  122. label="Logout"
  123. icon={<ExitIcon fill={Colors.RED} width={20} height={20} />}
  124. red={true}
  125. buttonFn={() =>
  126. openModal('confirm', 'Are you sure you want to logout?', handleLogout)
  127. }
  128. />
  129. <MenuButton
  130. label="Delete account"
  131. icon={<UserXMark fill={Colors.RED} width={20} height={20} />}
  132. red={true}
  133. buttonFn={() =>
  134. openModal(
  135. 'confirm',
  136. 'Are you sure you want to delete your account?',
  137. handleDeleteAccount
  138. )
  139. }
  140. />
  141. </>
  142. ) : null}
  143. <View style={{ gap: 6, marginTop: 16 }}>
  144. <Text style={styles.bottomText}>Version {APP_VERSION}</Text>
  145. <Text style={styles.bottomText}>
  146. Map server:{'\n'}
  147. {FASTEST_MAP_HOST}
  148. </Text>
  149. </View>
  150. </View>
  151. </SafeAreaView>
  152. <WarningModal
  153. isVisible={modalInfo.visible}
  154. onClose={closeModal}
  155. type={modalInfo.type}
  156. message={modalInfo.message}
  157. action={() => {
  158. modalInfo.action();
  159. closeModal();
  160. }}
  161. />
  162. </>
  163. );
  164. };