Skip to content

Commit

Permalink
크루, 게스트 모집 참여 취소하기 api 연결 (#461)
Browse files Browse the repository at this point in the history
* feat: 크루 가입 신청 취소하기 기능 추가

* feat: 게스트 모집 참여 취소하기 기능 추가
  • Loading branch information
dlwl98 authored Dec 3, 2023
1 parent 9ce983e commit 16ba286
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 16 deletions.
24 changes: 24 additions & 0 deletions src/hooks/crews/useCrewParticipateDeleteMutation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useMutation } from '@tanstack/react-query';
import { useQueryClient } from '@tanstack/react-query';

import { deleteCrewParticipate } from '@api/crews/deleteCrewParticipate';

import { useLoginInfoStore } from '@stores/loginInfo.store';

export const useCrewParticipateDeleteMutation = () => {
const queryClient = useQueryClient();
const id = useLoginInfoStore((state) => state.loginInfo?.id);

return useMutation({
mutationFn: deleteCrewParticipate,
onSuccess: (_, { crewId }) => {
queryClient.invalidateQueries({
queryKey: ['crew-detail', crewId],
});
id &&
queryClient.invalidateQueries({
queryKey: ['crew-registration', id, crewId],
});
},
});
};
23 changes: 16 additions & 7 deletions src/hooks/games/useGameParticipateDeleteMutation.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import { useMutation } from '@tanstack/react-query';
import { useQueryClient } from '@tanstack/react-query';

import { deleteGameParticipate } from '@api/games/deleteGameParticipate';

import { DeleteGameParticipateRequest } from '@type/api/games';
import { useLoginInfoStore } from '@stores/loginInfo.store';

export const useGameParticipateDeleteMutation = () => {
const queryClient = useQueryClient();
const id = useLoginInfoStore((state) => state.loginInfo?.id);

export const useGameParticipateDeleteMutation = ({
gameId,
memberId,
}: DeleteGameParticipateRequest) => {
return useMutation({
mutationKey: ['delete-game-participate', gameId, memberId],
mutationFn: () => deleteGameParticipate({ gameId, memberId }),
mutationFn: deleteGameParticipate,
onSuccess: (_, { gameId }) => {
queryClient.invalidateQueries({
queryKey: ['game-detail', gameId],
});
id &&
queryClient.invalidateQueries({
queryKey: ['game-registration', id, gameId],
});
},
});
};
20 changes: 16 additions & 4 deletions src/pages/CrewsDetailPage/components/ParticipateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import toast from 'react-hot-toast';
import { Button } from '@components/shared/Button';

import { useCrewParticipateCreateMutation } from '@hooks/crews/useCrewParticipateCreateMutation';
import { useCrewParticipateDeleteMutation } from '@hooks/crews/useCrewParticipateDeleteMutation';
import { useCrewRegistrationStatusQuery } from '@hooks/member/useCrewRegistrationStatusQuery';

import { theme } from '@styles/theme';
Expand All @@ -19,8 +20,10 @@ export const ParticipateButton = ({
const {
data: { memberRegistrationStatus },
} = useCrewRegistrationStatusQuery({ memberId: loginId, crewId });
const { mutate: participateMutate } = useCrewParticipateCreateMutation();

const { mutate: participateCreateMutate } =
useCrewParticipateCreateMutation();
const { mutate: participateDeleteMutate } =
useCrewParticipateDeleteMutation();
if (memberRegistrationStatus === '없음' && !vacancy) {
return (
<Button
Expand All @@ -40,7 +43,7 @@ export const ParticipateButton = ({
height="50px"
width="100%"
onClick={() =>
participateMutate(
participateCreateMutate(
{ crewId },
{
onSuccess: () => {
Expand All @@ -61,7 +64,16 @@ export const ParticipateButton = ({
{...theme.BUTTON_PROPS.LARGE_RED_BUTTON_PROPS}
height="50px"
width="100%"
onClick={() => toast('준비중인 기능입니다')}
onClick={() =>
participateDeleteMutate(
{ memberId: loginId, crewId },
{
onSuccess: () => {
toast('가입 신청이 취소되었습니다');
},
}
)
}
>
참여 취소하기
</Button>
Expand Down
25 changes: 20 additions & 5 deletions src/pages/GamesDetailPage/components/GuestButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useNavigate } from 'react-router-dom';
import { Button } from '@components/shared/Button';

import { useGameParticipateCreateMutation } from '@hooks/games/useGameParticipateCreateMutation';
import { useGameParticipateDeleteMutation } from '@hooks/games/useGameParticipateDeleteMutation';
import { useGameRegistrationStatusQuery } from '@hooks/member/useGameRegistrationStatusQuery';

import { theme } from '@styles/theme';
Expand Down Expand Up @@ -35,13 +36,16 @@ export const GuestButton = ({
const {
data: { memberRegistrationStatus, isReviewDone },
} = useGameRegistrationStatusQuery({ memberId: loginId, gameId });
const { mutate: participateMutate } = useGameParticipateCreateMutation();
const { mutate: participateCreateMutate } =
useGameParticipateCreateMutation();
const { mutate: participateDeleteMutate } =
useGameParticipateDeleteMutation();

const navigateReviewPage = () =>
navigate(PATH_NAME.GET_GAMES_REVIEW_PATH(String(gameId)));

const handleParticipateButtonClick = () =>
participateMutate(
const handleParticipateCreateButtonClick = () =>
participateCreateMutate(
{ gameId },
{
onSuccess: () => {
Expand All @@ -50,6 +54,17 @@ export const GuestButton = ({
}
);

const handleParticipateDeleteButtonClick = () => {
participateDeleteMutate(
{ memberId: loginId, gameId },
{
onSuccess: () => {
toast('참여 신청이 취소되었습니다');
},
}
);
};

if (isContinue) {
return null;
}
Expand Down Expand Up @@ -81,15 +96,15 @@ export const GuestButton = ({

if (memberRegistrationStatus === '없음') {
return (
<BottomButton onClick={handleParticipateButtonClick}>
<BottomButton onClick={handleParticipateCreateButtonClick}>
참여 신청하기
</BottomButton>
);
}

if (memberRegistrationStatus === '대기') {
return (
<BottomButton onClick={() => toast('준비중인 기능입니다')}>
<BottomButton onClick={handleParticipateDeleteButtonClick}>
참여 취소하기
</BottomButton>
);
Expand Down

0 comments on commit 16ba286

Please sign in to comment.