index.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 { APP_VERSION, FASTEST_MAP_HOST } from 'src/constants';
  17. import { useNotification } from 'src/contexts/NotificationContext';
  18. export const MenuDrawer = (props: any) => {
  19. const { mutate: deleteUser } = useDeleteUserMutation();
  20. const token = storage.get('token', StoreType.STRING) as string;
  21. const navigation = useNavigation();
  22. const [modalInfo, setModalInfo] = useState({
  23. visible: false,
  24. type: 'confirm',
  25. message: '',
  26. action: () => {}
  27. });
  28. const { updateNotificationStatus } = useNotification();
  29. const openModal = (type: string, message: string, action: any) => {
  30. setModalInfo({
  31. visible: true,
  32. type,
  33. message,
  34. action
  35. });
  36. };
  37. const closeModal = () => {
  38. setModalInfo({ ...modalInfo, visible: false });
  39. };
  40. const handleLogout = () => {
  41. storage.remove('token');
  42. storage.remove('uid');
  43. storage.remove('currentUserData');
  44. storage.remove('visitedTilesUrl');
  45. storage.remove('filterSettings');
  46. updateNotificationStatus();
  47. navigation.dispatch(
  48. CommonActions.reset({
  49. index: 1,
  50. routes: [{ name: NAVIGATION_PAGES.WELCOME }]
  51. })
  52. );
  53. };
  54. const handleDeleteAccount = () => {
  55. deleteUser({ token }, { onSuccess: handleLogout });
  56. };
  57. return (
  58. <>
  59. <View style={styles.container}>
  60. <View style={{ flex: 1 }}>
  61. <View style={styles.logoContainer}>
  62. <Image source={require('../../../assets/logo-ua.png')} style={styles.logo} />
  63. </View>
  64. <MenuButton
  65. label="Info"
  66. icon={<InfoIcon fill={Colors.DARK_BLUE} width={20} height={20} />}
  67. red={false}
  68. buttonFn={() => navigation.navigate(NAVIGATION_PAGES.INFO as never)}
  69. />
  70. <MenuButton
  71. label="Contact Us"
  72. icon={<MailIcon fill={Colors.DARK_BLUE} width={20} height={20} />}
  73. red={false}
  74. buttonFn={() => Linking.openURL('https://nomadmania.com/contact/')}
  75. />
  76. <MenuButton
  77. label="Terms & Conditions"
  78. icon={<DocumentIcon fill={Colors.DARK_BLUE} width={20} height={20} />}
  79. red={false}
  80. buttonFn={() => Linking.openURL('https://nomadmania.com/terms/')}
  81. />
  82. </View>
  83. <View style={styles.bottomMenu}>
  84. {token ? (
  85. <>
  86. <MenuButton
  87. label="Logout"
  88. icon={<ExitIcon fill={Colors.RED} width={20} height={20} />}
  89. red={true}
  90. buttonFn={() =>
  91. openModal('confirm', 'Are you sure you want to logout?', handleLogout)
  92. }
  93. />
  94. <MenuButton
  95. label="Delete account"
  96. icon={<UserXMark fill={Colors.RED} width={20} height={20} />}
  97. red={true}
  98. buttonFn={() =>
  99. openModal(
  100. 'confirm',
  101. 'Are you sure you want to delete your account?',
  102. handleDeleteAccount
  103. )
  104. }
  105. />
  106. </>
  107. ) : null}
  108. <View style={{ gap: 6, marginTop: 16 }}>
  109. <Text style={styles.bottomText}>Version {APP_VERSION}</Text>
  110. <Text style={styles.bottomText}>
  111. Map server:{'\n'}
  112. {FASTEST_MAP_HOST}
  113. </Text>
  114. </View>
  115. </View>
  116. </View>
  117. <WarningModal
  118. isVisible={modalInfo.visible}
  119. onClose={closeModal}
  120. type={modalInfo.type}
  121. message={modalInfo.message}
  122. action={() => {
  123. modalInfo.action();
  124. closeModal();
  125. }}
  126. />
  127. </>
  128. );
  129. };