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 ( <>