Add logout functionality to MenuBar component; clear localStorage and navigate to homepage on logout

This commit is contained in:
Vishnu 2025-05-13 10:41:39 +05:30
parent 4337bb9056
commit 34aa9b9dec
4 changed files with 19 additions and 5 deletions

View File

@ -1,12 +1,14 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { ArrowIcon } from "../../icons/ExportCommonIcons"; import { ArrowIcon } from "../../icons/ExportCommonIcons";
import { toggleTheme } from "../../../utils/theme"; import { toggleTheme } from "../../../utils/theme";
import { useNavigate } from "react-router-dom";
interface MenuBarProps { interface MenuBarProps {
setOpenMenu: (isOpen: boolean) => void; // Function to update menu state setOpenMenu: (isOpen: boolean) => void; // Function to update menu state
} }
const MenuBar: React.FC<MenuBarProps> = ({ setOpenMenu }) => { const MenuBar: React.FC<MenuBarProps> = ({ setOpenMenu }) => {
const navigate = useNavigate();
const [activeMenu, setActiveMenu] = useState<string | null>(null); const [activeMenu, setActiveMenu] = useState<string | null>(null);
const [activeSubMenu, setActiveSubMenu] = useState<string | null>(null); const [activeSubMenu, setActiveSubMenu] = useState<string | null>(null);
@ -23,13 +25,19 @@ const MenuBar: React.FC<MenuBarProps> = ({ setOpenMenu }) => {
})); }));
}; };
function handleThemeChange(){ function handleThemeChange() {
toggleTheme(); toggleTheme();
window.location.reload(); window.location.reload();
} }
const savedTheme: string | null = localStorage.getItem("theme") ?? "light"; const savedTheme: string | null = localStorage.getItem("theme") ?? "light";
const handleLogout = () => {
localStorage.clear(); // 1. Clear all localStorage
navigate('/'); // 2. Redirect to homepage
};
return ( return (
<div <div
className="menu-bar" className="menu-bar"
@ -539,6 +547,9 @@ const MenuBar: React.FC<MenuBarProps> = ({ setOpenMenu }) => {
</div> </div>
)} )}
</div> </div>
<div className="menu-button-container" onClick={handleLogout}>
<div className="menu-button">Log out</div>
</div>
</div> </div>
</div> </div>
); );

View File

@ -49,7 +49,7 @@ function MoveControls({
"Ctrl" | "Shift" | "Ctrl+Shift" | "" "Ctrl" | "Shift" | "Ctrl+Shift" | ""
>(""); >("");
const email = localStorage.getItem("email"); const email = localStorage.getItem("email");
const organization = email!.split("@")[1].split(".")[0]; const organization = email?.split("@")[1].split(".")[0] ?? null;
const updateBackend = ( const updateBackend = (
productName: string, productName: string,
@ -308,7 +308,7 @@ function MoveControls({
} }
); );
if (event) { if (event && organization) {
updateBackend( updateBackend(
selectedProduct.productName, selectedProduct.productName,
selectedProduct.productId, selectedProduct.productId,

View File

@ -22,7 +22,7 @@ function RotateControls({ rotatedObjects, setRotatedObjects, movedObjects, setMo
const itemsData = useRef<Types.FloorItems>([]); const itemsData = useRef<Types.FloorItems>([]);
const email = localStorage.getItem('email') const email = localStorage.getItem('email')
const organization = (email!.split("@")[1]).split(".")[0]; const organization = (email?.split("@")[1])?.split(".")[0] ?? null;
const updateBackend = ( const updateBackend = (
productName: string, productName: string,
@ -214,7 +214,7 @@ function RotateControls({ rotatedObjects, setRotatedObjects, movedObjects, setMo
rotation: [obj.rotation.x, obj.rotation.y, obj.rotation.z], rotation: [obj.rotation.x, obj.rotation.y, obj.rotation.z],
}) })
if (event) { if (event && organization) {
updateBackend( updateBackend(
selectedProduct.productName, selectedProduct.productName,
selectedProduct.productId, selectedProduct.productId,

View File

@ -1278,6 +1278,9 @@
} }
} }
.toggle-sidebar-ui-button { .toggle-sidebar-ui-button {
svg{
transform: scaleX(-1);
}
.tooltip { .tooltip {
right: 56px; right: 56px;
&::after { &::after {