Skip to content

Commit

Permalink
refactor: api.logout() -> useResetUserInfo() (#230)
Browse files Browse the repository at this point in the history
* feat: 로그아웃 기능 추가 (ProfileDropdownMenu)

* feat: 로그아웃 기능 추가 (LogoutModal)
  • Loading branch information
nijuy authored Jun 23, 2024
1 parent b51df88 commit ec959f0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
17 changes: 15 additions & 2 deletions src/components/ProfileDropdownMenu/ProfileDropdownMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as DropdownMenu from '@radix-ui/react-dropdown-menu';
import { Link } from 'react-router-dom';
import { Link, useNavigate } from 'react-router-dom';

import { useResetUserInfo } from '@/hooks/useResetUserInfo';

import {
StyledProfileDropdownContent,
Expand All @@ -23,6 +25,15 @@ export const ProfileDropdownMenu = ({
email,
children,
}: ProfileDropdownMenuProps) => {
const navigate = useNavigate();
const resetUserInfo = useResetUserInfo();

const handleLogout = () => {
resetUserInfo();
alert('로그아웃 되었습니다.');
navigate(0);
};

return (
<DropdownMenu.Root open={open} onOpenChange={onOpenChange}>
{children}
Expand All @@ -36,7 +47,9 @@ export const ProfileDropdownMenu = ({
<Link to="/mypage">마이페이지</Link>
</StyledProfileDropdownItem>
<StyledProfileDropdownItem asChild>
<button type="button">로그아웃</button>
<button type="button" onClick={handleLogout}>
로그아웃
</button>
</StyledProfileDropdownItem>
</StyledProfileDropdownContent>
</DropdownMenu.Portal>
Expand Down
5 changes: 3 additions & 2 deletions src/home/components/Dialog/LogoutModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BoxButton } from '@yourssu/design-system-react';
import { useNavigate } from 'react-router-dom';

import PpussungIcon from '@/assets/home/ppussung.svg';
import { api } from '@/service/TokenService';
import { useResetUserInfo } from '@/hooks/useResetUserInfo';

import {
StyledButtonContainer,
Expand All @@ -21,9 +21,10 @@ interface LogoutModalProps {

export const LogoutModal = ({ open, onOpenChange }: LogoutModalProps) => {
const navigate = useNavigate();
const resetUserInfo = useResetUserInfo();

const handleLogout = () => {
api.logout();
resetUserInfo();
alert('로그아웃 되었습니다.');
navigate('/');
};
Expand Down
7 changes: 0 additions & 7 deletions src/home/components/Nav/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ export const Nav = () => {
const isLoggedIn = useRecoilValue(LogInState);
const theme = useTheme();

// Todo: 로그아웃 기능 추가 (ProfileDropdownMenu)
// const handleLogout = () => {
// sessionStorage.removeItem('accessExpiredIn');
// api.logout();
// return;
// };

return (
<StyledContainer>
{isLoggedIn ? (
Expand Down

0 comments on commit ec959f0

Please sign in to comment.