-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthDetails.js
More file actions
96 lines (83 loc) · 2.58 KB
/
AuthDetails.js
File metadata and controls
96 lines (83 loc) · 2.58 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
import React, { useState, useEffect } from 'react';
import AuthLayout from './AuthLayout';
import { useForm, useUpdateProfileFields, useCurrentUser, useCompleteRegister } from '../../hooks';
import { update as updateAuth, useAuth } from '../../providers/AuthProvider';
import { Box, Button, Input, Select } from '../../ui-kit';
import authSteps from '../Auth/authSteps';
function upperFirst(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function AuthDetails(props) {
const [status, setStatus] = useState('IDLE');
const [error, setError] = useState(null);
const [user, setUser] = useState(null);
const [state, dispatch] = useAuth();
const [updateProfileFields] = useUpdateProfileFields();
const [completeRegister] = useCompleteRegister();
const { currentUser } = useCurrentUser();
useEffect(() => {
setUser(currentUser);
}, [currentUser]);
const onError = (e) => {
setStatus('ERROR');
setError(e);
};
const { values, handleSubmit, setFieldValue } = useForm(async () => {
setStatus('LOADING');
const userProfile = Object.keys(values).map((key) => ({
field: upperFirst(key),
value: values[key],
}));
try {
dispatch(
updateAuth({
userProfile,
})
);
await completeRegister({ variables: { profileInput: userProfile } });
dispatch(updateAuth({ step: authSteps.Success }));
} catch (e) {
onError(e);
console.log(JSON.stringify(e));
}
});
const isLoading = status === 'LOADING';
return (
<AuthLayout
{...props}
heading="Complete your profile"
subHeading="Help us learn a little more about you so we can connect you with the
best ministries and events."
>
<Box textAlign="left">
<Box mb="base">
<Input
id="firstName"
placeholder="First Name"
handleOnChange={(text) => setFieldValue('firstName', text)}
required
error={error?.firstName}
editable={!isLoading}
/>
</Box>
<Box mb="base">
<Input
id="lastName"
placeholder="Last Name"
handleOnChange={(text) => setFieldValue('lastName', text)}
required
error={error?.lastName}
editable={!isLoading}
/>
</Box>
</Box>
<Button
status={status}
title={`Finish${isLoading ? 'ing...' : ''}`}
onClick={handleSubmit}
disabled={!(values.firstName && values.lastName) || isLoading}
/>
</AuthLayout>
);
}
export default AuthDetails;