1+ import React from 'react' ;
2+ import Avatar from '@material-ui/core/Avatar' ;
3+ import Button from '@material-ui/core/Button' ;
4+ import CssBaseline from '@material-ui/core/CssBaseline' ;
5+ import TextField from '@material-ui/core/TextField' ;
6+ import FormControlLabel from '@material-ui/core/FormControlLabel' ;
7+ import Checkbox from '@material-ui/core/Checkbox' ;
8+ import Link from '@material-ui/core/Link' ;
9+ import Grid from '@material-ui/core/Grid' ;
10+ import Box from '@material-ui/core/Box' ;
11+ import LockOutlinedIcon from '@material-ui/icons/LockOutlined' ;
12+ import Typography from '@material-ui/core/Typography' ;
13+ import { makeStyles } from '@material-ui/core/styles' ;
14+ import Container from '@material-ui/core/Container' ;
15+ import { useHistory } from 'react-router-dom'
16+
17+ import { useAuth } from "../context/AuthContext"
18+
19+ function Copyright ( ) {
20+ return (
21+ < Typography variant = "body2" color = "textSecondary" align = "center" >
22+ { 'Copyright © ' }
23+ < Link color = "inherit" href = "https://material-ui.com/" >
24+ Your Website
25+ </ Link > { ' ' }
26+ { new Date ( ) . getFullYear ( ) }
27+ { '.' }
28+ </ Typography >
29+ ) ;
30+ }
31+
32+ const useStyles = makeStyles ( ( theme ) => ( {
33+ paper : {
34+ marginTop : theme . spacing ( 8 ) ,
35+ display : 'flex' ,
36+ flexDirection : 'column' ,
37+ alignItems : 'center' ,
38+ } ,
39+ avatar : {
40+ margin : theme . spacing ( 1 ) ,
41+ backgroundColor : theme . palette . secondary . main ,
42+ } ,
43+ form : {
44+ width : '100%' , // Fix IE 11 issue.
45+ marginTop : theme . spacing ( 3 ) ,
46+ } ,
47+ submit : {
48+ margin : theme . spacing ( 3 , 0 , 2 ) ,
49+ } ,
50+ } ) ) ;
51+
52+ export default function SignUp ( ) {
53+ const classes = useStyles ( ) ;
54+ const { currentUser, updateEmail, updatePassword } = useAuth ( )
55+ const history = useHistory ( )
56+
57+ function handleSubmitUpdateProfile ( e ) {
58+ e . preventDefault ( )
59+ const signUpFields = {
60+ firstName : e . target . firstName . value ,
61+ lastName : e . target . lastName . value ,
62+ email : e . target . email . value ,
63+ password : e . target . password . value
64+ }
65+
66+ let promises = [ ]
67+ if ( signUpFields . email !== currentUser . email ) {
68+ promises . push ( updateEmail ( signUpFields . email ) )
69+ }
70+
71+ if ( signUpFields . password ) {
72+ promises . push ( updatePassword ( signUpFields . password ) )
73+ }
74+
75+
76+ Promise . all ( promises )
77+ . then ( ( ) => {
78+ history . push ( '/' )
79+ } )
80+ . catch ( error => {
81+ console . log ( 'error: ' , error ) ;
82+
83+ } )
84+ }
85+
86+ return (
87+ < Container component = "main" maxWidth = "xs" >
88+ < CssBaseline />
89+ < div className = { classes . paper } >
90+ < Avatar className = { classes . avatar } >
91+ < LockOutlinedIcon />
92+ </ Avatar >
93+ < Typography component = "h1" variant = "h5" >
94+ Update Profile
95+ </ Typography >
96+ < form className = { classes . form } onSubmit = { handleSubmitUpdateProfile } noValidate >
97+ < Grid container spacing = { 2 } >
98+ < Grid item xs = { 12 } sm = { 6 } >
99+ < TextField
100+ autoComplete = "fname"
101+ name = "firstName"
102+ variant = "outlined"
103+ required
104+ fullWidth
105+ id = "firstName"
106+ label = "First Name"
107+ autoFocus
108+ />
109+ </ Grid >
110+ < Grid item xs = { 12 } sm = { 6 } >
111+ < TextField
112+ variant = "outlined"
113+ required
114+ fullWidth
115+ id = "lastName"
116+ label = "Last Name"
117+ name = "lastName"
118+ autoComplete = "lname"
119+ />
120+ </ Grid >
121+ < Grid item xs = { 12 } >
122+ < TextField
123+ variant = "outlined"
124+ required
125+ fullWidth
126+ id = "email"
127+ label = "Email Address"
128+ name = "email"
129+ autoComplete = "email"
130+ />
131+ </ Grid >
132+ < Grid item xs = { 12 } >
133+ < TextField
134+ variant = "outlined"
135+ required
136+ fullWidth
137+ name = "password"
138+ label = "Password"
139+ type = "password"
140+ id = "password"
141+ autoComplete = "current-password"
142+ />
143+ </ Grid >
144+ { /* <Grid item xs={12}>
145+ <FormControlLabel
146+ control={<Checkbox value="allowExtraEmails" color="primary" />}
147+ label="I want to receive inspiration, marketing promotions and updates via email."
148+ />
149+ </Grid> */ }
150+ </ Grid >
151+ < Button
152+ type = "submit"
153+ fullWidth
154+ variant = "contained"
155+ color = "primary"
156+ className = { classes . submit }
157+ >
158+ Update profile
159+ </ Button >
160+ < Grid container justify = "flex-end" >
161+ < Grid item >
162+ < Link href = "/signup" variant = "body2" >
163+ Already have an account? Sign up
164+ </ Link >
165+ </ Grid >
166+ </ Grid >
167+ </ form >
168+ </ div >
169+ < Box mt = { 5 } >
170+ < Copyright />
171+ </ Box >
172+ </ Container >
173+ ) ;
174+ }
0 commit comments