"use client"; import React from "react"; import { Menu, MenuItem, IconButton, ListItemIcon, Typography, Button, CircularProgress, } from "@mui/material"; import AccountCircleIcon from "@mui/icons-material/AccountCircle"; import SettingsIcon from "@mui/icons-material/Settings"; import LogoutIcon from "@mui/icons-material/Logout"; import { useDispatch, useSelector } from "react-redux"; import { selectIsLoggedIn, selectStatus } from "@/app/redux/auth/selectors"; import { logout } from "@/app/redux/auth/authSlice"; import { AppDispatch } from "@/app/redux/types"; import { useRouter } from "next/navigation"; export default function AccountMenu() { const [anchorEl, setAnchorEl] = React.useState(null); const open = Boolean(anchorEl); const handleClick = (event: React.MouseEvent) => { setAnchorEl(event.currentTarget); }; const handleClose = () => { setAnchorEl(null); }; const dispatch = useDispatch(); const router = useRouter(); const handleGoToSettings = () => { router.push("/dashboard/settings"); handleClose(); }; // Select relevant state from your auth slice const isLoggedIn = useSelector(selectIsLoggedIn); const authStatus = useSelector(selectStatus); // Determine if we're currently in the process of logging out const isLoggingOut = authStatus === "loading"; const handleLogout = async () => { // Dispatch the logout thunk - redirection will be handled by the epic await dispatch(logout()); }; // Only show the logout button if the user is logged in if (!isLoggedIn) { return null; } return ( <> Account Settings ); }