4
4
*/
5
5
import store from '../../renderer/store' ;
6
6
import * as actions from '../../actions/actions' ;
7
+ import { NetworkCellSharp , NextWeek } from '@material-ui/icons' ;
8
+ import { username } from '../../../security/email' ;
9
+ // TM - no react-redux imports?
7
10
8
11
export const handleNewUser = ( e ) => {
9
12
e . preventDefault ( ) ;
@@ -26,12 +29,10 @@ export const handleNewUser = (e) => {
26
29
}
27
30
if ( ! checkPhone ( phone ) ) {
28
31
window . alert (
29
- 'Warning: Please enter a valid phone number with country code (+1) in the following format:\n\n+12345678900'
30
- ) ;
32
+ 'Warning: Please enter a valid phone number with country code (+1) in the following format:\n\n+12345678900' ) ;
31
33
return ;
32
34
}
33
- console . log ( 'sending user data to createNewUser' ) ;
34
- // return createNewUser(email, username, password, phone);
35
+
35
36
createNewUser ( email , username , password , phone ) ;
36
37
} ;
37
38
@@ -55,10 +56,11 @@ export const confirmPassword = () => {
55
56
export const checkPasswordLength = ( ) => {
56
57
const passwordLengthAlert = document . getElementById ( 'password-length-alert' ) ;
57
58
const password = document . getElementById ( 'signupPassword' ) . value ;
59
+ const regex = / ^ (? = [ a - z \d ] { 6 , } $ ) (? = \d * [ a - z ] ) [ a - z ] * \d [ a - z \d ] * $ / ;
58
60
59
- if ( password . length < 6 ) {
61
+ if ( ! regex . test ( password ) ) {
60
62
passwordLengthAlert . innerHTML =
61
- 'Warning : Password must be 6 characters or longer' ;
63
+ '\nWarning : Password must be 6 characters or longer \nand must include at least one number and one letter ' ;
62
64
} else {
63
65
passwordLengthAlert . innerHTML = '' ;
64
66
}
@@ -101,36 +103,46 @@ export const createNewUser = (email, username, password, phone) => {
101
103
102
104
window . alert ( `New user has been successfully created. \n\n
103
105
An email with the user's credentials and login instructions has been sent to ${ email } ` ) ;
104
-
106
+
107
+ } ) . then ( ( ) => {
105
108
getUpdatedUserList ( ) ;
106
109
} )
107
110
. catch ( ( err ) => {
108
111
console . log ( err ) ;
109
112
} ) ;
110
113
} ;
111
114
115
+
112
116
export const getUpdatedUserList = ( ) => {
113
- console . log ( 'store username: ' , store . userInfo . username ) ;
117
+
118
+ // TM: Added this - do we need to use mapStateToProps to access the signed-in user's info?
119
+ // const mapStateToProps = state => {
120
+ // console.log(state);
121
+ // return{
122
+ // username: state.session.userName,
123
+ // token: state.session.token
124
+ // }};
125
+
126
+
114
127
fetch ( 'http://localhost:3000/admin' , {
115
128
method : 'POST' ,
116
129
headers : {
117
130
'Content-Type' : 'application/json' ,
118
131
} ,
119
132
body : JSON . stringify ( {
120
- username : store . userInfo . username ,
121
- token : store . userInfo . token ,
133
+ // username: store.userInfo.username, //TM: Accessing store.userInfo.username returns undefined - this is original code
134
+ // token: store.userInfo.token,
122
135
} ) ,
123
136
} )
124
137
. then ( ( response ) => response . json ( ) )
125
138
. then ( ( data ) => {
126
- console . log ( 'this is data from newUserHelper' , data ) ;
127
139
updateUserList ( data ) ;
128
140
} )
129
141
. catch ( ( err ) => {
130
142
console . log ( 'error in getUpdatedUserList: ' , err ) ;
131
- } )
143
+ } ) ;
132
144
} ;
133
145
134
- export const updateUserList = ( data ) => {
146
+ export const updateUserList = ( data ) => { // TM: react-redux is not imported but this is still working... redux is stupid
135
147
store . dispatch ( actions . updateUserList ( data ) ) ;
136
148
} ;
0 commit comments