From 1c55d66f71eea38969df2692f72830598d643663 Mon Sep 17 00:00:00 2001 From: HitanshiMehta <41253570+HitanshiMehta@users.noreply.github.com> Date: Wed, 5 Feb 2025 12:52:26 +0530 Subject: [PATCH] feat: added confirmation warning when user try to login anonymously(#743) Co-authored-by: Dunsin <78784850+Dun-sin@users.noreply.github.com> --- client/src/pages/Home.jsx | 143 ++++++++++++++++++++++++-------------- 1 file changed, 90 insertions(+), 53 deletions(-) diff --git a/client/src/pages/Home.jsx b/client/src/pages/Home.jsx index c9ca076d..c5001bae 100644 --- a/client/src/pages/Home.jsx +++ b/client/src/pages/Home.jsx @@ -1,64 +1,101 @@ import React, { useState } from 'react'; + +import { IoIosArrowRoundBack } from "react-icons/io"; +import { useNavigate } from 'react-router-dom'; + + import Login from './Login'; import { useAuth } from 'src/context/AuthContext'; +import { useDialog } from 'src/context/DialogContext'; + const userID = Math.random().toFixed(12).toString(36).slice(2); + const Home = () => { - const { dispatchAuth } = useAuth(); - - const [isLogginWithEmail, setIsLogginWithEmail] = useState(false); - - function loginAnonymously() { - dispatchAuth({ - type: 'LOGIN', - payload: { - loginType: 'anonymous', - loginId: userID, - email: null, - }, - }); - } - - return ( -
-
-
-
-

WHISPER

-

- Chat anonymously and safely with people for free -

-
- - {isLogginWithEmail ? ( - - ) : ( -
- - -
- )} -
-
- -
-
-
- ); + const { dispatchAuth } = useAuth(); + const { setDialog } = useDialog(); + const navigate = useNavigate(); + + + const [isLogginWithEmail, setIsLogginWithEmail] = useState(false); + + + function loginAnonymously() { + dispatchAuth({ + type: 'LOGIN', + payload: { + loginType: 'anonymous', + loginId: userID, + email: null, + }, + }); + } + + + const handleLoginAnonymously = () => { + setDialog({ + isOpen: true, + text: 'Are you sure you want to login anonymously?', + noBtnText: 'Cancel', + yesBtnText: 'Yes, log in anonymously', + handler: loginAnonymously + }); + }; + + + const handleBackClick = () => { + navigate(-1); // Go back to the previous page + }; + + + return ( +
+
+
+ {isLogginWithEmail &&
+ +
} +
+

WHISPER

+

+ Chat anonymously and safely with people for free +

+
+ + + {isLogginWithEmail ? ( + + ) : ( +
+ + +
+ )} +
+
+ +
+
+
+ ); }; + export default Home; + + +