From 3f8c00ca5870dd11ba453055f9ac8048e7b69609 Mon Sep 17 00:00:00 2001 From: llddang <77055208+llddang@users.noreply.github.com> Date: Fri, 27 Sep 2024 21:47:14 +0900 Subject: [PATCH] =?UTF-8?q?Feature/#304=20=ED=8C=80=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EA=B6=8C=ED=95=9C=20=EC=88=98=EC=A0=95=20(#306)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 사이드바에서 팀 조회시 myTeamAtom으로 상태 저장 #304 * feat: myTeamAtom 구조 수정 #304 * fix: 비회원일 때 정보가 없어서 생기는 에러 해결 #304 --- src/app/team/[teamId]/page.tsx | 4 ++-- src/atom.ts | 4 +--- src/components/Sidebar/SidebarContent/index.tsx | 12 ++++++++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/app/team/[teamId]/page.tsx b/src/app/team/[teamId]/page.tsx index a3e9719..5561150 100644 --- a/src/app/team/[teamId]/page.tsx +++ b/src/app/team/[teamId]/page.tsx @@ -146,8 +146,8 @@ const Page = ({ params }: { params: { teamId: number } }) => { const [isMyTeam, setIsMyTeam] = useState(false); useEffect(() => { - if (myTeam.teams !== undefined) { - const res = myTeam.teams.filter((teamId) => teamId === params.teamId); + if (myTeam !== undefined) { + const res = myTeam.filter((teamId) => teamId === Number(params.teamId)); setIsMyTeam(res.length === 1); } }, [myTeam, params.teamId]); diff --git a/src/atom.ts b/src/atom.ts index 189d724..8dab594 100644 --- a/src/atom.ts +++ b/src/atom.ts @@ -15,8 +15,6 @@ export const defaultUserAtom = { export const userAtom = atomWithStorage('user', defaultUserAtom as UserAtomType); -export const myTeamAtom = atomWithStorage<{ teams: number[] }>('myTeam', { - teams: [], -}); +export const myTeamAtom = atomWithStorage('myTeam', []); export const loginBackPathAtom = atomWithStorage('loginBackPath', '/'); diff --git a/src/components/Sidebar/SidebarContent/index.tsx b/src/components/Sidebar/SidebarContent/index.tsx index 2e6a6d8..3e3aca3 100644 --- a/src/components/Sidebar/SidebarContent/index.tsx +++ b/src/components/Sidebar/SidebarContent/index.tsx @@ -2,13 +2,13 @@ import { Avatar, Button, Flex, IconButton, Text } from '@chakra-ui/react'; import { useSetAtom } from 'jotai'; -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import { BiBell, BiUser } from 'react-icons/bi'; import { BsPlus, BsGrid } from 'react-icons/bs'; import { MdOutlineLogout } from 'react-icons/md'; import { useGetSideBarInfoQuery } from '@/app/api/member'; -import { defaultUserAtom, userAtom } from '@/atom'; +import { defaultUserAtom, myTeamAtom, userAtom } from '@/atom'; import TeamModal from '@/containers/team/TeamModal'; import useGetUser from '@/hooks/useGetUser'; @@ -20,8 +20,16 @@ const SidebarContent = ({ isOpen, setIsOpen }: SidebarContentProps) => { const [isTeamModalOpen, setIsTeamModalOpen] = useState(false); const user = useGetUser(); const setUser = useSetAtom(userAtom); + const setMyTeams = useSetAtom(myTeamAtom); const { data: sidebarInfo } = useGetSideBarInfoQuery(); + useEffect(() => { + const myTeams = sidebarInfo?.body.myTeamsAndStudies + ? sidebarInfo.body.myTeamsAndStudies.map((team: { teamId: number }) => team.teamId) + : []; + setMyTeams(myTeams); + }, [setMyTeams, sidebarInfo]); + return ( <>