index.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import React from 'react';
  2. import { View, Text, TouchableOpacity, Linking } from 'react-native';
  3. import Modal from 'react-native-modal';
  4. import { useError } from 'src/contexts/ErrorContext';
  5. import { styles } from '../WarningModal/styles';
  6. import { Colors } from 'src/theme';
  7. import CloseIcon from 'assets/icons/close.svg';
  8. import { ButtonVariants } from 'src/types/components';
  9. import { Button } from '../Button';
  10. import { CommonActions, useNavigation } from '@react-navigation/native';
  11. import { NAVIGATION_PAGES } from 'src/types';
  12. import { storage } from 'src/storage';
  13. import { useMessagesStore } from 'src/stores/unreadMessagesStore';
  14. import { useFriendsNotificationsStore } from 'src/stores/friendsNotificationsStore';
  15. export const ErrorModal = () => {
  16. const { error, hideError, navigateToLogin, navigateToAuth, premiumError, resetErrorState } =
  17. useError();
  18. const navigation = useNavigation();
  19. const updateNotificationStatus = useFriendsNotificationsStore(
  20. (state) => state.updateNotificationStatus
  21. );
  22. const updateUnreadMessagesCount = useMessagesStore((state) => state.updateUnreadMessagesCount);
  23. const handleClose = () => {
  24. if (navigateToLogin) {
  25. storage.remove('token');
  26. storage.remove('uid');
  27. storage.remove('currentUserData');
  28. storage.remove('showNomads');
  29. storage.remove('filterSettings');
  30. updateNotificationStatus();
  31. updateUnreadMessagesCount();
  32. navigation.dispatch(
  33. CommonActions.reset({
  34. index: 1,
  35. routes: [{ name: NAVIGATION_PAGES.WELCOME }]
  36. })
  37. );
  38. }
  39. hideError();
  40. };
  41. const handleGoToWeb = () => {
  42. Linking.openURL('https://nomadmania.com/blog-authentication/').catch((err) =>
  43. console.error('Failed to open auth URL:', err)
  44. );
  45. hideError();
  46. };
  47. return (
  48. <Modal isVisible={!!error} onModalHide={resetErrorState}>
  49. <View style={styles.centeredView}>
  50. <View style={styles.modalView}>
  51. <View style={{ alignSelf: 'flex-end' }}>
  52. <TouchableOpacity onPress={handleClose}>
  53. <CloseIcon fill={Colors.LIGHT_GRAY} />
  54. </TouchableOpacity>
  55. </View>
  56. <View style={styles.modalContent}>
  57. <Text style={styles.modalTitle}>Oops!</Text>
  58. <Text style={styles.modalText}>
  59. {premiumError
  60. ? 'This feature is available to Premium users. Premium account settings can be managed on our website.'
  61. : `An error occurred: ${error}`}
  62. </Text>
  63. <View style={styles.buttonContainer}>
  64. <Button
  65. variant={ButtonVariants.OPACITY}
  66. containerStyles={{
  67. borderColor: Colors.DARK_BLUE,
  68. backgroundColor: Colors.DARK_BLUE,
  69. width: '60%'
  70. }}
  71. textStyles={{
  72. color: Colors.WHITE
  73. }}
  74. onPress={navigateToAuth ? handleGoToWeb : handleClose}
  75. children="OK"
  76. />
  77. </View>
  78. </View>
  79. </View>
  80. </View>
  81. </Modal>
  82. );
  83. };