From cbd38eadc22468fbe76039caf87e6ca53ac742de Mon Sep 17 00:00:00 2001 From: LeeJongBeom <52884648+devleejb@users.noreply.github.com> Date: Fri, 19 Jan 2024 16:46:28 +0900 Subject: [PATCH] Add logout logic (#71) --- .../src/components/common/ProfilePopover.tsx | 46 +++++++++++++++++++ .../components/drawers/WorkspaceDrawer.tsx | 23 +++++++++- 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 frontend/src/components/common/ProfilePopover.tsx diff --git a/frontend/src/components/common/ProfilePopover.tsx b/frontend/src/components/common/ProfilePopover.tsx new file mode 100644 index 00000000..7b22f215 --- /dev/null +++ b/frontend/src/components/common/ProfilePopover.tsx @@ -0,0 +1,46 @@ +import { + ListItemIcon, + ListItemText, + MenuItem, + MenuList, + Popover, + PopoverProps, +} from "@mui/material"; +import LogoutIcon from "@mui/icons-material/Logout"; +import { useDispatch } from "react-redux"; +import { setAccessToken } from "../../store/authSlice"; +import { setUserData } from "../../store/userSlice"; + +function ProfilePopover(props: PopoverProps) { + const dispatch = useDispatch(); + + const handleLogout = () => { + dispatch(setAccessToken(null)); + dispatch(setUserData(null)); + }; + + return ( + + + + + + + Logout + + + + ); +} + +export default ProfilePopover; diff --git a/frontend/src/components/drawers/WorkspaceDrawer.tsx b/frontend/src/components/drawers/WorkspaceDrawer.tsx index f4a0d589..b9e90845 100644 --- a/frontend/src/components/drawers/WorkspaceDrawer.tsx +++ b/frontend/src/components/drawers/WorkspaceDrawer.tsx @@ -6,15 +6,28 @@ import { ListItem, ListItemAvatar, ListItemButton, + ListItemSecondaryAction, ListItemText, } from "@mui/material"; +import MoreVertIcon from "@mui/icons-material/MoreVert"; import { useSelector } from "react-redux"; import { selectUser } from "../../store/userSlice"; +import { MouseEventHandler, useState } from "react"; +import ProfilePopover from "../common/ProfilePopover"; const DRAWER_WIDTH = 240; function WorkspaceDrawer() { const userStore = useSelector(selectUser); + const [profileAnchorEl, setProfileAnchorEl] = useState<(EventTarget & Element) | null>(null); + + const handleOpenProfilePopover: MouseEventHandler = (event) => { + setProfileAnchorEl(event.currentTarget); + }; + + const handleCloseProfilePopover = () => { + setProfileAnchorEl(null); + }; return ( - + {userStore.data?.nickname.charAt(0)} + + + +