Skip to content

Commit

Permalink
feat: 행사 신청 / 일반 모임 신청 API 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
borimong committed Nov 12, 2024
1 parent fabcf36 commit 039d998
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 38 deletions.
8 changes: 4 additions & 4 deletions src/__generated__/schema2.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/api/API_LEGACY/meeting/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
getGroupBrowsingCard,
GroupBrowsingCardDetail,
GetMeetingResponse,
postEventApplication,
} from '.';

interface UseQueryGetMeetingParams {
Expand Down Expand Up @@ -141,6 +142,20 @@ export const useMutationPostApplication = ({
});
};

export const useMutationPostEventApplication = ({
useMutationOptions,
}: UseMutateBody<PostApplicationRequest>): UseMutationResult<
{ statusCode: number },
AxiosError,
PostApplicationRequest
> => {
return useMutation<{ statusCode: number }, AxiosError, PostApplicationRequest>({
...useMutationOptions,
mutationKey: ['postApplication'],
mutationFn: postEventApplication,
});
};

export const useMutationDeleteApplication = ({
useMutationOptions,
}: UseMutateBody<number>): UseMutationResult<{ statusCode: number }, AxiosError, number> => {
Expand Down
4 changes: 4 additions & 0 deletions src/api/API_LEGACY/meeting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
105 changes: 71 additions & 34 deletions src/components/page/meetingDetail/MeetingController/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = () => {
Expand Down

0 comments on commit 039d998

Please sign in to comment.