From 934f6ff101b15f910d474475289595117d8c754c Mon Sep 17 00:00:00 2001 From: llddang Date: Sun, 22 Sep 2024 16:28:36 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EC=82=AC=EC=9D=B4=EB=93=9C?= =?UTF-8?q?=EB=B0=94=EC=97=90=EC=84=9C=20=ED=8C=80=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=EC=8B=9C=20myTeamAtom=EC=9C=BC=EB=A1=9C=20=EC=83=81=ED=83=9C?= =?UTF-8?q?=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #304 --- src/components/Sidebar/SidebarContent/index.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/Sidebar/SidebarContent/index.tsx b/src/components/Sidebar/SidebarContent/index.tsx index 2e6a6d8..a5b0983 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 + ? sidebarInfo.body.myTeamsAndStudies.map((team: { teamId: number }) => team.teamId) + : []; + setMyTeams(myTeams); + }, [setMyTeams, sidebarInfo]); + return ( <> From 49fb13e1c1d8c7d0e3f71a66a919d51466bf37ed Mon Sep 17 00:00:00 2001 From: llddang Date: Sun, 22 Sep 2024 16:28:53 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20myTeamAtom=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #304 --- src/app/team/[teamId]/page.tsx | 4 ++-- src/atom.ts | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/app/team/[teamId]/page.tsx b/src/app/team/[teamId]/page.tsx index 4c123ae..6b177a5 100644 --- a/src/app/team/[teamId]/page.tsx +++ b/src/app/team/[teamId]/page.tsx @@ -145,8 +145,8 @@ const Page = ({ params }: { params: { teamId: number } }) => { const myTeam = useAtomValue(myTeamAtom); 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', '/'); From 7582abe7274609769ea54db79b094593eb065796 Mon Sep 17 00:00:00 2001 From: llddang Date: Fri, 27 Sep 2024 21:37:54 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=EB=B9=84=ED=9A=8C=EC=9B=90=EC=9D=BC?= =?UTF-8?q?=20=EB=95=8C=20=EC=A0=95=EB=B3=B4=EA=B0=80=20=EC=97=86=EC=96=B4?= =?UTF-8?q?=EC=84=9C=20=EC=83=9D=EA=B8=B0=EB=8A=94=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #304 --- src/components/Sidebar/SidebarContent/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Sidebar/SidebarContent/index.tsx b/src/components/Sidebar/SidebarContent/index.tsx index a5b0983..3e3aca3 100644 --- a/src/components/Sidebar/SidebarContent/index.tsx +++ b/src/components/Sidebar/SidebarContent/index.tsx @@ -24,7 +24,7 @@ const SidebarContent = ({ isOpen, setIsOpen }: SidebarContentProps) => { const { data: sidebarInfo } = useGetSideBarInfoQuery(); useEffect(() => { - const myTeams = sidebarInfo + const myTeams = sidebarInfo?.body.myTeamsAndStudies ? sidebarInfo.body.myTeamsAndStudies.map((team: { teamId: number }) => team.teamId) : []; setMyTeams(myTeams);