Compare commits
No commits in common. "69cc3b9383647d4a4a58e01dcb91e64d9167ec1a" and "71dd35adc227b7128011dc7ed1b9c74403279ac1" have entirely different histories.
69cc3b9383
...
71dd35adc2
@ -19,7 +19,7 @@ import { useProjectName } from "../../hooks/useProjects";
|
|||||||
import eventBus from "../../services/eventBus";
|
import eventBus from "../../services/eventBus";
|
||||||
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
import { useHasUserPermission } from "../../hooks/useHasUserPermission";
|
||||||
import { MANAGE_PROJECT } from "../../utils/constants";
|
import { MANAGE_PROJECT } from "../../utils/constants";
|
||||||
import { useAuthModal, useLogout } from "../../hooks/useAuth";
|
import { useAuthModal } from "../../hooks/useAuth";
|
||||||
|
|
||||||
const Header = () => {
|
const Header = () => {
|
||||||
const { profile } = useProfile();
|
const { profile } = useProfile();
|
||||||
@ -29,7 +29,9 @@ const Header = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const {onOpen} = useAuthModal()
|
const {onOpen} = useAuthModal()
|
||||||
const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT);
|
const HasManageProjectPermission = useHasUserPermission(MANAGE_PROJECT);
|
||||||
const { mutate : logout,isPending:logouting} = useLogout()
|
// {
|
||||||
|
// console.log(location.pathname);
|
||||||
|
// }
|
||||||
|
|
||||||
const isDashboardPath =
|
const isDashboardPath =
|
||||||
/^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname);
|
/^\/dashboard$/.test(location.pathname) || /^\/$/.test(location.pathname);
|
||||||
@ -59,9 +61,41 @@ const Header = () => {
|
|||||||
return role ? role.name : "User";
|
return role ? role.name : "User";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleLogout = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
logout();
|
||||||
|
};
|
||||||
|
|
||||||
|
const logout = async () => {
|
||||||
|
try {
|
||||||
|
let data = {
|
||||||
|
refreshToken: localStorage.getItem("refreshToken"),
|
||||||
|
};
|
||||||
|
|
||||||
|
AuthRepository.logout(data)
|
||||||
|
.then(() => {
|
||||||
|
localStorage.removeItem("jwtToken");
|
||||||
|
localStorage.removeItem("refreshToken");
|
||||||
|
localStorage.removeItem("user");
|
||||||
|
localStorage.clear();
|
||||||
|
clearAllCache();
|
||||||
|
window.location.href = "/auth/login";
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
localStorage.removeItem("jwtToken");
|
||||||
|
localStorage.removeItem("refreshToken");
|
||||||
|
localStorage.removeItem("user");
|
||||||
|
localStorage.clear();
|
||||||
|
clearAllCache();
|
||||||
|
window.location.href = "/auth/login";
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(
|
||||||
|
"Error during logout:",
|
||||||
|
error?.response?.data || error.message
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleProfilePage = () => {
|
const handleProfilePage = () => {
|
||||||
navigate(`/employee/${profile?.employeeInfo?.id}`);
|
navigate(`/employee/${profile?.employeeInfo?.id}`);
|
||||||
@ -440,10 +474,11 @@ const Header = () => {
|
|||||||
<a
|
<a
|
||||||
aria-label="click to log out"
|
aria-label="click to log out"
|
||||||
className="dropdown-item cusor-pointer"
|
className="dropdown-item cusor-pointer"
|
||||||
onClick={()=>handleLogout()}
|
href="/logout"
|
||||||
|
onClick={handleLogout}
|
||||||
>
|
>
|
||||||
{logouting ? "Please Wait":<> <i className="bx bx-log-out me-2"></i>
|
<i className="bx bx-power-off me-2"></i>
|
||||||
<span className="align-middle">SignOut</span></>}
|
<span className="align-middle">Log Out</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
@ -53,31 +53,4 @@ export const useAuthModal = () => {
|
|||||||
onOpen: () => dispatch(openAuthModal()),
|
onOpen: () => dispatch(openAuthModal()),
|
||||||
onClose: () => dispatch(closeAuthModal()),
|
onClose: () => dispatch(closeAuthModal()),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useLogout = ()=>{
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
|
|
||||||
return useMutation({
|
|
||||||
mutationFn: async () => {
|
|
||||||
let payload = {refreshToken: localStorage.getItem("refreshToken")}
|
|
||||||
return await AuthRepository.logout(payload);
|
|
||||||
},
|
|
||||||
|
|
||||||
onSuccess: (data) => {
|
|
||||||
localStorage.removeItem("jwtToken");
|
|
||||||
localStorage.removeItem("refreshToken");
|
|
||||||
localStorage.removeItem("ctnt");
|
|
||||||
localStorage.clear();
|
|
||||||
window.location.href = "/auth/login";
|
|
||||||
if (onSuccessCallBack) onSuccessCallBack();
|
|
||||||
},
|
|
||||||
|
|
||||||
onError: (error) => {
|
|
||||||
showToast(error.message || "Error while creating project", "error");
|
|
||||||
localStorage.removeItem("jwtToken");
|
|
||||||
localStorage.removeItem("refreshToken")
|
|
||||||
localStorage.removeItem("ctnt")
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@ -21,7 +21,6 @@ const SwitchTenant = () => {
|
|||||||
queryKey: ["profile"],
|
queryKey: ["profile"],
|
||||||
queryFn: () => AuthRepository.profile(),
|
queryFn: () => AuthRepository.profile(),
|
||||||
});
|
});
|
||||||
window.location.reload();
|
|
||||||
});
|
});
|
||||||
const currentTenant = localStorage.getItem("ctnt");
|
const currentTenant = localStorage.getItem("ctnt");
|
||||||
const handleTenantselection = (tenantId) => {
|
const handleTenantselection = (tenantId) => {
|
||||||
@ -84,11 +83,11 @@ const SwitchTenant = () => {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<button
|
<button
|
||||||
className={` ${currentTenant === tenant.id ? "badge bg-label-primary w-50" :"btn btn-primary btn-sm mt-2 align-self-start" }`}
|
className="btn btn-primary btn-sm mt-2 align-self-start"
|
||||||
onClick={() => handleTenantselection(tenant?.id)}
|
onClick={() => handleTenantselection(tenant?.id)}
|
||||||
disabled={isPending && pendingTenant === tenant.id || currentTenant === tenant.id }
|
disabled={isPending && pendingTenant === tenant.id || currentTenant === tenant.id }
|
||||||
>
|
>
|
||||||
{currentTenant === tenant.id ? "Active Tenant" :isPending && pendingTenant === tenant.id
|
{isPending && pendingTenant === tenant.id
|
||||||
? "Please Wait.."
|
? "Please Wait.."
|
||||||
: "Go To Dashboard"}
|
: "Go To Dashboard"}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useTenants, useSelectTenant, useLogout } from "../../hooks/useAuth.jsx";
|
import { useTenants, useSelectTenant } from "../../hooks/useAuth.jsx";
|
||||||
import { Link, useNavigate } from "react-router-dom";
|
import { Link, useNavigate } from "react-router-dom";
|
||||||
import Dashboard from "../../components/Dashboard/Dashboard.jsx";
|
import Dashboard from "../../components/Dashboard/Dashboard.jsx";
|
||||||
import Loader from "../../components/common/Loader.jsx";
|
import Loader from "../../components/common/Loader.jsx";
|
||||||
@ -17,15 +17,12 @@ const TenantSelectionPage = () => {
|
|||||||
localStorage.setItem("ctnt", tenantId);
|
localStorage.setItem("ctnt", tenantId);
|
||||||
chooseTenant(tenantId);
|
chooseTenant(tenantId);
|
||||||
};
|
};
|
||||||
|
|
||||||
const {mutate:handleLogout,isPending:isLogouting} = useLogout(()=>{})
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
// useEffect(() => {
|
if (localStorage.getItem("ctnt")) {
|
||||||
// if (localStorage.getItem("ctnt")) {
|
navigate("/dashboard");
|
||||||
// navigate("/dashboard");
|
}
|
||||||
// }
|
}, [navigate]);
|
||||||
// }, [navigate]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isLoading && data?.data?.length === 1) {
|
if (!isLoading && data?.data?.length === 1) {
|
||||||
@ -50,7 +47,7 @@ const TenantSelectionPage = () => {
|
|||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container-fluid">
|
<div className="container-fluid bg-primary">
|
||||||
{/* Logo */}
|
{/* Logo */}
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
<img
|
<img
|
||||||
@ -67,10 +64,6 @@ const TenantSelectionPage = () => {
|
|||||||
<p className="fs-6 fs-md-5">
|
<p className="fs-6 fs-md-5">
|
||||||
Please select which dashboard you want to explore!!!
|
Please select which dashboard you want to explore!!!
|
||||||
</p>
|
</p>
|
||||||
<div onClick={()=>handleLogout()}>
|
|
||||||
{isLogouting ? "Please Wait...":<span className="fs-6 fw-semibold cursor-pointer text-decoration-underline"><i className='bx bx-log-out'></i>SignOut</span>}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Card Section */}
|
{/* Card Section */}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user