@@ -3,6 +3,7 @@ import { Link, withRouter } from 'react-router-dom';
3
3
4
4
import { withFirebase } from '../Firebase' ;
5
5
import * as ROUTES from '../../constants/routes' ;
6
+ import * as ROLES from '../../constants/roles' ;
6
7
7
8
const SignUpPage = ( ) => (
8
9
< div >
@@ -16,6 +17,7 @@ const INITIAL_STATE = {
16
17
email : '' ,
17
18
passwordOne : '' ,
18
19
passwordTwo : '' ,
20
+ isAdmin : false ,
19
21
error : null ,
20
22
} ;
21
23
@@ -27,7 +29,12 @@ class SignUpFormBase extends Component {
27
29
}
28
30
29
31
onSubmit = event => {
30
- const { username, email, passwordOne } = this . state ;
32
+ const { username, email, passwordOne, isAdmin } = this . state ;
33
+ const roles = [ ] ;
34
+
35
+ if ( isAdmin ) {
36
+ roles . push ( ROLES . ADMIN ) ;
37
+ }
31
38
32
39
this . props . firebase
33
40
. doCreateUserWithEmailAndPassword ( email , passwordOne )
@@ -38,6 +45,7 @@ class SignUpFormBase extends Component {
38
45
. set ( {
39
46
username,
40
47
email,
48
+ roles,
41
49
} )
42
50
. then ( ( ) => {
43
51
this . setState ( { ...INITIAL_STATE } ) ;
@@ -58,12 +66,17 @@ class SignUpFormBase extends Component {
58
66
this . setState ( { [ event . target . name ] : event . target . value } ) ;
59
67
} ;
60
68
69
+ onChangeCheckbox = event => {
70
+ this . setState ( { [ event . target . name ] : event . target . checked } ) ;
71
+ } ;
72
+
61
73
render ( ) {
62
74
const {
63
75
username,
64
76
email,
65
77
passwordOne,
66
78
passwordTwo,
79
+ isAdmin,
67
80
error,
68
81
} = this . state ;
69
82
@@ -103,6 +116,15 @@ class SignUpFormBase extends Component {
103
116
type = "password"
104
117
placeholder = "Confirm Password"
105
118
/>
119
+ < label >
120
+ Admin:
121
+ < input
122
+ name = "isAdmin"
123
+ type = "checkbox"
124
+ checked = { isAdmin }
125
+ onChange = { this . onChangeCheckbox }
126
+ />
127
+ </ label >
106
128
< button disabled = { isInvalid } type = "submit" >
107
129
Sign Up
108
130
</ button >
0 commit comments