-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/128/edit crew api 연결 #129
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 all commits
a4642fe
8a65520
5cde8ef
6f5118d
8cc9bd6
9b8b2f8
0776981
f96de45
25be7cf
c58777e
062362b
cbe2519
60b6c03
9616d8b
5313fd4
be51721
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,53 @@ | ||||||||
| import { useQuery } from '@tanstack/react-query'; | ||||||||
| import { toast } from 'react-toastify'; | ||||||||
| import { useRouter } from 'next/navigation'; | ||||||||
| import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; | ||||||||
| import { createCrew, editCrew } from '@/src/_apis/crew/crew'; | ||||||||
| import { getCrewDetail } from '@/src/_apis/crew/crew-detail-apis'; | ||||||||
| import { CreateCrewRequestTypes, EditCrewRequestTypes } from '@/src/types/create-crew'; | ||||||||
|
|
||||||||
| export function useGetCrewDetailQuery(id: number) { | ||||||||
| return useQuery({ | ||||||||
| queryKey: ['crewDetail', id], | ||||||||
| queryFn: () => getCrewDetail(id), | ||||||||
| }); | ||||||||
| } | ||||||||
|
|
||||||||
| export function useCreateCrewQuery() { | ||||||||
| const router = useRouter(); | ||||||||
| const queryClient = useQueryClient(); | ||||||||
|
|
||||||||
| return useMutation({ | ||||||||
| mutationFn: (data: CreateCrewRequestTypes) => createCrew(data), | ||||||||
| onSuccess: (data) => { | ||||||||
| if (data === null || data === undefined) { | ||||||||
| return; | ||||||||
| } | ||||||||
| queryClient.invalidateQueries({ queryKey: ['crewLists', 'crewDetail'] }); | ||||||||
|
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. 쿼리 무효화 시 올바른 사용법 적용
수정 제안: -queryClient.invalidateQueries({ queryKey: ['crewLists', 'crewDetail'] });
+queryClient.invalidateQueries(['crewLists']);
+queryClient.invalidateQueries(['crewDetail']);📝 Committable suggestion
Suggested change
|
||||||||
| toast.success('크루가 생성되었습니다.'); | ||||||||
| router.push(`/crew/detail/${data.crewId}`); | ||||||||
| }, | ||||||||
| onError: (error) => { | ||||||||
| toast.error(error.message); | ||||||||
| }, | ||||||||
| }); | ||||||||
| } | ||||||||
|
|
||||||||
| export function useEditCrewQuery(id: number) { | ||||||||
| const router = useRouter(); | ||||||||
| const queryClient = useQueryClient(); | ||||||||
|
|
||||||||
| return useMutation({ | ||||||||
| mutationFn: (data: EditCrewRequestTypes) => editCrew(id, data), | ||||||||
| onSuccess: () => { | ||||||||
| queryClient.invalidateQueries({ queryKey: ['crewDetail'] }); | ||||||||
|
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 쿼리 무효화 시 정확한 키 사용 현재 수정 제안: -queryClient.invalidateQueries({ queryKey: ['crewDetail'] });
+queryClient.invalidateQueries(['crewDetail', id]);
|
||||||||
| toast.success('크루 정보가 수정되었습니다.'); | ||||||||
| if (router) { | ||||||||
| router.push(`/crew/detail/${id}`); | ||||||||
| } | ||||||||
| }, | ||||||||
| onError: (error) => { | ||||||||
| toast.error(error.message); | ||||||||
| }, | ||||||||
| retry: false, | ||||||||
| }); | ||||||||
| } | ||||||||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -31,7 +31,7 @@ export default { | |||||||
| } as Meta<typeof CreateCrewForm>; | ||||||||
|
|
||||||||
| const Template: StoryFn<CreateCrewFormTypes> = function CreateCrewPageStory() { | ||||||||
| return <CreateCrewForm data={initialValue} />; | ||||||||
| return <CreateCrewForm data={initialValue} type="create" />; | ||||||||
|
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 타입 안전성 개선이 필요합니다
다음과 같이 개선하는 것을 제안드립니다: - return <CreateCrewForm data={initialValue} type="create" />;
+ const formType = 'create' as const;
+ return <CreateCrewForm data={initialValue} type={formType} />;📝 Committable suggestion
Suggested change
|
||||||||
| }; | ||||||||
|
|
||||||||
| export const Default = Template.bind({}); | ||||||||
|
|
||||||||
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.
editCrew 함수의 구현을 개선해야 합니다.
다음과 같은 중요한 개선사항들이 필요합니다:
다음과 같이 수정하는 것을 제안드립니다:
🧰 Tools
🪛 Biome
[error] 40-40: The catch clause that only rethrows the original error is useless.
An unnecessary catch clause can be confusing.
Unsafe fix: Remove the try/catch clause.
(lint/complexity/noUselessCatch)