-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathJuniorSignup.tsx
168 lines (156 loc) · 4.18 KB
/
JuniorSignup.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
import React, {useState} from 'react';
import {
StyleSheet,
Text,
View,
TouchableWithoutFeedback,
TextInput,
Keyboard,
TouchableOpacity,
} from 'react-native';
import {gql, useMutation} from '@apollo/client';
interface signupState {
name: string;
email: string;
phoneNumber: string;
password: string;
zipCode: any;
}
// TODO: change occupation to zip code when Andy modifies DB
const ADD_HELPER = gql`
mutation addHelper(
$name: String!
$email: String!
$phone: String!
$password: String!
$zipCode: Int
) {
addHelper(
name: $name
email: $email
phone: $phone
password: $password
zipcode: $zipCode
) {
id
}
}
`;
const JuniorSignup = ({navigation, authID, setAuthID}) => {
// const {setAuthID} = useContext(AuthContext);
const initialState: signupState = {
name: '',
email: '',
phoneNumber: '',
password: '',
zipCode: '',
};
// console.log('authID in signup', authID);
// state for the forms
const [form, setForm] = useState<signupState>(initialState);
// mutation hook to send form data to backend
const [addHelper, {data, error}] = useMutation(ADD_HELPER);
const handleSubmit = async () => {
const {name, email, phoneNumber, password, zipCode} = form;
const numberedZip = Number(zipCode);
// TODO : need some sort of validation for the forms before we send to DB
try {
const {data} = await addHelper({
variables: {
name,
email,
phone: phoneNumber,
password,
zipCode: numberedZip,
},
});
console.log('data', data.addHelper.id);
const uID = Number(data.addHelper.id);
setAuthID(uID);
setForm(initialState);
navigation.navigate('JuniorDash');
} catch (error) {
console.log('error', error);
}
// TODO: once id returns, need to set it to global auth state (maybe use onCompleted for useMutation?)
};
return (
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<View style={styles.container}>
<Text style={styles.labels}>Name</Text>
<TextInput
style={styles.inputFields}
placeholder="Name"
onChangeText={text => setForm({...form, name: text})}
value={form.name}
/>
<Text style={styles.labels}>Email</Text>
<TextInput
style={styles.inputFields}
placeholder="[email protected]"
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 JuniorSignup;
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,
},
});