1
1
/* eslint-disable */
2
- import React , { useEffect , useRef , useState } from " react" ;
3
- import { FcGoogle } from " react-icons/fc" ;
4
- import { BiSolidShow } from " react-icons/bi" ;
5
- import { BiSolidHide } from " react-icons/bi" ;
6
- import { useAppDispatch , useAppSelector } from " ../store/store" ;
7
- import { loginUser } from " ../store/features/auth/authSlice" ;
8
- import { toast } from " react-toastify" ;
9
- import { useFormik } from " formik" ;
10
- import * as Yup from " yup" ;
11
- import { Link , useNavigate } from " react-router-dom" ;
12
- import { PulseLoader } from " react-spinners" ;
13
- import { addProductToWishlist } from " ../store/features/wishlist/wishlistSlice" ;
14
- import authService from " ../store/features/auth/authService" ;
2
+ import React , { useEffect , useRef , useState } from ' react' ;
3
+ import { FcGoogle } from ' react-icons/fc' ;
4
+ import { BiSolidShow } from ' react-icons/bi' ;
5
+ import { BiSolidHide } from ' react-icons/bi' ;
6
+ import { useAppDispatch , useAppSelector } from ' ../store/store' ;
7
+ import { loginUser } from ' ../store/features/auth/authSlice' ;
8
+ import { toast } from ' react-toastify' ;
9
+ import { useFormik } from ' formik' ;
10
+ import * as Yup from ' yup' ;
11
+ import { Link , useNavigate } from ' react-router-dom' ;
12
+ import { PulseLoader } from ' react-spinners' ;
13
+ import { addProductToWishlist } from ' ../store/features/wishlist/wishlistSlice' ;
14
+ import authService from ' ../store/features/auth/authService' ;
15
15
import { joinRoom } from '../utils/socket/socket' ;
16
16
17
17
const LoginSchema = Yup . object ( ) . shape ( {
18
18
email : Yup . string ( )
19
- . email ( " Email must be valid" )
20
- . required ( " Email is required" ) ,
21
- password : Yup . string ( ) . required ( " Password is required" ) ,
19
+ . email ( ' Email must be valid' )
20
+ . required ( ' Email is required' ) ,
21
+ password : Yup . string ( ) . required ( ' Password is required' ) ,
22
22
} ) ;
23
23
24
24
function UserLogin ( ) {
@@ -39,35 +39,39 @@ function UserLogin() {
39
39
40
40
const formik = useFormik ( {
41
41
initialValues : {
42
- email : "" ,
43
- password : "" ,
42
+ email : '' ,
43
+ password : '' ,
44
44
} ,
45
45
validationSchema : LoginSchema ,
46
46
onSubmit : async ( values ) => {
47
+ const { email } = values ;
48
+ localStorage . setItem ( 'loggedEmail' , email ) ;
47
49
const action = await dispatch ( loginUser ( values ) ) ;
48
50
if ( loginUser . fulfilled . match ( action ) ) {
49
- const pendingWishlistProduct = localStorage . getItem ( "pendingWishlistProduct" ) ;
51
+ const pendingWishlistProduct = localStorage . getItem (
52
+ 'pendingWishlistProduct'
53
+ ) ;
50
54
if ( pendingWishlistProduct ) {
51
55
await dispatch ( addProductToWishlist ( pendingWishlistProduct ) ) ;
52
- localStorage . removeItem ( " pendingWishlistProduct" ) ;
56
+ localStorage . removeItem ( ' pendingWishlistProduct' ) ;
53
57
}
54
58
}
55
- }
59
+ } ,
56
60
} ) ;
57
61
58
62
useEffect ( ( ) => {
59
- const token = localStorage . getItem ( " token" ) ;
63
+ const token = localStorage . getItem ( ' token' ) ;
60
64
if ( token ) {
61
- navigate ( " /home" ) ;
65
+ navigate ( ' /home' ) ;
62
66
}
63
67
} , [ navigate ] ) ;
64
68
65
69
useEffect (
66
70
function ( ) {
67
71
if ( isSuccess && token && isAuthenticated ) {
68
- localStorage . setItem ( " token" , token ) ;
72
+ localStorage . setItem ( ' token' , token ) ;
69
73
toast . success ( message ) ;
70
- navigate ( " /home" ) ;
74
+ navigate ( ' /home' ) ;
71
75
formik . resetForm ( ) ;
72
76
joinRoom ( token ) ;
73
77
}
@@ -121,7 +125,7 @@ function UserLogin() {
121
125
</ div >
122
126
< div className = "form__group" >
123
127
< input
124
- type = { isVisible ? " text" : " password" }
128
+ type = { isVisible ? ' text' : ' password' }
125
129
placeholder = "Password"
126
130
className = "form__input"
127
131
id = "password"
@@ -144,7 +148,7 @@ function UserLogin() {
144
148
/>
145
149
)
146
150
) : (
147
- ""
151
+ ''
148
152
) }
149
153
< p className = "form__text" >
150
154
< Link to = "/reset-password" className = "form__link" >
@@ -161,11 +165,11 @@ function UserLogin() {
161
165
) : null }
162
166
< button
163
167
type = "submit"
164
- className = { `btn form__btn${ isLoading ? " loading" : "" } ` }
168
+ className = { `btn form__btn${ isLoading ? ' loading' : '' } ` }
165
169
disabled = { isLoading }
166
170
onClick = { ( ) => setIsClicked ( true ) }
167
171
>
168
- < span > { isLoading ? " Loading " : " Login" } </ span >
172
+ < span > { isLoading ? ' Loading ' : ' Login' } </ span >
169
173
< PulseLoader size = { 6 } color = "#ffe2d1" loading = { isLoading } />
170
174
</ button >
171
175
</ form >
@@ -186,4 +190,4 @@ function UserLogin() {
186
190
) ;
187
191
}
188
192
189
- export default UserLogin ;
193
+ export default UserLogin ;
0 commit comments