-
Notifications
You must be signed in to change notification settings - Fork 3
[refactor] AdminClubContext를 Zustand store로 마이그레이션 #1412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seongwon030
wants to merge
7
commits into
develop-fe
Choose a base branch
from
feature/#1403-admin-club-context-zustand-migration-MOA-799
base: develop-fe
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b8849f2
feat(store): useAdminClubStore, useApplicantSSE 추가
seongwon030 303d7a7
refactor(admin): AdminClubContext를 Zustand store로 마이그레이션
seongwon030 5c1fada
docs: 상태관리부서 추가
seongwon030 58b548b
docs: 실시간 이벤트 내용 변경
seongwon030 cf1eade
fix(hooks): applicationFormId 변경 시 applicantsData 초기화
seongwon030 90f9672
refactor(store): hasConsented를 Zustand에서 로컬 useState로 이동
seongwon030 6d6dc49
docs: 커밋 전 format
seongwon030 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # useAdminClubStore — 어드민 전역 상태 관리 | ||
|
|
||
| `AdminClubContext`를 Zustand로 마이그레이션하여 SSE 업데이트로 인한 불필요한 리렌더링을 제거한 store. | ||
|
|
||
| ## 배경 | ||
|
|
||
| 기존 `AdminClubContext`에는 4개 상태가 묶여 있었다: | ||
| - `clubId` — 로그인한 관리자의 클럽 ID | ||
| - `hasConsented` — 개인정보 동의 여부 | ||
| - `applicantsData` — SSE로 실시간 업데이트되는 지원자 데이터 | ||
| - `applicationFormId` — SSE 연결 트리거용 ID | ||
|
|
||
| `applicantsData`가 SSE 이벤트마다 변경되면서 Context를 구독하는 9개 컴포넌트 전부가 리렌더링되었다. `applicantsData`의 실제 소비자는 `ApplicantsTab` 하나뿐이었기 때문에 나머지 8개 컴포넌트의 리렌더링은 불필요했다. | ||
|
|
||
| ## 구조 | ||
|
|
||
| ``` | ||
| src/store/useAdminClubStore.ts — clubId, hasConsented (전역 공유 필요) | ||
| src/hooks/useApplicantSSE.ts — applicantsData + SSE 연결 (ApplicantsTab 스코프) | ||
| ``` | ||
|
|
||
| `applicationFormId`는 store에 포함하지 않는다. SSE 훅의 인자로 직접 전달한다. | ||
|
|
||
| ## Selector 훅 | ||
|
|
||
| ```typescript | ||
| import { useAdminClubId } from '@/store/useAdminClubStore'; | ||
| import { useAdminHasConsented } from '@/store/useAdminClubStore'; | ||
|
|
||
| const { clubId, setClubId } = useAdminClubId(); | ||
| const { hasConsented, setHasConsented } = useAdminHasConsented(); | ||
| ``` | ||
|
|
||
| 각 selector 훅은 해당 상태만 구독하므로, 다른 상태가 변경되어도 리렌더링이 발생하지 않는다. | ||
|
|
||
| ## useApplicantSSE | ||
|
|
||
| ```typescript | ||
| import { useApplicantSSE } from '@/hooks/useApplicantSSE'; | ||
|
|
||
| const { applicantsData, setApplicantsData } = useApplicantSSE(applicationFormId); | ||
| ``` | ||
|
|
||
| - `applicationFormId`가 변경되면 SSE 연결을 재수립한다 | ||
| - 컴포넌트 언마운트 시 SSE 연결을 자동으로 닫는다 | ||
| - 에러 발생 시 2초 후 자동 재연결한다 | ||
| - `setApplicantsData`로 초기 데이터(`useGetApplicants` 결과)를 주입할 수 있다 | ||
|
|
||
| ## 관련 코드 | ||
|
|
||
| - `src/store/useAdminClubStore.ts` — Zustand store 정의 | ||
| - `src/hooks/useApplicantSSE.ts` — SSE 연결 관리 및 applicantsData 상태 | ||
| - `src/apis/clubSSE.ts` — EventSource 생성 유틸 | ||
| - `src/pages/AdminPage/tabs/ApplicantsTab/ApplicantsTab.tsx` — useApplicantSSE 사용처 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 3 additions & 9 deletions
12
frontend/src/pages/AdminPage/auth/PrivateRoute/PrivateRoute.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.