2
2
import * as React from 'react' ;
3
3
import Link from 'valuelink' ;
4
4
import { Input , isEmail } from 'valuelink/tags' ;
5
- import { isDate } from './utilities.js' ;
5
+ import { isDate , isStrongPassword , isValidPostcode } from './utilities.js' ;
6
6
import './App.css' ;
7
7
8
8
const FormInput = ( props ) => {
9
9
const { label, ...rest } = props ;
10
10
return (
11
11
< tr >
12
- < td >
12
+ < td className = 'labeltext' >
13
13
{ label }
14
14
</ td >
15
15
< td >
@@ -41,15 +41,22 @@ class AddUser extends React.Component {
41
41
this . state = {
42
42
name : '' ,
43
43
email : '' ,
44
+ emailCheck : '' ,
45
+ password : '' ,
44
46
dob : '' ,
47
+ address : {
48
+ line1 : '' ,
49
+ line2 : '' ,
50
+ suburb : '' ,
51
+ postcode : ''
52
+ } ,
45
53
isActive : true
46
54
} ;
55
+ console . log ( this . state ) ;
47
56
}
48
57
49
58
onSubmit = e => {
50
- console . log ( 'pressed' ) ;
51
- this . setState ( { name : '' , email : '' , dob : '' , isActive : true } ) ;
52
- console . log ( this . state ) ;
59
+ this . setState ( { name : '' , email : '' , emailCheck : '' , password : '' , dob : '' , isActive : true , address : { line1 : '' , line2 : '' , suburb : '' , postcode : '' } } ) ;
53
60
e . preventDefault ( ) ;
54
61
} ;
55
62
@@ -61,24 +68,60 @@ class AddUser extends React.Component {
61
68
const emailLink = Link . state ( this , 'email' )
62
69
. check ( x => x , 'Email is required' )
63
70
. check ( x => isEmail ( x ) , 'Must be a valid email address' ) ;
71
+
72
+ const emailCheckLink = Link . state ( this , 'emailCheck' )
73
+ . check ( x => x , 'Re-enter Email is required' )
74
+ . check ( x => x = this . state . email , 'Emails addresses do not match' ) ;
75
+
76
+ const passwordLink = Link . state ( this , 'password' )
77
+ . check ( x => x , 'password is required' )
78
+ . check ( x => isStrongPassword ( x ) , 'Must be 8 characters ' ) ;
64
79
65
80
const dobLink = Link . state ( this , 'dob' )
66
81
. check ( x => x , 'DOB is required' )
67
82
. check ( x => isDate ( x ) , 'Must be a valid date in format yyyy-mm-dd' ) ;
68
83
84
+ const addressLine1Link = Link . state ( this , 'address' ) . at ( 'line1' )
85
+ . check ( x => x , 'Address Line 1 is required' ) ;
86
+
87
+ const addressLine2Link = Link . state ( this , 'address' ) . at ( 'line2' ) ;
88
+
89
+ const addressSuburbLink = Link . state ( this , 'address' ) . at ( 'suburb' )
90
+ . check ( x => x , 'Suburb is required' ) ; ;
91
+
92
+ const addressPostcodeLink = Link . state ( this , 'address' ) . at ( 'postcode' )
93
+ . check ( x => x , 'Postcode is required' )
94
+ . check ( x => isValidPostcode ( x ) , 'Postcode should be 4 digits only' ) ;
95
+
69
96
const isActiveLink = Link . state ( this , 'isActive' ) ;
70
97
71
98
return (
72
99
< div className = 'divStyle' >
73
- < h2 > Add User</ h2 >
100
+ { /* <h2>Add User</h2> */ }
74
101
< form onSubmit = { this . onSubmit } >
75
102
< table >
103
+ < thead >
104
+ < tr />
105
+ < tr >
106
+ < td />
107
+ < td className = 'formheader' > Add User</ td >
108
+ < td />
109
+ </ tr >
110
+ < tr />
111
+ </ thead >
76
112
< tbody >
77
113
< FormInput label = "Name:" valueLink = { nameLink } type = "text" placeholder = "username" size = "30" />
78
114
< FormInput label = "Email:" valueLink = { emailLink } type = "text" placeholder = "email" size = "30" />
115
+ < FormInput label = "Re-Enter Email:" valueLink = { emailCheckLink } type = "text" placeholder = "Re-enter email" size = "30" />
116
+ < FormInput label = "Password:" valueLink = { passwordLink } type = "password" placeholder = "password" />
79
117
< FormInput label = "DOB:" valueLink = { dobLink } type = "text" placeholder = "Date of Birth - yyyy-mm-dd" size = "30" />
80
118
< FormInput label = "Is active:" valueLink = { isActiveLink } type = "checkbox" />
81
- < FormButton buttonText = "Add User" type = "submit" disabled = { nameLink . error || emailLink . error || dobLink . error } />
119
+ < FormInput label = "Address Line 1:" valueLink = { addressLine1Link } type = "text" placeholder = "Address Line 1" size = "30" />
120
+ < FormInput label = "Address Line 2:" valueLink = { addressLine2Link } type = "text" placeholder = "Address Line 2" size = "30" />
121
+ < FormInput label = "Suburb:" valueLink = { addressSuburbLink } type = "text" placeholder = "Suburb" size = "30" />
122
+ < FormInput label = "Postcode:" valueLink = { addressPostcodeLink } type = "text" placeholder = "Postcode" size = "30" />
123
+ < FormButton buttonText = "Add" type = "submit" disabled = { nameLink . error || emailLink . error || dobLink . error } />
124
+ < FormButton buttonText = "Cancel" />
82
125
</ tbody >
83
126
</ table >
84
127
</ form >
0 commit comments