Skip to content

Commit a2ec19d

Browse files
committed
feat:구매/참가자 승인 api 구현
1 parent 2b30d49 commit a2ec19d

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

src/features/dashboard/api/participants.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,13 @@ export const getParticipants = async ({ eventId = 1, tags = 'all', page = 0, siz
66
const response = await axiosClient.get('/host-channels/dashboard/participant-management', { params });
77
return response.data.result;
88
};
9+
10+
export const approveParticipants = async ({ orderId }: { orderId: number }) => {
11+
try {
12+
const response = await axiosClient.post('/host-channels/dashboard/participant-management/approve', { orderId });
13+
14+
return response.data;
15+
} catch (error) {
16+
console.log(error);
17+
}
18+
};

src/features/dashboard/hook/useParticipants.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { useQuery } from '@tanstack/react-query';
1+
import { useMutation, useQuery } from '@tanstack/react-query';
22
import { getParticipants } from '../../../features/dashboard/api/participants';
33
import { useParams } from 'react-router-dom';
4+
import { ApiResponse } from '../../../shared/types/api/apiResponse';
5+
import { AxiosError } from 'axios';
6+
import { approveParticipants } from '../../../features/dashboard/api/participants';
7+
import { useParticipantStore } from '../model/ParticipantStore';
48

59
export const useParticipants = (tags = 'all', page = 0, size = 10) => {
610
const { id } = useParams();
@@ -21,3 +25,14 @@ export const useParticipants = (tags = 'all', page = 0, size = 10) => {
2125
error,
2226
};
2327
};
28+
29+
export const useApproveParticipants = (orderId: number) => {
30+
const { toggleApproveParticipant } = useParticipantStore();
31+
32+
return useMutation<ApiResponse<string>, AxiosError, { orderId: number }>({
33+
mutationFn: () => approveParticipants({ orderId }),
34+
onSuccess: () => {
35+
toggleApproveParticipant(orderId);
36+
},
37+
});
38+
};

src/features/dashboard/ui/ParicipantCard.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useParticipantStore } from '../model/ParticipantStore';
44
import { participantsData } from '../../../shared/types/participantInfoType';
55
import SecondaryButton from '../../../../design-system/ui/buttons/SecondaryButton';
66
import { useNavigate } from 'react-router-dom';
7+
import { useApproveParticipants } from '../hook/useParticipants';
78

89
interface ParticipantCardProps {
910
participant: participantsData;
@@ -12,9 +13,11 @@ interface ParticipantCardProps {
1213
}
1314

1415
const ParticipantCard = ({ participant, checked, onChange }: ParticipantCardProps) => {
15-
const { approvedParticipants, toggleApproveParticipant } = useParticipantStore();
16+
const { approvedParticipants } = useParticipantStore();
1617
const navigate = useNavigate();
1718

19+
const { mutate: approveParticipant } = useApproveParticipants(participant.orderNumber);
20+
1821
return (
1922
<div className="flex items-center justify-between w-full text-xs bg-white px-2 md:px-3 py-2 shadow-sm">
2023
<div className="flex gap-2 md:gap-3">
@@ -56,7 +59,7 @@ const ParticipantCard = ({ participant, checked, onChange }: ParticipantCardProp
5659
type="button"
5760
size="small"
5861
color="pink"
59-
onClick={() => toggleApproveParticipant(participant.orderNumber)}
62+
onClick={() => approveParticipant({ orderId: participant.orderNumber })}
6063
/>
6164
)}
6265
</div>

0 commit comments

Comments
 (0)