123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- import React from 'react';
- import { Text, View, TouchableOpacity } from 'react-native';
- import Modal from 'react-native-modal';
- import { styles } from './styles';
- import CloseIcon from '../../../assets/icons/close.svg';
- import { Colors } from 'src/theme';
- import { useNavigation } from '@react-navigation/native';
- import { NAVIGATION_PAGES } from 'src/types';
- import { ButtonVariants } from 'src/types/components';
- import { Button } from '../Button';
- export const WarningModal = ({
- isVisible,
- onClose,
- type,
- message,
- title,
- action,
- onModalHide
- }: {
- isVisible: boolean;
- onClose: () => void;
- type: string;
- message?: string;
- title?: string;
- action?: () => void;
- onModalHide?: () => void;
- }) => {
- const navigation = useNavigation();
- const content = {
- offline: {
- message: 'Please check your Internet connection and try again.',
- buttons: [
- {
- text: 'OK',
- textColor: Colors.WHITE,
- color: Colors.DARK_BLUE,
- action: onClose,
- borderColor: Colors.DARK_BLUE
- }
- ]
- },
- unauthorized: {
- message: 'To use this feature you need to have an account with NomadMania.',
- buttons: [
- {
- text: 'Login',
- textColor: Colors.DARK_BLUE,
- color: Colors.WHITE,
- action: () => {
- action && action();
- onClose();
- navigation.navigate(NAVIGATION_PAGES.LOGIN as never);
- },
- borderColor: Colors.DARK_BLUE
- },
- {
- text: 'Register',
- textColor: Colors.WHITE,
- color: Colors.DARK_BLUE,
- action: () => {
- action && action();
- onClose();
- navigation.navigate(NAVIGATION_PAGES.REGISTER as never);
- },
- borderColor: Colors.DARK_BLUE
- }
- ]
- },
- delete: {
- message,
- buttons: [
- {
- text: 'No',
- textColor: Colors.DARK_BLUE,
- color: Colors.WHITE,
- action: () => {
- onClose();
- },
- borderColor: Colors.DARK_BLUE
- },
- {
- text: 'Delete',
- textColor: Colors.WHITE,
- color: Colors.RED,
- action: () => {
- onClose();
- action && action();
- },
- borderColor: Colors.RED
- }
- ]
- },
- success: {
- message,
- buttons: [
- {
- text: 'OK',
- textColor: Colors.WHITE,
- color: Colors.ORANGE,
- action: () => {
- onClose;
- action && action();
- },
- borderColor: Colors.ORANGE
- }
- ]
- },
- confirm: {
- message,
- buttons: [
- {
- text: 'No',
- textColor: Colors.DARK_BLUE,
- color: Colors.WHITE,
- action: () => {
- onClose();
- },
- borderColor: Colors.DARK_BLUE
- },
- {
- text: 'Yes',
- textColor: Colors.WHITE,
- color: Colors.DARK_BLUE,
- action: () => {
- onClose();
- action && action();
- },
- borderColor: Colors.DARK_BLUE
- }
- ]
- }
- };
- const modalContent = content[type as keyof typeof content] || {};
- return (
- <Modal isVisible={isVisible} onModalHide={onModalHide}>
- <View style={styles.centeredView}>
- <View style={styles.modalView}>
- <View style={{ alignSelf: 'flex-end' }}>
- <TouchableOpacity onPress={onClose}>
- <CloseIcon fill={Colors.LIGHT_GRAY} />
- </TouchableOpacity>
- </View>
- <View style={styles.modalContent}>
- <Text style={styles.modalTitle}>{title ?? 'Oops!'}</Text>
- <Text style={styles.modalText}>{modalContent.message}</Text>
- <View style={styles.buttonContainer}>
- {modalContent.buttons.map(
- (
- button: {
- text: string;
- textColor: string;
- color: string;
- action: () => void;
- borderColor: string;
- },
- idx: number
- ) => (
- <Button
- key={idx}
- variant={ButtonVariants.OPACITY}
- containerStyles={{
- borderColor: button.borderColor,
- backgroundColor: button.color,
- width: type === 'offline' ? '60%' : '45%'
- }}
- textStyles={{
- color: button.textColor
- }}
- onPress={button.action}
- children={button.text}
- />
- )
- )}
- </View>
- </View>
- </View>
- </View>
- </Modal>
- );
- };
|