1
- import React from "react" ;
1
+ import React , { useState } from "react" ;
2
2
import { useNavigate } from 'react-router-dom' ;
3
3
4
4
// Material UI Imports
5
- import TextField from "@mui/material/TextField" ;
6
- import Button from "@mui/material/Button" ;
5
+ import TextField from '@mui/material/TextField' ;
6
+ import Button from '@mui/material/Button' ;
7
+ import Box from '@mui/material/Box' ;
8
+ import IconButton from '@mui/material/IconButton' ;
9
+ import OutlinedInput from '@mui/material/OutlinedInput' ;
10
+ import InputLabel from '@mui/material/InputLabel' ;
11
+ import InputAdornment from '@mui/material/InputAdornment' ;
12
+ import FormControl from '@mui/material/FormControl' ;
13
+ import Visibility from '@mui/icons-material/Visibility' ;
14
+ import VisibilityOff from '@mui/icons-material/VisibilityOff' ;
15
+ import PasswordStrengthBar from 'react-password-strength-bar' ;
16
+
7
17
8
18
// Helper Functions
9
19
import {
@@ -15,89 +25,144 @@ import {
15
25
16
26
const SignUp = ( ) => {
17
27
const navigate = useNavigate ( ) ;
18
-
28
+ const [ values , setValues ] = useState ( {
29
+ email : '' ,
30
+ username : '' ,
31
+ password : '' ,
32
+ passwordConfirmation : '' ,
33
+ phone : '' ,
34
+ showPassword : false ,
35
+ } ) ;
36
+
37
+ const handleClickShowPassword = ( ) => {
38
+ setValues ( {
39
+ ...values ,
40
+ showPassword : ! values . showPassword ,
41
+ } ) ;
42
+ } ;
43
+
19
44
return (
20
45
< div className = 'renderContainers' >
21
46
< div className = 'header' >
22
47
< h1 className = 'tabTitle' > Sign Up</ h1 >
23
48
</ div >
24
49
< div className = 'settings-container' >
25
- < form className = 'loginForm' >
26
- < TextField
27
- id = "signupEmail"
28
- label = "Email"
29
- variant = "outlined"
30
- sx = { {
31
- m : 1 ,
32
- } }
33
- />
34
- < br />
35
- < TextField
36
- id = "signupUsername"
37
- label = "Username"
38
- variant = "outlined"
39
- sx = { {
40
- m : 1 ,
41
- } }
42
- />
43
- < br />
44
- < TextField
45
- id = "signupPassword"
46
- label = "Password"
47
- variant = "outlined"
48
- type = "password"
49
- onChange = { ( ) => checkPasswordLength ( ) }
50
- sx = { {
51
- m : 1 ,
52
- } }
53
- />
54
- < span id = "password-length-alert" > </ span >
55
- < br />
56
- < TextField
57
- id = "signupPasswordConfirmation"
58
- label = "Confirm Password"
59
- variant = "outlined"
60
- type = "password"
61
- onChange = { ( ) => confirmPassword ( ) }
62
- sx = { {
63
- m : 1 ,
64
- } }
65
- />
66
- < span id = "password-confirmation-alert" > </ span >
67
- < br />
68
- < TextField
69
- id = "signupPhone"
70
- label = "Phone"
71
- variant = "outlined"
72
- onChange = { ( ) => {
73
- //fixing the property 'value' does not exist on type 'HTMLElement'
74
- const inputValue = (
75
- document . getElementById ( "signupPhone" ) as HTMLTextAreaElement
76
- ) . value ;
77
- checkPhone ( inputValue ) ;
78
- } }
79
- sx = { {
80
- m : 1 ,
81
- } }
50
+ < Box
51
+ className = 'settingsForm'
52
+ component = 'form'
53
+ autoComplete = 'off'
54
+ onSubmit = { ( e : any ) => handleNewUser ( e , e . target . roleID ) }
55
+ sx = { { color :'blue' } }
56
+ >
57
+
58
+ < TextField
59
+ id = 'signupEmail'
60
+ label = 'Email'
61
+ variant = 'outlined'
62
+ required
63
+ sx = { {
64
+ m : 1
65
+ } }
66
+ />
67
+ < br />
68
+ < TextField
69
+ id = 'signupUsername'
70
+ label = 'Username'
71
+ variant = 'outlined'
72
+ required
73
+ inputProps = { { minLength : 4 , maxLength : 16 } }
74
+ sx = { {
75
+ m : 1
76
+ } }
77
+ />
78
+ < br />
79
+
80
+ < FormControl sx = { { m : 1 , maxWidth :195 } } variant = "outlined" >
81
+ < InputLabel htmlFor = "signupPassword" > Password</ InputLabel >
82
+ < OutlinedInput
83
+ id = "signupPassword"
84
+ type = { values . showPassword ? 'text' : 'password' }
85
+ onChange = { ( e ) => {
86
+ checkPasswordLength ( ) ;
87
+ setValues ( { ...values , password :e . target . value } )
88
+ } }
89
+ endAdornment = {
90
+ < InputAdornment position = "end" >
91
+ < IconButton
92
+ aria-label = "toggle password visibility"
93
+ onClick = { handleClickShowPassword }
94
+ // onMouseDown={handleMouseDownPassword}
95
+ edge = "end"
96
+ >
97
+ { values . showPassword ? < VisibilityOff /> : < Visibility /> }
98
+ </ IconButton >
99
+ </ InputAdornment >
100
+ }
101
+ label = "Password"
82
102
/>
83
- < br />
84
- < span id = "phone-alert" > </ span >
85
- < br />
86
- < Button
87
- variant = "contained"
88
- size = "medium"
89
- type = "submit"
90
- onClick = { ( e ) => {
91
- handleNewUser ( e , '1' )
92
- navigate ( '/' )
93
- } }
94
- sx = { {
95
- m : 1 ,
96
- } }
97
- >
98
- Submit
103
+ </ FormControl >
104
+ { values . password && < PasswordStrengthBar style = { { maxWidth :'190px' , color :'red' , marginLeft :10 } } password = { values . password } /> }
105
+ < span id = 'password-length-alert' style = { { fontSize :10 , textAlign :'left' , maxWidth :190 , display :'inline-block' , marginLeft :10 } } > </ span >
106
+
107
+ < br />
108
+ < TextField
109
+ id = 'signupPasswordConfirmation'
110
+ label = 'Confirm Password'
111
+ variant = 'outlined'
112
+ type = 'password'
113
+ required
114
+ onChange = { ( e ) => {
115
+ setValues ( { ...values , passwordConfirmation :e . target . value } )
116
+ confirmPassword ( )
117
+ } }
118
+ sx = { {
119
+ m : 1
120
+ } }
121
+ />
122
+ { /* This is sacrilege but I hardcoded this bar and made it hidden to keep the same formatting as above */ }
123
+ { < PasswordStrengthBar style = { { maxWidth :'190px' , color :'red' , marginBottom :- 20 , visibility :'hidden' , maxHeight :0 } } /> }
124
+ < span id = 'password-confirmation-alert' style = { { fontSize :10 , textAlign :'left' , maxWidth :190 , display :'inline-block' , marginLeft :10 , paddingTop :15 } } > </ span >
125
+ < br />
126
+ < TextField
127
+ id = 'signupPhone'
128
+ label = 'Phone'
129
+ variant = 'outlined'
130
+ required
131
+ inputProps = { { maxLength : 12 } }
132
+
133
+ onChange = { ( ) => {
134
+ const inputElement = ( document . getElementById ( 'signupPhone' ) as HTMLInputElement ) . value ;
135
+ checkPhone ( inputElement )
136
+ } }
137
+ sx = { {
138
+ m : 1
139
+ } }
140
+ />
141
+ < br />
142
+ < span id = 'phone-alert' > </ span >
143
+ < br />
144
+ < Button
145
+ variant = 'contained'
146
+ size = 'medium'
147
+ onClick = { ( ) => {
148
+ history . back ( ) } }
149
+ sx = { {
150
+ m : 1
151
+ } }
152
+ >
153
+ Back
99
154
</ Button >
100
- </ form >
155
+ < Button
156
+ variant = 'contained'
157
+ size = 'medium'
158
+ type = 'submit'
159
+ sx = { {
160
+ m : 1
161
+ } }
162
+ >
163
+ Submit
164
+ </ Button >
165
+ </ Box >
101
166
</ div >
102
167
</ div >
103
168
)
0 commit comments