Skip to content

Commit

Permalink
Feature/#325 로그아웃시 메인페이지로 이동 (#326)
Browse files Browse the repository at this point in the history
* feat: 로그아웃 핸들러 함수로 구현

#325

* feat: 로그아웃 버튼 클릭시 메인페이지로 이동하도록 로직 추가

#325
  • Loading branch information
llddang authored Sep 27, 2024
1 parent 5a00b4a commit f062acd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/components/Sidebar/SidebarContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { Avatar, Button, Flex, IconButton, Text } from '@chakra-ui/react';
import { useSetAtom } from 'jotai';
import { useRouter } from 'next/navigation';
import { useEffect, useState } from 'react';
import { BiBell, BiUser } from 'react-icons/bi';
import { BsPlus, BsGrid } from 'react-icons/bs';
Expand All @@ -18,11 +19,20 @@ import { SidebarContentProps, SidebarTeam } from '../type';

const SidebarContent = ({ isOpen, setIsOpen }: SidebarContentProps) => {
const [isTeamModalOpen, setIsTeamModalOpen] = useState<boolean>(false);

const user = useGetUser();
const setUser = useSetAtom(userAtom);
const setMyTeams = useSetAtom(myTeamAtom);

const router = useRouter();

const { data: sidebarInfo } = useGetSideBarInfoQuery();

const handleLogOutButtonClick = () => {
setUser(defaultUserAtom);
router.push('/');
};

useEffect(() => {
const myTeams = sidebarInfo?.body.myTeamsAndStudies
? sidebarInfo.body.myTeamsAndStudies.map((team: { teamId: number }) => team.teamId)
Expand Down Expand Up @@ -67,7 +77,7 @@ const SidebarContent = ({ isOpen, setIsOpen }: SidebarContentProps) => {
<Flex direction={isOpen ? 'row' : 'column'} gap="4">
<SidebarIconButton icon={<BiBell />} onClick={() => {}} />
<SidebarIconButton icon={<BiUser />} onClick={() => {}} />
<SidebarIconButton icon={<MdOutlineLogout />} onClick={() => setUser(defaultUserAtom)} />
<SidebarIconButton icon={<MdOutlineLogout />} onClick={handleLogOutButtonClick} />
</Flex>
</Flex>
{isOpen && user?.isLogin && (
Expand Down

0 comments on commit f062acd

Please sign in to comment.