22 * @desc this is the admin component of the application.
33 * @author gaurav sharma
44 */
5- import React , { useEffect } from 'react' ;
5+ import React , { useEffect , useState } from 'react' ;
66
77import { connect } from 'react-redux' ;
88import { userLogin } from '../../redux/actions' ;
99import { toast , ToastContainer } from 'react-toastify' ;
10- import FontAwesome from 'react-fontawesome ' ;
10+ import ChevronRightIcon from '@material-ui/icons/ChevronRight ' ;
1111
1212import LoadingOverlay from '../../components/LoadingOverlay' ;
1313
1414import './index.scss' ;
1515
1616
1717const LandingPage = ( props ) => {
18+ const [ user , setUser ] = useState ( "" )
19+ const [ password , setPassword ] = useState ( "" )
20+
1821 useEffect ( ( ) => {
1922 if ( localStorage . getItem ( 'data' ) ) {
2023 window . location = '/adminAccount' ;
@@ -44,8 +47,7 @@ const LandingPage = (props) => {
4447 const onLogin = ( e ) => {
4548 e . preventDefault ( ) ;
4649 const { triggerLoginUser } = props ;
47-
48- triggerLoginUser ( userUname . value , userPass . value ) ;
50+ triggerLoginUser ( user , password ) ;
4951 }
5052
5153 /**
@@ -66,6 +68,9 @@ const LandingPage = (props) => {
6668 }
6769 }
6870
71+ const onFormValid = ( ) => {
72+ return user && password
73+ }
6974
7075 const { fetching, login } = props ;
7176 { login && responseHandler ( ) }
@@ -83,13 +88,15 @@ const LandingPage = (props) => {
8388 < section className = 'user-login' id = 'user-login' >
8489
8590 < label htmlFor = "username" > Username</ label > < br />
86- < input ref = { userUname => userUname = userUname } className = 'custom-field login-field' placeholder = 'Username for user' />
91+ < input onChange = { e => setUser ( e . target . value ) } className = 'custom-field login-field' placeholder = 'Username for user' />
8792
8893 < label htmlFor = "username" > Password</ label > < br />
89- < input ref = { userPass => userPass = userPass } type = 'password' className = 'custom-field login-field' placeholder = 'Password for user' />
94+ < input onChange = { e => setPassword ( e . target . value ) } type = 'password' className = 'custom-field login-field' placeholder = 'Password for user' />
9095
9196 < p className = 'text-center' >
92- < button className = "litnite-btn" onClick = { onLogin } > LOGIN < FontAwesome name = "chevron-right" /> </ button >
97+ < button className = "litnite-btn" onClick = { onLogin } disabled = { ! onFormValid ( ) } > < span className = "content-center" >
98+ LOGIN < ChevronRightIcon />
99+ </ span > </ button >
93100 </ p >
94101
95102 < br /> < br /> < br />
0 commit comments