-
Notifications
You must be signed in to change notification settings - Fork 3
Fix/146/gathering detail #149
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
Changes from 14 commits
09d1a34
7fa546b
b4b5770
e3662c1
0fd0de8
6c21c51
b594996
ff71c77
84ffc6b
267b354
695da8d
943b93c
ea96284
a882bc7
f356715
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,16 +2,24 @@ | |
|
|
||
| import { useRouter } from 'next/navigation'; | ||
| import { useDisclosure } from '@mantine/hooks'; | ||
| import { useGetCrewDetailQuery } from '@/src/_queries/crew/crew-detail-queries'; | ||
| import { useGetGatheringListQuery } from '@/src/_queries/crew/gathering-list-queries'; | ||
| import { useAuth } from '@/src/hooks/use-auth'; | ||
| import CreateGatheringModalContainer from '@/src/app/(crew)/crew/detail/[id]/_components/create-gathering/create-gathering-modal/container'; | ||
| import Button from '@/src/components/common/input/button'; | ||
| import { CrewDetail } from '@/src/types/crew-card'; | ||
| import { CreateGatheringFormTypes } from '@/src/types/gathering-data'; | ||
|
|
||
| export default function CreateGathering({ crewId }: { crewId: number }) { | ||
| const { isAuth } = useAuth(); | ||
| const router = useRouter(); | ||
| const [opened, { open, close }] = useDisclosure(false); | ||
|
|
||
| const { data: gatheringList, isLoading, error, refetch } = useGetGatheringListQuery(crewId); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ก Codebase verification ๋ชจ์ ์์ฑ ํ refetch๊ฐ ํธ์ถ๋์ง ์๋ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ํ์ฌ ์ฝ๋์์ ๋ชจ์์ด ์์ฑ๋ ํ
๐ Analysis chainrefetch ํจ์์ ์ฌ์ฉ์ฑ ๊ฒ์ฆ์ด ํ์ํฉ๋๋ค.
๐ Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check if refetch is called after gathering creation
ast-grep --pattern 'CreateGatheringModalContainer {
$$$
onSuccess={() => {
$$$
refetch();
$$$
}}
$$$
}'
Length of output: 125 Script: #!/bin/bash
# Search for CreateGatheringModalContainer component and its usage
rg "CreateGatheringModalContainer" -A 10
# Search for any usage of refetch in the file
rg "refetch" "src/app/(crew)/crew/detail/[id]/_components/create-gathering/index.tsx" -A 5
Length of output: 5526 Script: #!/bin/bash
# Search for the container component implementation to check mutation handling
rg -A 20 "useCreateGatheringQuery" "src/app/(crew)/crew/detail/[id]/_components/create-gathering/create-gathering-modal/container.tsx"
# Search for any onSuccess handlers in the modal container
rg "onSuccess" "src/app/(crew)/crew/detail/[id]/_components/create-gathering/create-gathering-modal/container.tsx" -A 5
Length of output: 1366 |
||
|
|
||
| // totalGatheringCount ์ถ์ถ | ||
| const totalGatheringCount = gatheringList?.length ?? 0; | ||
|
Comment on lines
+18
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ ๏ธ Refactor suggestion ๋ก๋ฉ ๋ฐ ์๋ฌ ์ํ ์ฒ๋ฆฌ ๊ฐ์ ์ด ํ์ํฉ๋๋ค. ํ์ฌ const { data: gatheringList, isLoading, error, refetch } = useGetGatheringListQuery(crewId);
const totalGatheringCount = gatheringList?.length ?? 0;
+ if (error) {
+ return <div>๋ฐ์ดํฐ๋ฅผ ๋ถ๋ฌ์ค๋ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค.</div>;
+ }
+
+ if (isLoading) {
+ return <div>๋ก๋ฉ ์ค...</div>;
+ }
|
||
|
|
||
| const handleButtonClick = () => { | ||
| if (isAuth) { | ||
| open(); // ๋ก๊ทธ์ธ ์ํ์ผ ๊ฒฝ์ฐ ๋ชจ๋ฌ ์ด๊ธฐ | ||
|
|
@@ -30,7 +38,13 @@ export default function CreateGathering({ crewId }: { crewId: number }) { | |
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="flex items-center justify-between px-3 md:px-7 lg:px-11"> | ||
| <div className="flex items-end space-x-2"> | ||
| <h2 className="text-2xl font-semibold text-gray-800">์ฝ์ ์ก๊ธฐ</h2> | ||
| <span className="text-base font-semibold text-blue-500"> | ||
| ํ์ฌ {totalGatheringCount}๊ฐ์ ์ฝ์์ด ๊ฐ์ค๋์ด ์์ต๋๋ค. | ||
| </span> | ||
| </div> | ||
| <Button type="button" className="btn-filled px-4" onClick={handleButtonClick}> | ||
| ์ฝ์ ๋ง๋ค๊ธฐ | ||
| </Button> | ||
|
|
@@ -40,6 +54,6 @@ export default function CreateGathering({ crewId }: { crewId: number }) { | |
| close={close} | ||
| data={initialValue} | ||
| /> | ||
| </> | ||
| </div> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useEffect, useState } from 'react'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { toast } from 'react-toastify'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useRouter } from 'next/navigation'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { Loader } from '@mantine/core'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useDisclosure } from '@mantine/hooks'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { cancelCrew, joinCrew, leaveCrew } from '@/src/_apis/crew/crew-detail-apis'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { useUser } from '@/src/_queries/auth/user-queries'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -20,6 +21,7 @@ export default function DetailCrew({ id }: DetailCrewContainerProps) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [isCaptain, setIsCaptain] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [isMember, setIsMember] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [isJoining, setIsJoining] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [isConfirmed, setIsConfirmed] = useState(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [confirmCancelOpened, { open: openConfirmCancel, close: closeConfirmCancel }] = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useDisclosure(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const router = useRouter(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -35,12 +37,20 @@ export default function DetailCrew({ id }: DetailCrewContainerProps) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { data, isLoading, error: fetchError, refetch } = useGetCrewDetailQuery(id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentUserId && data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const captain = data.crewMembers.find((member) => member.captain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const memberExists = data.crewMembers.some((member) => member.id === currentUserId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // confirmed ์ํ ๊ณ์ฐ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (data.participantCount !== undefined && data.totalCount !== undefined) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setIsConfirmed(data.participantCount === data.totalCount); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Captain ๋ฐ ๋ฉค๋ฒ ์ฌ๋ถ ํ์ธ (currentUserId ํ์) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (currentUserId) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const captain = data.crewMembers.find((member) => member.captain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const memberExists = data.crewMembers.some((member) => member.id === currentUserId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setIsCaptain(captain?.id === currentUserId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setIsMember(memberExists); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setIsCaptain(captain?.id === currentUserId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setIsMember(memberExists); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+40
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ๐ ๏ธ Refactor suggestion ๋ฐ์ดํฐ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ๊ฐํํด ์ฃผ์ธ์. ํ์ฌ ๊ตฌํ์์ ๋ช ๊ฐ์ง ๊ฐ์ ์ด ํ์ํ ๋ถ๋ถ์ด ์์ต๋๋ค:
๋ค์๊ณผ ๊ฐ์ด ๊ฐ์ ํด ๋ณด์ธ์: useEffect(() => {
if (data) {
- if (data.participantCount !== undefined && data.totalCount !== undefined) {
+ const participantCount = data.participantCount ?? 0;
+ const totalCount = data.totalCount ?? 0;
- setIsConfirmed(data.participantCount === data.totalCount);
+ setIsConfirmed(participantCount === totalCount);
- }
if (currentUserId) {
+ const crewMembers = data.crewMembers ?? [];
- const captain = data.crewMembers.find((member) => member.captain);
+ const captain = crewMembers.find((member) => member.captain);
- const memberExists = data.crewMembers.some((member) => member.id === currentUserId);
+ const memberExists = crewMembers.some((member) => member.id === currentUserId);
setIsCaptain(captain?.id === currentUserId);
setIsMember(memberExists);
}
}
}, [currentUserId, data]);๐ Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [currentUserId, data]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -88,7 +98,7 @@ export default function DetailCrew({ id }: DetailCrewContainerProps) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.success('ํฌ๋ฃจ๊ฐ ์ฑ๊ณต์ ์ผ๋ก ์ญ์ ๋์์ต๋๋ค.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| router.push('/'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (deleteError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.error('ํฌ๋ฃจ ์ญ์ ์ค ์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| toast.error('๐ซ ํฌ๋ฃจ ์ญ์ ์ค ์๋ฌ๊ฐ ๋ฐ์ํ์ต๋๋ค.'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -106,9 +116,10 @@ export default function DetailCrew({ id }: DetailCrewContainerProps) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO: ๋ก๋ฉ, ์๋ฌ์ฒ๋ฆฌ ์ถํ ๊ฐ์ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isLoading) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <p>Loading...</p>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <Loader />; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO: ์ถํ 404ํ์ด์ง๋ก ์ด๋์ํค๊ธฐ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (fetchError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (fetchError instanceof ApiError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -118,7 +129,7 @@ export default function DetailCrew({ id }: DetailCrewContainerProps) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <p>ํฌ๋ฃจ ์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค</p>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (parseError) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <p>{`Error ${fetchError.status}: ${fetchError.message}`}</p>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <p>{`Error ${fetchError.message}`}</p>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return <p>๋ฐ์ดํฐ ํต์ ์ ์คํจํ์ต๋๋ค.</p>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -135,6 +146,7 @@ export default function DetailCrew({ id }: DetailCrewContainerProps) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isCaptain={isCaptain} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isMember={isMember} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isJoining={isJoining} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isConfirmed={isConfirmed} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleJoinClick={handleJoinClick} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleLeaveCrew={handleLeaveCrew} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handleDelete={handleDelete} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐ก Codebase verification
์ฉ์ด ํต์ผ์ด ํ์ํ ๋ถ๋ถ์ด ํ์ธ๋์์ต๋๋ค.
๊ฒ์ ๊ฒฐ๊ณผ๋ฅผ ํตํด ๋ค์๊ณผ ๊ฐ์ ๋ถ์ผ์น ์ฌํญ์ด ๋ฐ๊ฒฌ๋์์ต๋๋ค:
src/app/(crew)/crew/create/_components/create-crew-form/index.tsxsrc/app/(crew)/crew/detail/[id]/_components/create-gathering/create-gathering-form/index.tsxํฌ๋ฃจ์ ๋ชจ์์ ์๋ก ๋ค๋ฅธ ๊ฐ๋ ์ด๋ฏ๋ก, ๊ฐ๊ฐ์ ์ปจํ ์คํธ์ ๋ง๋ ์ฉ์ด๋ฅผ ์ฌ์ฉํ๋ ์ผ๊ด์ฑ ์๊ฒ ์ ์ฉํ๋ ๊ฒ์ด ์ข๊ฒ ์ต๋๋ค:
๐ Analysis chain
์ฉ์ด ๋ณ๊ฒฝ์ด ์ผ๊ด์ฑ ์๊ฒ ์ ์ฉ๋์๋์ง ํ์ธ์ด ํ์ํฉ๋๋ค.
๋ผ๋ฒจ๊ณผ ์๋ฌ ๋ฉ์์ง์ ์ฉ์ด๊ฐ "๋ชจ์ง ์ ์"์์ "ํฌ๋ฃจ ์ต๋ ์ธ์"์ผ๋ก ๋ณ๊ฒฝ๋์์ต๋๋ค. ์ด๋ PR์ ๋ชฉ์ ์ ๋ถํฉํ๋ ๋ณ๊ฒฝ์ฌํญ์ด์ง๋ง, ๋ค์ ์ฌํญ๋ค์ ํ์ธํด์ฃผ์๊ธฐ ๋ฐ๋๋๋ค:
Also applies to: 296-296
๐ Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 744