-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPinEntryScreen.js
More file actions
140 lines (128 loc) · 4.12 KB
/
PinEntryScreen.js
File metadata and controls
140 lines (128 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import React, { useState, useEffect } from 'react';
import { View, Text, TouchableOpacity, StyleSheet, Alert } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
const PinEntryScreen = ({ navigation }) => {
const [enteredPin, setEnteredPin] = useState('');
const [savedPin, setSavedPin] = useState(null);
// Fetch the saved PIN when the component mounts
useEffect(() => {
const fetchSavedPin = async () => {
const pin = await AsyncStorage.getItem('userPin');
setSavedPin(pin);
};
fetchSavedPin();
}, []);
const handlePinPress = (value) => {
if (enteredPin.length < 4) {
setEnteredPin(enteredPin + value);
}
};
const handleDelete = () => {
setEnteredPin(enteredPin.slice(0, -1));
};
const handleSubmit = async () => {
if (enteredPin === savedPin) {
// Check if the user is signed in by looking for a token
const token = await AsyncStorage.getItem('token');
if (token) {
// If signed in, navigate to the correct landing page
const userRole = await AsyncStorage.getItem('userRole');
if (userRole === 'Admin') {
navigation.navigate('Landing');
} else if (userRole === 'Donor') {
navigation.navigate('Landing');
}
} else {
// If not signed in, take the user to the SignIn screen
navigation.navigate('SignIn');
}
} else {
Alert.alert('Incorrect PIN', 'The PIN you entered is incorrect. Please try again.');
setEnteredPin('');
}
};
return (
<View style={styles.container}>
<Text style={styles.title}>Enter Your PIN</Text>
<View style={styles.pinContainer}>
{[0, 1, 2, 3].map((index) => (
<Text key={index} style={styles.pinDigit}>
{enteredPin[index] ? '●' : '○'}
</Text>
))}
</View>
<View style={styles.numPad}>
{[1, 2, 3, 4, 5, 6, 7, 8, 9, 0].map((num) => (
<TouchableOpacity key={num} style={styles.numButton} onPress={() => handlePinPress(num.toString())}>
<Text style={styles.numText}>{num}</Text>
</TouchableOpacity>
))}
</View>
<View style={styles.actions}>
<TouchableOpacity style={styles.actionButton} onPress={handleDelete}>
<Text style={styles.actionText}>Delete</Text>
</TouchableOpacity>
{enteredPin.length === 4 && (
<TouchableOpacity style={styles.actionButton} onPress={handleSubmit}>
<Text style={styles.actionText}>Submit</Text>
</TouchableOpacity>
)}
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff',
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 20,
},
pinContainer: {
flexDirection: 'row',
justifyContent: 'space-between',
width: '60%',
marginBottom: 30,
},
pinDigit: {
fontSize: 36,
fontWeight: 'bold',
color: '#000',
},
numPad: {
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'center',
width: '60%',
},
numButton: {
width: 80,
height: 80,
justifyContent: 'center',
alignItems: 'center',
margin: 10,
borderWidth: 1,
borderColor: '#000',
borderRadius: 40,
},
numText: {
fontSize: 24,
fontWeight: 'bold',
},
actions: {
marginTop: 30,
},
actionButton: {
marginTop: 10,
},
actionText: {
fontSize: 18,
color: '#000',
},
});
export default PinEntryScreen;