1
1
import React , { Component } from 'react' ;
2
- import './Phone/Phone.css' ;
2
+ import PropTypes from 'prop-types' ;
3
+ import './Profile/Profile.css' ;
4
+ import API from './callAPI' ;
5
+
3
6
4
7
class Login extends Component {
5
8
@@ -30,20 +33,9 @@ class Login extends Component {
30
33
}
31
34
32
35
handleSubmit ( event ) {
33
- event . preventDefault ( ) ;
34
-
36
+ event . preventDefault ( ) ; // Don't submit the form. We will call the API ourself.
35
37
this . setState ( { errorMessage : '' } ) ;
36
- fetch ( this . props . isLogin ? '/api/users/login' : '/api/users/signup' , {
37
- headers : {
38
- Accept : 'application/json' ,
39
- 'Content-Type' : 'application/json'
40
- } ,
41
- method : 'POST' ,
42
- credentials : 'include' ,
43
- body : JSON . stringify ( {
44
- email : this . state . email , password : this . state . password
45
- } )
46
- } ) . then ( response => response . json ( ) )
38
+ API . loginOrSignup ( this . props . isLogin ? 'login' : 'signup' , this . state . email , this . state . password )
47
39
. then ( ( body ) => {
48
40
if ( body . ok ) {
49
41
this . props . onSubmit ( ) ;
@@ -63,7 +55,9 @@ class Login extends Component {
63
55
< img src = "images/username.svg" className = "icon" alt = "user" />
64
56
< input
65
57
id = "email"
66
- className = "logininput" type = "text" name = "email"
58
+ className = "logininput"
59
+ type = "text"
60
+ name = "email"
67
61
placeholder = "E-mail address"
68
62
onChange = { this . handleInputChange }
69
63
value = { this . state . email }
@@ -84,7 +78,11 @@ class Login extends Component {
84
78
< button className = "loginbutton" onClick = { this . submit } > { this . props . isLogin ? 'Login' : 'Sign Up' } </ button >
85
79
</ div >
86
80
</ form >
87
- < div className = "loginnew" onClick = { this . navigate } >
81
+ < div
82
+ className = "loginnew"
83
+ onClick = { this . navigate }
84
+ role = "presentation"
85
+ >
88
86
{ this . props . isLogin ? 'Add a new account' : 'Existing account?' }
89
87
</ div >
90
88
< div className = "messagearea" id = "messagearea" >
@@ -97,4 +95,9 @@ class Login extends Component {
97
95
}
98
96
}
99
97
98
+ Login . propTypes = {
99
+ isLogin : PropTypes . string . isRequired ,
100
+ onNavigate : PropTypes . func . isRequired ,
101
+ onSubmit : PropTypes . func . isRequired
102
+ } ;
100
103
export default Login ;
0 commit comments