diff --git a/src/__generated__/schema2.d.ts b/src/__generated__/schema2.d.ts index a17ebabf..b0dc9dcc 100644 --- a/src/__generated__/schema2.d.ts +++ b/src/__generated__/schema2.d.ts @@ -77,8 +77,8 @@ export interface paths { post: operations["createMeeting"]; }; "/meeting/v2/apply": { - /** 모임 지원 */ - post: operations["applyMeeting"]; + /** 일반 모임 지원 */ + post: operations["applyGeneralMeeting"]; }; "/comment/v2": { /** 모임 게시글 댓글 리스트 조회 */ @@ -2325,8 +2325,8 @@ export interface operations { 400: never; }; }; - /** 모임 지원 */ - applyMeeting: { + /** 일반 모임 지원 */ + applyGeneralMeeting: { requestBody: { content: { "application/json;charset=UTF-8": components["schemas"]["MeetingV2ApplyMeetingDto"]; diff --git a/src/api/API_LEGACY/meeting/hooks.ts b/src/api/API_LEGACY/meeting/hooks.ts index f939e129..e0a414d2 100644 --- a/src/api/API_LEGACY/meeting/hooks.ts +++ b/src/api/API_LEGACY/meeting/hooks.ts @@ -30,6 +30,7 @@ import { getGroupBrowsingCard, GroupBrowsingCardDetail, GetMeetingResponse, + postEventApplication, } from '.'; interface UseQueryGetMeetingParams { @@ -141,6 +142,20 @@ export const useMutationPostApplication = ({ }); }; +export const useMutationPostEventApplication = ({ + useMutationOptions, +}: UseMutateBody): UseMutationResult< + { statusCode: number }, + AxiosError, + PostApplicationRequest +> => { + return useMutation<{ statusCode: number }, AxiosError, PostApplicationRequest>({ + ...useMutationOptions, + mutationKey: ['postApplication'], + mutationFn: postEventApplication, + }); +}; + export const useMutationDeleteApplication = ({ useMutationOptions, }: UseMutateBody): UseMutationResult<{ statusCode: number }, AxiosError, number> => { diff --git a/src/api/API_LEGACY/meeting/index.ts b/src/api/API_LEGACY/meeting/index.ts index bea250f1..59b8568b 100644 --- a/src/api/API_LEGACY/meeting/index.ts +++ b/src/api/API_LEGACY/meeting/index.ts @@ -217,6 +217,10 @@ export const postApplication = async (body: PostApplicationRequest): Promise<{ s return (await api.post<{ statusCode: number }>(`/meeting/v2/apply`, body)).data; }; +export const postEventApplication = async (body: PostApplicationRequest): Promise<{ statusCode: number }> => { + return (await api.post<{ statusCode: number }>(`/meeting/v2/apply/undefined`, body)).data; +}; + export const deleteApplication = async (meetingId: number): Promise<{ statusCode: number }> => { return (await api.delete<{ statusCode: number }>(`/meeting/v2/${meetingId}/apply`)).data; }; diff --git a/src/components/page/meetingDetail/MeetingController/index.tsx b/src/components/page/meetingDetail/MeetingController/index.tsx index 444dd95e..2e21a05b 100644 --- a/src/components/page/meetingDetail/MeetingController/index.tsx +++ b/src/components/page/meetingDetail/MeetingController/index.tsx @@ -22,6 +22,7 @@ import ButtonLoader from '@components/loader/ButtonLoader'; import { useDialog } from '@sopt-makers/ui'; import { ReactNode } from 'react'; import ProfileAnchor from './ProfileAnchor'; +import { useMutationPostEventApplication } from '@api/API_LEGACY/meeting/hooks'; interface DetailHeaderProps { detailData: GetMeetingResponse; @@ -91,7 +92,7 @@ const MeetingController = ({ const router = useRouter(); const meetingId = router.query.id; const isRecruiting = status === ERecruitmentStatus.RECRUITING; - + const { mutate: mutateEventApplication } = useMutationPostEventApplication({}); const { isModalOpened: isGuestModalOpened, handleModalOpen: handleGuestModalOpen, @@ -169,39 +170,75 @@ const MeetingController = ({ const handleApplicationButton = (textareaValue: string) => { setIsSubmitting(true); - mutateApplication( - { meetingId: Number(meetingId), content: textareaValue }, - { - onSuccess: async () => { - await queryClient.refetchQueries({ - queryKey: ['getMeeting', meetingId as string], - }); - dialogOpen({ - title: '신청 완료 되었습니다', - description: '', - type: 'single', - typeOptions: { approveButtonText: '확인', buttonFunction: dialogClose }, - }); - - setIsSubmitting(false); - handleDefaultModalClose(); - }, - onError: async (error: AxiosError) => { - await queryClient.refetchQueries({ - queryKey: ['getMeeting', meetingId as string], - }); - const errorResponse = error.response as AxiosResponse; - dialogOpen({ - title: errorResponse.data.errorCode, - description: '', - type: 'single', - typeOptions: { approveButtonText: '확인', buttonFunction: dialogClose }, - }); - setIsSubmitting(false); - handleDefaultModalClose(); - }, - } - ); + if (category === '행사') { + mutateEventApplication( + { meetingId: Number(meetingId), content: textareaValue }, + { + onSuccess: async () => { + await queryClient.refetchQueries({ + queryKey: ['getMeeting', meetingId as string], + }); + dialogOpen({ + title: '신청 완료 되었습니다', + description: '', + type: 'single', + typeOptions: { approveButtonText: '확인', buttonFunction: dialogClose }, + }); + + setIsSubmitting(false); + handleDefaultModalClose(); + }, + onError: async (error: AxiosError) => { + await queryClient.refetchQueries({ + queryKey: ['getMeeting', meetingId as string], + }); + const errorResponse = error.response as AxiosResponse; + dialogOpen({ + title: errorResponse.data.errorCode, + description: '', + type: 'single', + typeOptions: { approveButtonText: '확인', buttonFunction: dialogClose }, + }); + setIsSubmitting(false); + handleDefaultModalClose(); + }, + } + ); + } else { + mutateApplication( + { meetingId: Number(meetingId), content: textareaValue }, + { + onSuccess: async () => { + await queryClient.refetchQueries({ + queryKey: ['getMeeting', meetingId as string], + }); + dialogOpen({ + title: '신청 완료 되었습니다', + description: '', + type: 'single', + typeOptions: { approveButtonText: '확인', buttonFunction: dialogClose }, + }); + + setIsSubmitting(false); + handleDefaultModalClose(); + }, + onError: async (error: AxiosError) => { + await queryClient.refetchQueries({ + queryKey: ['getMeeting', meetingId as string], + }); + const errorResponse = error.response as AxiosResponse; + dialogOpen({ + title: errorResponse.data.errorCode, + description: '', + type: 'single', + typeOptions: { approveButtonText: '확인', buttonFunction: dialogClose }, + }); + setIsSubmitting(false); + handleDefaultModalClose(); + }, + } + ); + } }; const handleCancelApplication = () => {