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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
|
// User Sign Up / Register page.
import { useEffect, useState } from 'react'
import { useSelector, useDispatch } from 'react-redux'
import { Link as RouterLink } from 'react-router-dom'
import {
Avatar,
Button,
Card,
Checkbox,
Container,
FormControlLabel,
Grid,
IconButton,
InputAdornment,
Link,
TextField,
Typography
} from '@material-ui/core'
import { makeStyles } from '@material-ui/core/styles'
import LockOutlinedIcon from '@material-ui/icons/LockOutlined'
import Visibility from '@material-ui/icons/Visibility'
import VisibilityOff from '@material-ui/icons/VisibilityOff'
import { signUp, authDefault, googleLogin, githubLogin } from '../redux/authSlice'
import github from '../static/github-mark.png'
import google from '../static/google.png'
const useStyles = makeStyles((theme) => ({
paper: {
marginTop: theme.spacing(20),
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
padding: theme.spacing(3, 5)
},
avatar: {
margin: theme.spacing(1),
backgroundColor: theme.palette.primary.main
},
form: {
width: '100%', // Fix IE 11 issue.
marginTop: theme.spacing(1)
},
submit: {
margin: theme.spacing(1.5, 0)
}
}))
export default function SignUp () {
const classes = useStyles()
const isRegistered = useSelector(state => state.auth.isRegistered)
const regErrors = useSelector(state => state.auth.regErrors)
const dispatch = useDispatch()
const homeURL = `${window.location.origin}/#/`
useEffect(() => {
document.title = 'Sign Up - ' + process.env.REACT_APP_NAME
return () => {
dispatch(authDefault())
}
}, [dispatch])
const [email, setEmail] = useState('')
const [password, setPassword] = useState('')
const [reenterPassword, setReenterPassword] = useState('')
const [accept, setAccept] = useState(true)
const [showPassword, setShowPassword] = useState(false)
const handleClickShowPassword = () => setShowPassword(!showPassword)
const handleMouseDownPassword = () => setShowPassword(!showPassword)
const [showReenterPassword, setShowReenterPassword] = useState(false)
const handleClickShowReenterPassword = () => setShowReenterPassword(!showReenterPassword)
const handleMouseDownReenterPassword = () => setShowReenterPassword(!showReenterPassword)
// Function call for google oAuth sign up.
const handleGoogleSignup = () => {
const host = window.location.origin
dispatch(googleLogin(host))
}
// Function call for github sign up.
const handleGithubSignup = () => {
const host = window.location.origin
dispatch(githubLogin(host))
}
return (
<Container component='main' maxWidth='xs'>
<Card className={classes.paper}>
<Avatar className={classes.avatar}>
<LockOutlinedIcon />
</Avatar>
<Typography component='h1' variant='h5'>
Register | Sign Up
</Typography>
{/* Display's error messages while signing in */}
<Typography variant='body1' align='center' style={{ marginTop: '10px' }} color={isRegistered ? 'secondary' : 'error'}>
{regErrors}
</Typography>
<form className={classes.form} noValidate>
<TextField
variant='outlined'
margin='normal'
required
fullWidth
id='email'
label='Email'
name='email'
type='email'
autoComplete='email'
value={email}
onChange={e => setEmail(e.target.value)}
autoFocus
/>
<TextField
variant='outlined'
margin='normal'
required
fullWidth
name='password'
label='Password'
InputProps={{
endAdornment: (
<InputAdornment position='end'>
<IconButton
size='small'
aria-label='toggle password visibility'
onClick={handleClickShowPassword}
onMouseDown={handleMouseDownPassword}
>
{showPassword ? <Visibility fontSize='small' /> : <VisibilityOff fontSize='small' />} {/* Handle password visibility */}
</IconButton>
</InputAdornment>
)
}}
type={showPassword ? 'text' : 'password'}
id='password'
value={password}
onChange={e => setPassword(e.target.value)}
autoComplete='current-password'
/>
<TextField
variant='outlined'
margin='normal'
required
fullWidth
name='reenterPassword'
label='Reenter Password'
InputProps={{
endAdornment: (
<InputAdornment position='end'>
<IconButton
size='small'
aria-label='toggle password visibility'
onClick={handleClickShowReenterPassword}
onMouseDown={handleMouseDownReenterPassword}
>
{showReenterPassword ? <Visibility fontSize='small' /> : <VisibilityOff fontSize='small' />} {/* Handle password visibility */}
</IconButton>
</InputAdornment>
)
}}
type={showReenterPassword ? 'text' : 'password'}
id='reenterPassword'
value={reenterPassword}
onChange={e => setReenterPassword(e.target.value)}
autoComplete='current-password'
/>
<FormControlLabel
control={<Checkbox checked={accept} onChange={e => setAccept(e.target.checked)} color='primary' />}
label='I accept the Terms of Use & Privacy Policy'
/>
<Button
fullWidth
variant='contained'
color='primary'
onClick={() => dispatch(signUp({ email, password, reenterPassword }))}
className={classes.submit}
disabled={!accept}
>
Sign Up
</Button>
<Typography variant='body2' color='secondary' align='center'>Or</Typography>
{/* Google oAuth Sign Up option */}
<Button
fullWidth
variant='outlined'
color='primary'
onClick={handleGoogleSignup}
className={classes.submit}
>
<img alt='Google' src={google} height='20' />  Sign Up With Google
</Button>
{/* Github Sign Up option */}
<Button
fullWidth
variant='outlined'
color='primary'
onClick={handleGithubSignup}
className={classes.submit}
>
<img alt='GitHub' src={github} height='20' />  Sign Up With GitHub
</Button>
</form>
<Grid container>
<Grid item style={{ margin: 'auto' }}>
<Link component={RouterLink} to='/login' variant='body2'>
Already have account? Login
</Link>
</Grid>
</Grid>
</Card>
<Button
fullWidth
onClick={() => { window.open(homeURL, '_self') }}
color='default'
className={classes.submit}
>
Back to home
</Button>
</Container>
)
}
|