refactor: guest mode
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
// import { useEffect } from "react";
|
||||
import { Navigate } from "react-router-dom";
|
||||
import { useGuestLoginQuery } from "../app/services/auth";
|
||||
import { useAppSelector } from "../app/store";
|
||||
|
||||
// type Props = {};
|
||||
|
||||
const GuestLogining = () => {
|
||||
useGuestLoginQuery();
|
||||
const { token, guest } = useAppSelector((store) => store.authData);
|
||||
if (token && guest) return <Navigate to={"/"} replace />;
|
||||
return null;
|
||||
};
|
||||
|
||||
export default GuestLogining;
|
||||
@@ -55,7 +55,7 @@ export default function HomePage() {
|
||||
return (
|
||||
<>
|
||||
<Manifest />
|
||||
<Notification />
|
||||
{!guest && <Notification />}
|
||||
<StyledWrapper className={guest ? "guest" : ""}>
|
||||
{!guest && (
|
||||
<div className={`col left`}>
|
||||
|
||||
@@ -26,6 +26,7 @@ import HomePage from "./home";
|
||||
import ChatPage from "./chat";
|
||||
import Loading from "../common/component/Loading";
|
||||
import store, { useAppSelector } from "../app/store";
|
||||
import GuestLogining from "./guest";
|
||||
let toastId: string;
|
||||
const PageRoutes = () => {
|
||||
const {
|
||||
@@ -48,6 +49,7 @@ const PageRoutes = () => {
|
||||
<HashRouter>
|
||||
<Suspense fallback={<Loading fullscreen={true} />}>
|
||||
<Routes>
|
||||
<Route path="/guest_login" element={<GuestLogining />} />
|
||||
<Route path="/oauth/:token" element={<OAuthPage />} />
|
||||
<Route
|
||||
path="/login"
|
||||
@@ -91,6 +93,7 @@ const PageRoutes = () => {
|
||||
<Route path="/onboarding" element={<OnboardingPage />} />
|
||||
|
||||
<Route
|
||||
key={"main"}
|
||||
path="/"
|
||||
element={
|
||||
<RequireAuth>
|
||||
|
||||
@@ -6,6 +6,8 @@ import StyledModal from "../../common/component/styled/Modal";
|
||||
import Button from "../../common/component/styled/Button";
|
||||
import Checkbox from "../../common/component/styled/Checkbox";
|
||||
import useLogout from "../../common/hook/useLogout";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useAppSelector } from "../../app/store";
|
||||
|
||||
const StyledConfirm = styled(StyledModal)`
|
||||
.clear {
|
||||
@@ -32,6 +34,8 @@ interface Props {
|
||||
}
|
||||
|
||||
const LogoutConfirmModal: FC<Props> = ({ closeModal }) => {
|
||||
const token = useAppSelector((store) => store.authData.token);
|
||||
const navigateTo = useNavigate();
|
||||
const [clearLocal, setClearLocal] = useState(false);
|
||||
const { logout, exited, exiting, clearLocalData } = useLogout();
|
||||
const handleLogout = () => {
|
||||
@@ -48,12 +52,13 @@ const LogoutConfirmModal: FC<Props> = ({ closeModal }) => {
|
||||
clearLocalData();
|
||||
}
|
||||
toast.success("Logout Successfully");
|
||||
setTimeout(() => {
|
||||
location.href = `${location.origin}#/login`;
|
||||
}, 500);
|
||||
// location.reload();
|
||||
}
|
||||
}, [exited, clearLocal]);
|
||||
useEffect(() => {
|
||||
if (!token) {
|
||||
navigateTo("/login");
|
||||
}
|
||||
}, [token]);
|
||||
|
||||
return (
|
||||
<Modal id="modal-modal">
|
||||
|
||||
Reference in New Issue
Block a user