Skip to content

Commit b5b262a

Browse files
#TRAPWLS-19 Popup shown intially in Login screen
1 parent d5b13ef commit b5b262a

File tree

4 files changed

+80
-7
lines changed

4 files changed

+80
-7
lines changed

src/loginAuthentication/LoginPage.css

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,35 @@ input:focus{
143143
align-items: center;
144144
background-color: rgba(255, 255, 255, 0.8);
145145
z-index: 1;
146+
}
147+
148+
/* Styling for Popup*/
149+
.popup-overlay {
150+
position: fixed;
151+
top: 0;
152+
left: 0;
153+
right: 0;
154+
bottom: 0;
155+
background: rgba(0, 0, 0, 0.5); /* Semi-transparent background */
156+
display: flex;
157+
justify-content: center;
158+
align-items: center;
159+
}
160+
161+
.popup {
162+
background: #fff;
163+
padding: 20px;
164+
border-radius: 8px;
165+
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
166+
text-align: center;
167+
max-width: 500px; /* Limit the max width */
168+
width: 100%;
169+
box-sizing: border-box;
170+
overflow-wrap: break-word;
171+
}
172+
173+
.popup button {
174+
margin-top: 10px;
175+
padding: 8px 16px;
176+
cursor: pointer;
146177
}

src/loginAuthentication/LoginPage.jsx

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {auth, provider} from "./firebase/FirebaseConfig";
99
import {signInWithPopup } from "firebase/auth";
1010
import {handleCreateUserWithEmailAndPassword, handleSignInWithEmailAndPassword} from './firebase/LoginAuthCreation';
1111
import ClipLoader from 'react-spinners/ClipLoader';
12+
import Popup from "../popup/Popup";
1213

1314
// for each time show the google accounts in the dialog
1415
provider.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>)}

src/popup/Popup.jsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { APP_INITIAL_POPUP_MSG } from "../utility/constants";
2+
3+
4+
const Popup = (props) => {
5+
const { setClosePopup } = props;
6+
7+
const closePopup = () => {
8+
setClosePopup(true);
9+
}
10+
11+
return(
12+
<div className="popup-overlay">
13+
<div className="popup">
14+
<img src="favicon1.ico" alt='' />
15+
<p dangerouslySetInnerHTML={{__html: APP_INITIAL_POPUP_MSG}}></p>
16+
<button onClick={closePopup}>OK</button>
17+
</div>
18+
</div>
19+
);
20+
}
21+
export default Popup;

src/utility/constants.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)