1
|
|
|
import React from 'react'; |
2
|
|
|
import { StyleSheet, Text, View, Pressable, Modal, TextInput} from 'react-native'; |
3
|
|
|
import userModel from '../../models/user'; |
4
|
|
|
import { showMessage, hideMessage } from "react-native-flash-message"; |
5
|
|
|
|
6
|
|
|
export default function DeleteModal({navigation, modalVisible, setModalVisible, setIsLoggedIn}) { |
7
|
|
|
|
8
|
|
|
async function deleteAccount(navigation) { |
9
|
|
|
const result = await userModel.deleteAccount(); |
10
|
|
|
|
11
|
|
|
if (Object.prototype.hasOwnProperty.call(result, 'errors')) { |
12
|
|
|
showMessage({ |
13
|
|
|
message: result['errors']['title'], |
14
|
|
|
type: 'danger', |
15
|
|
|
position: 'bottom' |
16
|
|
|
}) |
17
|
|
|
|
18
|
|
|
return; |
19
|
|
|
}; |
20
|
|
|
|
21
|
|
|
showMessage({ |
22
|
|
|
message: result['message'], |
23
|
|
|
type: 'danger', |
24
|
|
|
position: 'bottom' |
25
|
|
|
}); |
26
|
|
|
|
27
|
|
|
setIsLoggedIn(false); |
28
|
|
|
navigation.navigate('Auth'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
return ( |
32
|
|
|
<Modal |
33
|
|
|
animationType='fade' |
34
|
|
|
transparent={true} |
35
|
|
|
visible={modalVisible} |
36
|
|
|
onRequestClose={() => { |
37
|
|
|
setModalVisible(!modalVisible); |
38
|
|
|
}} |
39
|
|
|
> |
40
|
|
|
<View style={styles.modalContainer}> |
41
|
|
|
|
42
|
|
|
<View style={[styles.messageContainer, styles.shadowProp]}> |
43
|
|
|
<Text style={styles.title}>Are you sure you want to delete your account?</Text> |
44
|
|
|
|
45
|
|
|
<Pressable style={[styles.prepaidButton]} onPress={() => { |
46
|
|
|
deleteAccount(navigation) |
47
|
|
|
}}> |
48
|
|
|
<Text style={{color: 'white'}}>Yes, delete account</Text> |
49
|
|
|
</Pressable> |
50
|
|
|
|
51
|
|
|
<Pressable style={[styles.prepaidButton, {backgroundColor: 'grey'}]} onPress={() => { |
52
|
|
|
setModalVisible(!modalVisible); |
53
|
|
|
}}> |
54
|
|
|
<Text style={{color: 'white'}}>No</Text> |
55
|
|
|
</Pressable> |
56
|
|
|
</View> |
57
|
|
|
</View> |
58
|
|
|
</Modal> |
59
|
|
|
) |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
const styles = StyleSheet.create({ |
63
|
|
|
modalContainer: { |
64
|
|
|
height: '100%', |
65
|
|
|
width: '100%', |
66
|
|
|
backgroundColor: 'rgba(0, 0, 0, 0.8)', |
67
|
|
|
position:'absolute', |
68
|
|
|
alignItems: 'center' |
69
|
|
|
}, |
70
|
|
|
|
71
|
|
|
messageContainer: { |
72
|
|
|
backgroundColor: 'tomato', |
73
|
|
|
width: '90%', |
74
|
|
|
height: 250, |
75
|
|
|
marginTop: 200, |
76
|
|
|
justifyContent: 'center', |
77
|
|
|
alignItems: 'center' |
78
|
|
|
}, |
79
|
|
|
|
80
|
|
|
shadowProp: { |
81
|
|
|
elevation: 5, |
82
|
|
|
shadowColor: 'black' |
83
|
|
|
}, |
84
|
|
|
|
85
|
|
|
title: { |
86
|
|
|
fontSize: 18, |
87
|
|
|
fontWeight: '600', |
88
|
|
|
color: 'white' |
89
|
|
|
}, |
90
|
|
|
|
91
|
|
|
prepaidButton: { |
92
|
|
|
backgroundColor: 'black', |
93
|
|
|
width: '90%', |
94
|
|
|
height: 50, |
95
|
|
|
borderRadius: 50, |
96
|
|
|
display: 'flex', |
97
|
|
|
justifyContent: 'center', |
98
|
|
|
alignItems: 'center', |
99
|
|
|
marginTop: 30, |
100
|
|
|
}, |
101
|
|
|
}) |