Skip to content

Commit

Permalink
fix: 베팅 포인트 수정 즉시 업데이트 되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
maylh committed Aug 18, 2024
1 parent 68f6873 commit 9c93549
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ const UserWkHistoryPage = () => {
{data.pages.map((page) =>
page.applyInfoList.map((wkt) => (
<WorkationCard
refetch={refetch}
applyId={wkt.applyId}
accountId={accountId}
reviewId={wkt.reviewId}
Expand Down
9 changes: 6 additions & 3 deletions src/app/_components/user/mypage/UserWktCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface WorkationCardProps {
accountId?: string;
applyId: number;
onClick?: (applyStatusType: WorkationCardProps['applyStatusType']) => void;
refetch: () => void;
}

const WorkationCard = ({
Expand All @@ -50,6 +51,7 @@ const WorkationCard = ({
waitingNumber = -1,
applyId,
onClick,
refetch,
}: WorkationCardProps) => {
const { textLabel, buttonText, textLabelClass, buttonStyle, buttonDisabled } =
StatusConfig[applyStatusType];
Expand All @@ -75,9 +77,10 @@ const WorkationCard = ({

const { mutate: patchBettingPoint } = usePatchBettingPointMutation({
applyId,
successCallback: () => {
setCurrentBettingPoint(Number(newBettingPoint));
alert('베팅 포인트가 수정되었습니다.');
successCallback: (usedPoint) => {
alert(`베팅 포인트가 수정되었습니다.`);
setCurrentBettingPoint(usedPoint);
refetch?.();
},
errorCallback: (error) => {
alert(`베팅 포인트 수정 실패 : ${error.message}`);
Expand Down
1 change: 1 addition & 0 deletions src/app/_hooks/user/useGetMyWktHistoryQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ export const useGetMyWktHistoryQuery = ({
sort: pageable.sort,
};
},
refetchOnMount: true,
});
};
20 changes: 12 additions & 8 deletions src/app/_hooks/user/usePatchBettingPointMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,32 @@ export const usePatchBettingPointMutation = ({
errorCallback,
}: {
applyId: number;
successCallback?: () => void;
successCallback?: (usedPoint: number) => void;
errorCallback?: (error: Error) => void;
}) => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: async ({ usedPoint }: { usedPoint: number }) => {
const res = await api.patch(`/api/apply/${applyId}`, {
usedPoint,
});
return res.data.data;
const res = await api.patch(`/api/apply/${applyId}`, { usedPoint });
return usedPoint; // 클라이언트에서 사용된 usedPoint 반환
},
onSuccess: () => {
onSuccess: (usedPoint) => {
console.log('Updated usedPoint:', usedPoint);
queryClient.invalidateQueries({
queryKey: [useGetMyWktHistoryQueryKey, applyId],
});
queryClient.refetchQueries({
queryKey: [useGetMyWktHistoryQueryKey, applyId],
});
successCallback && successCallback();
if (successCallback) {
successCallback(usedPoint);
}
},
onError: (error: Error) => {
errorCallback && errorCallback(error);
if (errorCallback) {
errorCallback(error);
}
},
});
};

0 comments on commit 9c93549

Please sign in to comment.