Skip to content

Commit 56d14f5

Browse files
committed
feat: TeamId 전역 상태로 관리
1 parent 05df437 commit 56d14f5

File tree

8 files changed

+67
-52
lines changed

8 files changed

+67
-52
lines changed

src/page/archiving/index/ArchivingPage.tsx

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ import { useInteractTimeline } from '@/page/archiving/index/hook/common/useInter
1212
import { Block } from '@/page/archiving/index/type/blockType';
1313

1414
import ContentBox from '@/shared/component/ContentBox/ContentBox';
15-
import useTeamId from '@/shared/hook/common/useTeamId';
15+
import TeamProvider, { useTeamContext } from '@/shared/hook/common/useTeamContext';
1616
import { useDrawerAction } from '@/shared/store/drawer';
1717
import { useOpenModal } from '@/shared/store/modal';
1818

1919
const ArchivingPage = () => {
20-
const teamId = useTeamId();
2120
const { selectedBlock, handleBlockClick } = useInteractTimeline();
2221

2322
const openModal = useOpenModal();
@@ -43,30 +42,31 @@ const ArchivingPage = () => {
4342
const handleOpenBlockModal = () => {
4443
openModal('create-block');
4544
};
46-
4745
return (
48-
<DateProvider teamId={+teamId}>
49-
<Flex css={pageStyle}>
50-
<ContentBox
51-
variant="timeline"
52-
title="타임라인"
53-
headerOption={
54-
<Button variant="secondary" onClick={handleOpenBlockModal}>
55-
타임블록 추가
56-
</Button>
57-
}>
58-
<section css={timelineStyle}>
59-
<TimeLineHeader />
60-
<Flex css={contentStyle}>
61-
<Suspense>
62-
{/** fallback UI 디자인 나올 시에 TimeLine 크기만큼 채워서 Layout 안움직이도록 */}
63-
<TimeLine selectedBlock={finalSelectedBlock} onBlockClick={handleBlockClick} />
64-
</Suspense>
65-
</Flex>
66-
</section>
67-
</ContentBox>
68-
</Flex>
69-
</DateProvider>
46+
<TeamProvider>
47+
<DateProvider teamId={useTeamContext()}>
48+
<Flex css={pageStyle}>
49+
<ContentBox
50+
variant="timeline"
51+
title="타임라인"
52+
headerOption={
53+
<Button variant="secondary" onClick={handleOpenBlockModal}>
54+
타임블록 추가
55+
</Button>
56+
}>
57+
<section css={timelineStyle}>
58+
<TimeLineHeader />
59+
<Flex css={contentStyle}>
60+
<Suspense>
61+
{/** fallback UI 디자인 나올 시에 TimeLine 크기만큼 채워서 Layout 안움직이도록 */}
62+
<TimeLine selectedBlock={finalSelectedBlock} onBlockClick={handleBlockClick} />
63+
</Suspense>
64+
</Flex>
65+
</section>
66+
</ContentBox>
67+
</Flex>
68+
</DateProvider>
69+
</TeamProvider>
7070
);
7171
};
7272

src/page/archiving/index/DateProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const DateContext = createContext<DateContextProp>({} as DateContextProp);
2121
export const useDateContext = () => {
2222
const context = useContext(DateContext);
2323
if (!context) {
24-
throw new Error('Error from DateProvider');
24+
throw new Error('Error from DateContext');
2525
}
2626
return context;
2727
};

src/page/archiving/index/component/TimeBlockModal/component/Upload/UploadModal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { formatDatePost } from '@/page/archiving/index/component/TimeBlockModal/
1717
import { Files } from '@/shared/api/time-blocks/team/time-block/type';
1818
import WorkSapceInfo from '@/shared/component/WorkSpaceModal/info/WorkSpaceInfo';
1919
import { useBlockContext } from '@/shared/hook/common/useBlockContext';
20-
import useTeamId from '@/shared/hook/common/useTeamId';
20+
import { useTeamContext } from '@/shared/hook/common/useTeamContext';
2121
import { useCloseModal } from '@/shared/store/modal';
2222
import { useToastAction } from '@/shared/store/toast';
2323

@@ -26,7 +26,7 @@ interface UploadModalProps {
2626
}
2727

2828
const UploadModal = ({ isVisible }: UploadModalProps) => {
29-
const teamId = useTeamId();
29+
const teamId = useTeamContext();
3030

3131
const { formData, reset } = useBlockContext();
3232
const closeModal = useCloseModal();

src/page/archiving/index/component/TimeLine/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// TimeLine.tsx
12
import React from 'react';
23

34
import { useDateContext } from '@/page/archiving/index/DateProvider';
@@ -12,7 +13,7 @@ import { useGetTimeBlockQuery } from '@/page/archiving/index/hook/api/useGetTime
1213
import { Block } from '@/page/archiving/index/type/blockType';
1314
import { alignBlocks, createTimeBlock } from '@/page/archiving/index/util/block';
1415

15-
import useTeamId from '@/shared/hook/common/useTeamId';
16+
import { useTeamContext } from '@/shared/hook/common/useTeamContext';
1617
import { useDrawerIsOpen } from '@/shared/store/drawer';
1718

1819
interface TimeLineProps {
@@ -21,10 +22,10 @@ interface TimeLineProps {
2122
}
2223

2324
const TimeLine = ({ selectedBlock, onBlockClick }: TimeLineProps) => {
24-
const teamId = useTeamId();
25+
const teamId = useTeamContext();
2526
const { currentYear, currentMonth, endDay } = useDateContext();
2627

27-
const { data } = useGetTimeBlockQuery(+teamId, 'executive', currentYear, currentMonth);
28+
const { data } = useGetTimeBlockQuery(teamId, 'executive', currentYear, currentMonth);
2829

2930
const timeBlocks: Block[] = data.timeBlocks;
3031
const blockFloors = alignBlocks(timeBlocks, endDay, currentMonth, currentYear);

src/page/dashboard/.gitkeep

Whitespace-only changes.

src/page/dashboard/component/Timeline/TimelineSection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import { alignBlocks, createTimeBlock } from '@/page/archiving/index/util/block'
1212
import { timelineContentStyle } from '@/page/dashboard/component/Timeline/TimelineSection.style';
1313

1414
import { PATH } from '@/shared/constant/path';
15-
import useTeamId from '@/shared/hook/common/useTeamId';
15+
import { useTeamContext } from '@/shared/hook/common/useTeamContext';
1616

1717
const TimelineSection = () => {
1818
const navigate = useNavigate();
1919

20-
const teamId = useTeamId();
20+
const teamId = useTeamContext();
2121
const { currentYear, currentMonth, endDay } = useDate(+teamId);
2222

2323
const { data } = useGetTimeBlockQuery(+teamId, 'executive', currentYear, currentMonth);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ReactNode, createContext, useContext } from 'react';
2+
3+
import { useClubInfoQuery } from '@/shared/hook/api/useClubInfoQuery';
4+
5+
interface TeamProviderProp {
6+
children?: ReactNode;
7+
}
8+
9+
const TeamContext = createContext(Number(localStorage.getItem('teamId')));
10+
11+
export const useTeamContext = () => {
12+
const context = useContext(TeamContext);
13+
14+
if (context === undefined) {
15+
throw new Error('useTeamContext must be used within a TeamProvider');
16+
}
17+
18+
return context;
19+
};
20+
21+
const TeamProvider = ({ children }: TeamProviderProp) => {
22+
const { data } = useClubInfoQuery();
23+
const teamId = Number(localStorage.getItem('teamId')) || data?.belongTeamGetResponses?.[0]?.id;
24+
25+
if (!teamId) {
26+
console.error('teamId undefined');
27+
return;
28+
}
29+
30+
return <TeamContext.Provider value={teamId}>{children}</TeamContext.Provider>;
31+
};
32+
33+
export default TeamProvider;

src/shared/hook/common/useTeamId.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)