Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pakxe committed Aug 21, 2024
2 parents 3105dd0 + ffc0c34 commit ad1f45a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import validatePurchase from '@utils/validate/validatePurchase';
import useRequestGetStepList from '@hooks/queries/useRequestGetStepList';
import useMemberReportListInAction from '@hooks/useMemberReportListInAction/useMemberReportListInAction';
import useMemberReportInput from '@hooks/useMemberReportListInAction/useMemberReportInput';
import {useToast} from '@hooks/useToast/useToast';

import usePutAndDeleteBillAction from '@hooks/usePutAndDeleteBillAction';

Expand Down Expand Up @@ -64,6 +65,8 @@ const PutAndDeleteBillActionModal = ({
actions.find(({actionId}) => actionId === billAction.actionId),
)[0].members;

const {showToast} = useToast();

return (
<BottomSheet isOpened={isBottomSheetOpened} onClose={() => setIsBottomSheetOpened(false)}>
<form
Expand Down
14 changes: 11 additions & 3 deletions client/src/hooks/queries/useRequestPutBillAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,26 @@ interface PutBillActionMutationProps {
actionId: number;
title: string;
price: number;
onSuccessCallback?: () => void; // ์ฝœ๋ฐฑ ํ•จ์ˆ˜ ํƒ€์ž…์„ ์ •์˜
}

const useRequestPutBillAction = () => {
const eventId = getEventIdByUrl();
const queryClient = useQueryClient();

return useMutation({
mutationFn: ({actionId, title, price}: PutBillActionMutationProps) =>
requestPutBillAction({eventId, actionId, title, price}),
onSuccess: () => {
mutationFn: async ({actionId, title, price}: PutBillActionMutationProps) => {
const response = await requestPutBillAction({eventId, actionId, title, price});
return response; // response๋ฅผ ๋ฐ˜ํ™˜ํ•˜์—ฌ onSuccess์—์„œ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•จ
},
onSuccess: (data, variables) => {
queryClient.invalidateQueries({queryKey: [QUERY_KEYS.stepList]});
queryClient.invalidateQueries({queryKey: [QUERY_KEYS.memberReport]});

// ์ฝœ๋ฐฑ ํ•จ์ˆ˜๊ฐ€ ์ „๋‹ฌ๋˜์—ˆ๋‹ค๋ฉด ์‹คํ–‰
if (variables.onSuccessCallback) {
variables.onSuccessCallback();
}
},
});
};
Expand Down
5 changes: 3 additions & 2 deletions client/src/hooks/usePutAndDeleteBillAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,13 @@ const usePutAndDeleteBillAction = (
setErrorInfo(errorInfo ?? {title: false, price: false});
};

const onSubmit = async (event: React.FormEvent<HTMLFormElement>, inputPair: InputPair, actionId: number) => {
const onSubmit = (event: React.FormEvent<HTMLFormElement>, inputPair: InputPair, actionId: number) => {
event.preventDefault();

const {title, price} = inputPair;

await putBillAction({actionId, title, price: Number(price)});
putBillAction({actionId, title, price: Number(price)});

onClose();
};

Expand Down

0 comments on commit ad1f45a

Please sign in to comment.