index.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import React from 'react';
  2. import { Text, View, TouchableOpacity } from 'react-native';
  3. import Modal from 'react-native-modal';
  4. import { styles } from './styles';
  5. import CloseIcon from '../../../assets/icons/close.svg';
  6. import { Colors } from 'src/theme';
  7. import { useNavigation } from '@react-navigation/native';
  8. import { NAVIGATION_PAGES } from 'src/types';
  9. import { ButtonVariants } from 'src/types/components';
  10. import { Button } from '../Button';
  11. export const WarningModal = ({
  12. isVisible,
  13. onClose,
  14. type,
  15. message,
  16. title,
  17. action
  18. }: {
  19. isVisible: boolean;
  20. onClose: () => void;
  21. type: string;
  22. message?: string;
  23. title?: string;
  24. action?: () => void;
  25. }) => {
  26. const navigation = useNavigation();
  27. const content = {
  28. offline: {
  29. message: 'Please check your Internet connection and try again.',
  30. buttons: [
  31. {
  32. text: 'OK',
  33. textColor: Colors.WHITE,
  34. color: Colors.DARK_BLUE,
  35. action: onClose,
  36. borderColor: Colors.DARK_BLUE
  37. }
  38. ]
  39. },
  40. unauthorized: {
  41. message: 'To use this feature you need to have an account with NomadMania.',
  42. buttons: [
  43. {
  44. text: 'Login',
  45. textColor: Colors.DARK_BLUE,
  46. color: Colors.WHITE,
  47. action: () => {
  48. onClose();
  49. navigation.navigate(NAVIGATION_PAGES.LOGIN as never);
  50. },
  51. borderColor: Colors.DARK_BLUE
  52. },
  53. {
  54. text: 'Register',
  55. textColor: Colors.WHITE,
  56. color: Colors.DARK_BLUE,
  57. action: () => {
  58. onClose();
  59. navigation.navigate(NAVIGATION_PAGES.REGISTER as never);
  60. },
  61. borderColor: Colors.DARK_BLUE
  62. }
  63. ]
  64. },
  65. delete: {
  66. message,
  67. buttons: [
  68. {
  69. text: 'No',
  70. textColor: Colors.DARK_BLUE,
  71. color: Colors.WHITE,
  72. action: () => {
  73. onClose();
  74. },
  75. borderColor: Colors.DARK_BLUE
  76. },
  77. {
  78. text: 'Delete',
  79. textColor: Colors.WHITE,
  80. color: Colors.RED,
  81. action: () => {
  82. onClose();
  83. action && action();
  84. },
  85. borderColor: Colors.RED
  86. }
  87. ]
  88. },
  89. success: {
  90. message,
  91. buttons: [
  92. {
  93. text: 'OK',
  94. textColor: Colors.WHITE,
  95. color: Colors.ORANGE,
  96. action: onClose,
  97. borderColor: Colors.ORANGE
  98. },
  99. ]
  100. }
  101. };
  102. const modalContent = content[type as keyof typeof content] || {};
  103. return (
  104. <Modal isVisible={isVisible}>
  105. <View style={styles.centeredView}>
  106. <View style={styles.modalView}>
  107. <View style={{ alignSelf: 'flex-end' }}>
  108. <TouchableOpacity onPress={onClose}>
  109. <CloseIcon fill={Colors.LIGHT_GRAY} />
  110. </TouchableOpacity>
  111. </View>
  112. <View style={styles.modalContent}>
  113. <Text style={styles.modalTitle}>{title ?? 'Oops!'}</Text>
  114. <Text style={styles.modalText}>{modalContent.message}</Text>
  115. <View style={styles.buttonContainer}>
  116. {modalContent.buttons.map(
  117. (
  118. button: {
  119. text: string;
  120. textColor: string;
  121. color: string;
  122. action: () => void;
  123. borderColor: string;
  124. },
  125. idx: number
  126. ) => (
  127. <Button
  128. key={idx}
  129. variant={ButtonVariants.OPACITY}
  130. containerStyles={{
  131. borderColor: button.borderColor,
  132. backgroundColor: button.color,
  133. width: type === 'offline' ? '60%' : '45%'
  134. }}
  135. textStyles={{
  136. color: button.textColor
  137. }}
  138. onPress={button.action}
  139. children={button.text}
  140. />
  141. )
  142. )}
  143. </View>
  144. </View>
  145. </View>
  146. </View>
  147. </Modal>
  148. );
  149. };