1
- import React , { Component } from 'react' ;
1
+ import React , { Component , useState } from 'react' ;
2
2
import { connect } from 'react' ;
3
3
import { LoginInt } from '../../interfaces/Interfaces' ;
4
4
import { setUsername , setPassword } from '../../actions/actionCreators' ;
@@ -26,7 +26,9 @@ const mapStateToProps = (store: any) => ({
26
26
27
27
const mapDispatchToProps = ( dispatch : any ) => ( {
28
28
setUsername : ( username : string ) => dispatch ( setUsername ( username ) ) ,
29
- setPassword : ( password : string ) => dispatch ( setPassword ( password ) )
29
+ setPassword : ( password : string ) => dispatch ( setPassword ( password ) ) ,
30
+ // login: (username: string, password: string) => dispatch(login(username, password)),
31
+ // signup: (username: string, password: string) => dispatch(signup(username, password)),
30
32
} )
31
33
32
34
interface LoginProps extends LoginInt {
@@ -69,7 +71,34 @@ const useStyles = makeStyles((theme) => ({
69
71
70
72
const SignIn : React . FC < LoginProps > = ( props ) => {
71
73
const classes = useStyles ( ) ;
72
- const count = useSelector ( state => state ) ;
74
+ //const count = useSelector(state => state);
75
+
76
+ const [ username , setUsername ] = useState ( '' ) ;
77
+ const [ password , setPassword ] = useState ( '' ) ;
78
+
79
+ const handleChange = ( e ) => {
80
+ let inputVal = e . target . value ;
81
+ switch ( e . target . name ) {
82
+ case 'username' :
83
+ setUsername ( inputVal ) ;
84
+ break ;
85
+ case 'password' :
86
+ setPassword ( inputVal ) ;
87
+ break ;
88
+ }
89
+ } ;
90
+
91
+ const handleLogin = ( e ) => {
92
+ console . log ( 'click fired on handleLogin' )
93
+ e . preventDefault ( ) ;
94
+ fetch ( '/login' , {
95
+ method : 'POST' ,
96
+ body : JSON . stringify ( { username, password } )
97
+ } )
98
+ . then ( res => res . json ( ) )
99
+ . then ( data => console . log ( data ) )
100
+ . catch ( err => console . log ( err ) )
101
+ }
73
102
74
103
return (
75
104
< Container component = "main" maxWidth = "xs" >
@@ -92,6 +121,8 @@ const SignIn: React.FC<LoginProps> = (props) => {
92
121
name = "username"
93
122
autoComplete = "username"
94
123
autoFocus
124
+ value = { password }
125
+ onChange = { handleChange }
95
126
/>
96
127
< TextField
97
128
variant = "outlined"
@@ -103,6 +134,8 @@ const SignIn: React.FC<LoginProps> = (props) => {
103
134
type = "password"
104
135
id = "password"
105
136
autoComplete = "current-password"
137
+ value = { password }
138
+ onChange = { handleChange }
106
139
/>
107
140
< FormControlLabel
108
141
control = { < Checkbox value = "remember" color = "primary" /> }
@@ -114,6 +147,7 @@ const SignIn: React.FC<LoginProps> = (props) => {
114
147
variant = "contained"
115
148
color = "primary"
116
149
className = { classes . submit }
150
+ onClick = { handleLogin }
117
151
>
118
152
Sign In
119
153
</ Button >
0 commit comments