From 7e83d72598a882fbc4a2282583cdda00b2ef4f6a Mon Sep 17 00:00:00 2001 From: Park Nayoung <139189221+im-na0@users.noreply.github.com> Date: Thu, 25 Jan 2024 16:36:25 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20action=20=EC=A1=B0=EA=B1=B4=EB=AC=B8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/paymentPage/Payment.tsx | 33 ++++++++++++++++--------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/pages/paymentPage/Payment.tsx b/src/pages/paymentPage/Payment.tsx index d9f9742a..f31a4f91 100644 --- a/src/pages/paymentPage/Payment.tsx +++ b/src/pages/paymentPage/Payment.tsx @@ -52,6 +52,21 @@ const Payment = ({ action }: PaymentProps) => { useEffect(() => { if (action === "ready") { paymentSuccessQuery(); + + if (isSuccess) { + navigate(`/payment/${successData.paymentHistoryId}/success`); + } + + if (isError && isAxiosError(error)) { + if (error.response?.status === 409) { + setErrorMessage("이미 판매완료된 상품입니다."); + } else { + setErrorMessage( + error.response?.data.message || "오류가 발생했습니다.", + ); + } + setIsModalOpen(true); + } } if (action === "cancel") { @@ -59,23 +74,9 @@ const Payment = ({ action }: PaymentProps) => { setErrorMessage("결제가 취소되었습니다."); setIsModalOpen(true); } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [action]); - - useEffect(() => { - if (isSuccess) { - navigate(`/payment/${successData.paymentHistoryId}/success`); - } - if (isError && isAxiosError(error)) { - if (error.response?.status === 409) { - setErrorMessage("이미 판매완료된 상품입니다."); - } else { - setErrorMessage(error.response?.data.message || "오류가 발생했습니다."); - } - setIsModalOpen(true); - } - }, [isSuccess, isError, error, navigate, productId]); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [action, error, isError, isSuccess]); const closeModal = () => { setIsModalOpen(false);