-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSeniorSignup.tsx
187 lines (171 loc) · 4.54 KB
/
SeniorSignup.tsx
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import React, {useState} from 'react';
import {useQuery, gql, useMutation} from '@apollo/client';
import {
StyleSheet,
Text,
View,
TouchableOpacity,
TouchableWithoutFeedback,
Keyboard,
} from 'react-native';
import {TextInput} from 'react-native-gesture-handler';
interface signUpState {
firstName: string;
lastName: string;
email: string;
phoneNumber: string;
zipCode: string;
password: string;
}
const ADD_SENIOR = gql`
mutation addSenior(
$name: String!
$phone: String!
$password: String!
$zipCode: Int!
$email: String
) {
addSenior(
name: $name
phone: $phone
password: $password
zipcode: $zipCode
email: $email
) {
id
}
}
`;
const SeniorSignup: React.FC = ({navigation}) => {
// inital state for the forms
const [addSenior, {data, error}] = useMutation(ADD_SENIOR);
const initialState: signUpState = {
firstName: '',
lastName: '',
email: '',
phoneNumber: '',
zipCode: '',
password: '',
};
// if (loading) return 'Loading...';
// if (error) return `Error! ${error.message}`;
// state for the forms
const [form, setForm] = useState<signUpState>(initialState);
// console.log('state change', form);
// handle submit when submit button is clicked
const handleSubmit = async () => {
console.log('form', form)
const {firstName, lastName, phoneNumber, password, zipCode, email} = form;
const numberedZip = Number(zipCode);
const name = `${firstName} ${lastName}`
// TODO : need some sort of validation for the forms before we send to DB
try {
const {data} = await addSenior({
variables: {
name,
phone: phoneNumber,
email,
password,
zipCode: numberedZip,
},
});
setForm(initialState);
navigation.navigate('SeniorDash');
} catch (error) {
console.log('error', error);
}
};
return (
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<View style={styles.container}>
<Text style={styles.Text}>Sign Up</Text>
<Text style={styles.labels}>First Name</Text>
<TextInput
style={styles.inputFields}
placeholder="First Name"
onChangeText={text => setForm({...form, firstName: text})}
value={form.firstName}
/>
<Text style={styles.labels}>Last Name</Text>
<TextInput
style={styles.inputFields}
placeholder="Last Name"
onChangeText={text => setForm({...form, lastName: text})}
value={form.lastName}
/>
<Text style={styles.labels}>Email</Text>
<TextInput
style={styles.inputFields}
placeholder="Email"
onChangeText={text => setForm({...form, email: text})}
value={form.email}
/>
<Text style={styles.labels}>Phone Number</Text>
<TextInput
style={styles.inputFields}
keyboardType={'phone-pad'}
placeholder="1234567890"
onChangeText={text => setForm({...form, phoneNumber: text})}
value={form.phoneNumber}
/>
<Text style={styles.labels}>Zip Code</Text>
<TextInput
style={styles.inputFields}
placeholder="Zip Code"
keyboardType={'numeric'}
onChangeText={text => setForm({...form, zipCode: text})}
value={form.zipCode}
/>
<Text style={styles.labels}>Password</Text>
<TextInput
style={styles.inputFields}
secureTextEntry={true}
placeholder="Password"
onChangeText={text => setForm({...form, password: text})}
value={form.password}
/>
<TouchableOpacity
style={styles.button}
onPress={handleSubmit}>
<Text style={styles.buttonText}>Submit</Text>
</TouchableOpacity>
</View>
</TouchableWithoutFeedback>
);
};
export default SeniorSignup;
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'flex-start',
},
inputFields: {
width: '70%',
borderColor: 'lightblue',
borderStyle: 'solid',
borderWidth: 1,
fontSize: 25,
marginBottom: 10,
},
labels: {
fontSize: 25,
marginBottom: 5,
},
button: {
backgroundColor: 'lightblue',
borderColor: 'lightblue',
borderStyle: 'solid',
borderWidth: 1,
padding: 10,
marginTop: 10,
},
buttonText: {
fontSize: 20,
},
Text: {
fontSize: 40,
marginVertical: 20,
},
});