-
Notifications
You must be signed in to change notification settings - Fork 3
Feat/132/create edit gathering api 연결 #133
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 4 commits
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 | ||||
|---|---|---|---|---|---|---|
| @@ -1,9 +1,29 @@ | ||||||
| import { useQuery } from '@tanstack/react-query'; | ||||||
| import { GetGatheringDetail } from '@/src/_apis/gathering/gathering-detail-apis'; | ||||||
| import { toast } from 'react-toastify'; | ||||||
| import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; | ||||||
| import { GetGatheringDetail, createGathering } from '@/src/_apis/gathering/gathering-detail-apis'; | ||||||
| import { CreateGatheringRequestTypes } from '@/src/types/gathering-data'; | ||||||
|
|
||||||
| export function useGetGatheringDetailQuery(crewId: number, gatheringId: number) { | ||||||
| return useQuery({ | ||||||
| queryKey: ['gatheringDetail', crewId, gatheringId], | ||||||
| queryFn: () => GetGatheringDetail(crewId, gatheringId), | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| export function useCreateGatheringQuery(crewId: number) { | ||||||
| const queryClient = useQueryClient(); | ||||||
|
|
||||||
| return useMutation({ | ||||||
| mutationFn: (data: CreateGatheringRequestTypes) => createGathering(crewId, data), | ||||||
| onSuccess: () => { | ||||||
| queryClient.invalidateQueries({ | ||||||
| queryKey: ['gatheringList', crewId], | ||||||
| refetchType: 'all', | ||||||
| }); | ||||||
| toast.success('크루가 생성되었습니다.'); | ||||||
|
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. 성공 메시지의 용어를 수정해야 합니다. 성공 메시지에서 "크루가 생성되었습니다"라고 되어 있는데, PR의 목적에 따르면 이는 "모임"을 생성하는 기능입니다. 다음과 같이 수정하는 것을 제안드립니다: - toast.success('크루가 생성되었습니다.');
+ toast.success('모임이 생성되었습니다.');📝 Committable suggestion
Suggested change
|
||||||
| }, | ||||||
| onError: (error) => { | ||||||
| toast.error(error.message); | ||||||
| }, | ||||||
| }); | ||||||
| } | ||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |||||||||||||||
|
|
||||||||||||||||
| import { Controller, useForm, useWatch } from 'react-hook-form'; | ||||||||||||||||
| import { NumberInput } from '@mantine/core'; | ||||||||||||||||
| import { getImageUrl } from '@/src/_apis/image/get-image-url'; | ||||||||||||||||
| import Button from '@/src/components/common/input/button'; | ||||||||||||||||
| import DateTimePicker from '@/src/components/common/input/date-time-picker'; | ||||||||||||||||
| import FileInputWrap from '@/src/components/common/input/file-input-wrap'; | ||||||||||||||||
|
|
@@ -38,6 +39,16 @@ export default function CreateGatheringForm({ | |||||||||||||||
| const location = useWatch({ control, name: 'location' }); | ||||||||||||||||
| const introduce = useWatch({ control, name: 'introduce' }); | ||||||||||||||||
|
|
||||||||||||||||
| const handleFileChange = async ( | ||||||||||||||||
| file: File | string | null, | ||||||||||||||||
| onChange: (value: string | File) => void, | ||||||||||||||||
| ) => { | ||||||||||||||||
| if (file instanceof File) { | ||||||||||||||||
| const imgResponse = await getImageUrl(file, 'CREW'); | ||||||||||||||||
| onChange(imgResponse?.imageUrl || ''); | ||||||||||||||||
| } | ||||||||||||||||
| }; | ||||||||||||||||
|
|
||||||||||||||||
| return ( | ||||||||||||||||
| <form onSubmit={isEdit ? handleSubmit(onEdit) : handleSubmit(onSubmit)}> | ||||||||||||||||
| <div className="flex flex-col gap-6"> | ||||||||||||||||
|
|
@@ -103,6 +114,7 @@ export default function CreateGatheringForm({ | |||||||||||||||
| {...field} | ||||||||||||||||
| sample={ImgGatheringSampleUrls} | ||||||||||||||||
| onChange={(newValue) => { | ||||||||||||||||
| handleFileChange(newValue, field.onChange); | ||||||||||||||||
| field.onChange(newValue); | ||||||||||||||||
| trigger('imageUrl'); | ||||||||||||||||
|
Comment on lines
+117
to
119
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. onChange 핸들러의 중복 호출 문제를 수정해주세요. 현재 코드에서는 다음과 같이 수정하는 것을 추천드립니다: -handleFileChange(newValue, field.onChange);
-field.onChange(newValue);
-trigger('imageUrl');
+handleFileChange(newValue, (value) => {
+ field.onChange(value);
+ trigger('imageUrl');
+});📝 Committable suggestion
Suggested change
|
||||||||||||||||
| }} | ||||||||||||||||
|
|
@@ -162,8 +174,7 @@ export default function CreateGatheringForm({ | |||||||||||||||
| {...field} | ||||||||||||||||
| fullDate={new Date()} | ||||||||||||||||
| onChange={(date) => { | ||||||||||||||||
| const formattedDate = date.toLocaleString(); | ||||||||||||||||
| onChange(formattedDate); | ||||||||||||||||
| onChange(date); | ||||||||||||||||
| trigger('dateTime'); // 유효성 검사 실행 | ||||||||||||||||
| }} | ||||||||||||||||
| /> | ||||||||||||||||
|
|
||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| 'use client'; | ||
|
|
||
| import { Loader } from '@mantine/core'; | ||
| import { useCreateGatheringQuery } from '@/src/_queries/gathering/gathering-detail-queries'; | ||
| import { CreateGatheringFormTypes, CreateGatheringRequestTypes } from '@/src/types/gathering-data'; | ||
| import CreateGatheringModalPresenter from './presenter'; | ||
|
|
||
| export interface CreateGatheringModalContainerProps { | ||
| crewId: number; | ||
| opened: boolean; | ||
| close: () => void; | ||
| data: CreateGatheringFormTypes; | ||
| } | ||
|
|
||
| export default function CreateGatheringModalContainer({ | ||
| crewId, | ||
| opened, | ||
| close, | ||
| data, | ||
| }: CreateGatheringModalContainerProps) { | ||
| const { isPending, mutate } = useCreateGatheringQuery(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. 🛠️ Refactor suggestion 에러 처리 추가 필요
- const { isPending, mutate } = useCreateGatheringQuery(crewId);
+ const { isPending, error, mutate } = useCreateGatheringQuery(crewId);
+
+ useEffect(() => {
+ if (error) {
+ notifications.show({
+ title: '오류 발생',
+ message: '모임을 생성하는 중 문제가 발생했습니다.',
+ color: 'red',
+ });
+ }
+ }, [error]);
|
||
|
|
||
| const handleSubmit = async (createdData: CreateGatheringFormTypes) => { | ||
| const newData: CreateGatheringRequestTypes = { | ||
| title: createdData.title, | ||
| imageUrl: (createdData.imageUrl as string) ?? '', | ||
| dateTime: createdData.dateTime, | ||
| location: createdData.location, | ||
| totalCount: createdData.totalCount, | ||
| introduce: createdData.introduce, | ||
| }; | ||
|
|
||
| mutate(newData); | ||
| close(); | ||
| }; | ||
| const handleEdit = () => { | ||
| // TODO : 약속 수정하기 API 연결 | ||
| close(); | ||
| }; | ||
|
|
||
| if (isPending) | ||
| return ( | ||
| <div className="fixed inset-0 z-10 flex items-center justify-center"> | ||
| <Loader size="sm" /> | ||
| </div> | ||
| ); | ||
|
|
||
| return ( | ||
| <CreateGatheringModalPresenter | ||
| data={data} | ||
| opened={opened} | ||
| onClose={close} | ||
| onEdit={handleEdit} | ||
| onSubmit={handleSubmit} | ||
| /> | ||
| ); | ||
| } | ||
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.
🛠️ Refactor suggestion
API 구현에 대한 몇 가지 개선사항이 있습니다.
다음 사항들을 개선하면 좋을 것 같습니다:
id매개변수의 이름이 모호합니다.crewId로 변경하면 좋겠습니다.다음과 같이 수정하는 것을 제안드립니다:
📝 Committable suggestion