@@ -9,6 +9,7 @@ import {auth, provider} from "./firebase/FirebaseConfig";
99import { signInWithPopup } from "firebase/auth" ;
1010import { handleCreateUserWithEmailAndPassword , handleSignInWithEmailAndPassword } from './firebase/LoginAuthCreation' ;
1111import ClipLoader from 'react-spinners/ClipLoader' ;
12+ import Popup from "../popup/Popup" ;
1213
1314// for each time show the google accounts in the dialog
1415provider . setCustomParameters ( {
@@ -24,7 +25,9 @@ function LoginPage(props) {
2425 const navigateToNextPage = useNavigate ( ) ;
2526 const { setLoggedInUser} = props ;
2627 const [ isLoading , setIsLoading ] = useState ( false ) ;
28+ const [ showPopup , setShowPopup ] = useState ( false ) ;
2729 const [ isRegisterClicked , setRegisterClicked ] = useState ( false ) ;
30+ const isReadInfoOnce = localStorage . getItem ( 'isInfoRead' ) || false ;
2831
2932 //password requirement
3033 const [ isPwdFeedbackHint , setPwdFeedbackHint ] = useState ( null ) ;
@@ -92,6 +95,16 @@ function LoginPage(props) {
9295 } , [ input . password , handlePasswordErrorFeedback ] )
9396
9497
98+ // For show the popup initially
99+ useEffect ( ( ) => {
100+ const timer = setTimeout ( ( ) => {
101+ setShowPopup ( true ) ;
102+ } , 1500 )
103+
104+ return ( ) => clearTimeout ( timer ) ;
105+ } , [ ] )
106+
107+
95108 // Login via username/password
96109 async function loginClicked ( e ) {
97110 e . preventDefault ( ) ;
@@ -128,7 +141,6 @@ function LoginPage(props) {
128141
129142 // Register via username/password
130143 const registerClicked = async ( ) => {
131-
132144 // validate username/email and password
133145 const isValidated = handleValidationForUserInput ( input . username , input . password ) ;
134146 if ( ! isValidated ) return ;
@@ -185,11 +197,10 @@ function LoginPage(props) {
185197 function googleLogin ( ) {
186198 //signInWithRedirect(auth, provider) // alternative for Glogin
187199 signInWithPopup ( auth , provider ) . then ( ( data ) => {
188- storeLoginSuccessAndNavigate ( data ?. user )
200+ storeLoginSuccessAndNavigate ( data ?. user ) ;
189201 } ) . catch ( ( e ) => {
190- console . error ( "signinpopup catch--" , e )
202+ console . error ( "signinpopup catch--" , e ) ;
191203 } )
192-
193204 }
194205
195206 // Stored LoginStatus in localStorage and navigate to home
@@ -202,8 +213,8 @@ function LoginPage(props) {
202213 loggedInPhotoUrl : user ?. photoURL || ""
203214 }
204215 localStorage . setItem ( "loggedInData" , JSON . stringify ( loginObj ) ) ;
205- setLoggedInUser ( true )
206- navigateToNextPage ( '/home' )
216+ setLoggedInUser ( true ) ;
217+ navigateToNextPage ( '/home' ) ;
207218 }
208219
209220 // To show toast
@@ -215,10 +226,20 @@ function LoginPage(props) {
215226 }
216227 return ;
217228 }
229+
230+ const closePopupInfo = ( isRead = false ) => {
231+ if ( isRead ) {
232+ setShowPopup ( false ) ;
233+ localStorage . setItem ( 'isInfoRead' , true ) ;
234+ }
235+ }
218236
219237 return (
220238
221239 < div className = "cover" >
240+ { /* Popup shown initially */ }
241+ { showPopup && ! isReadInfoOnce && ( < Popup setClosePopup = { closePopupInfo } /> ) }
242+
222243 < u > < h2 > { isRegisterClicked ? "Register Here " : "Login Here " } </ h2 > </ u >
223244 < p > { ! isRegisterClicked ? "Sign in" : "Register here" } & let 's get started </ p >
224245 { errorMessageEmail . length > 0 && ( < div className = "error1" > { errorMessageEmail } </ div > ) }
0 commit comments