From c91f2f2f8b88209db84f2a097eacdd4f293be4f7 Mon Sep 17 00:00:00 2001 From: sumin Date: Tue, 29 Apr 2025 11:26:39 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20=ED=9B=84=EC=9B=90=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=97=90=EB=9F=AC=EB=A9=94=EC=84=B8?= =?UTF-8?q?=EC=A7=80=20=EC=A4=91=EB=B3=B5=20=ED=95=B4=EA=B2=B0=20=EB=B0=8F?= =?UTF-8?q?=20=EB=B2=84=ED=8A=BC=20disabled=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 후원 상세 에러메세지 조건 추가하여 중복 해결 및 값 변경된 후 버튼 disabled 상태 조정 --- .../components/DonationDetailInfo.jsx | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/pages/DonationDetail/components/DonationDetailInfo.jsx b/src/pages/DonationDetail/components/DonationDetailInfo.jsx index 4f53a53..56dd454 100644 --- a/src/pages/DonationDetail/components/DonationDetailInfo.jsx +++ b/src/pages/DonationDetail/components/DonationDetailInfo.jsx @@ -10,6 +10,8 @@ import { useEffect, useState } from "react"; import { toast } from "react-toastify"; import DonationDetailTimer from "./DonationDetailTimer"; +let isCreditErrorToastShown = false; + export default function DonationDetailInfo({ donation, loading }) { const { idol, receivedDonations, targetDonation, deadline, subtitle, title } = donation; @@ -36,19 +38,37 @@ export default function DonationDetailInfo({ donation, loading }) { }); const checkIsLimitOver = (newCredit) => { - const isOverLimit = newCredit > (myCredit.credit || 0); + const availableCredit = myCredit.credit || 0; + const isOverLimit = newCredit > availableCredit; setIsError(isOverLimit); - setCredit(newCredit); if (isOverLimit) { - toast.error("보유한 크레딧을 초과할 수 없습니다.", { - toastId: "credit-error", - }); - setCredit(myCredit.credit || 0); + if (!isCreditErrorToastShown) { + // 1. 초과했으면 토스트 띄우기 (이미 뜬 상태가 아니면) + toast.error("보유한 크레딧을 초과할 수 없습니다.", { + toastId: "credit-error", + }); + isCreditErrorToastShown = true; + } + // 2. 초과했으면 인풋을 현재 보유 크레딧으로 리셋 + setCredit(availableCredit); + + // 3. 에러 상태도 해제 (버튼 disabled 해제) + setIsError(false); + + // 4. 토스트 상태 초기화 + isCreditErrorToastShown = false; } else { - toast.dismiss("credit-error"); + setCredit(newCredit); + setIsError(false); + + // 이미 에러 토스트가 떠 있었으면 닫기 + if (isCreditErrorToastShown) { + toast.dismiss("credit-error"); + isCreditErrorToastShown = false; + } } }; @@ -91,6 +111,7 @@ export default function DonationDetailInfo({ donation, loading }) { setIsModalOpen(false); }; + // 스크롤 내리면 box 내부에 제목 표시 useEffect(() => { if (window.innerWidth <= 768) return; const handleWindowScroll = () => { From f4390a3f7ec0a7f1e3c8c6b50f02657f87ba42c1 Mon Sep 17 00:00:00 2001 From: sumin Date: Tue, 29 Apr 2025 12:00:00 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20=EB=AA=A9=ED=91=9C=20?= =?UTF-8?q?=EA=B8=88=EC=95=A1=20=EC=B4=88=EA=B3=BC=EC=8B=9C=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=EB=A9=94=EC=84=B8=EC=A7=80=20=EB=B0=8F=20=EB=B2=84?= =?UTF-8?q?=ED=8A=BC=20=EB=B9=84=ED=99=9C=EC=84=B1=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 목표금액 초과시 에러메세지 및 버튼 비활성화 완료 --- .../components/DonationDetailInfo.jsx | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/pages/DonationDetail/components/DonationDetailInfo.jsx b/src/pages/DonationDetail/components/DonationDetailInfo.jsx index 56dd454..18dcc60 100644 --- a/src/pages/DonationDetail/components/DonationDetailInfo.jsx +++ b/src/pages/DonationDetail/components/DonationDetailInfo.jsx @@ -11,6 +11,7 @@ import { toast } from "react-toastify"; import DonationDetailTimer from "./DonationDetailTimer"; let isCreditErrorToastShown = false; +let isTargetErrorToastShown = false; export default function DonationDetailInfo({ donation, loading }) { const { idol, receivedDonations, targetDonation, deadline, subtitle, title } = @@ -82,6 +83,7 @@ export default function DonationDetailInfo({ donation, loading }) { } checkIsLimitOver(newCredit); + checkIsTargetOver(newCredit); }; const creditList = [ @@ -133,7 +135,44 @@ export default function DonationDetailInfo({ donation, loading }) { const newValue = value === "" ? 0 : Number(value); checkIsLimitOver(newValue); + checkIsTargetOver(newValue); }; + + const checkIsTargetOver = (newCredit) => { + const isOverLimit = newCredit + donatedAmount > targetDonation; + const availableCredit = isOverLimit ? 0 : targetDonation - donatedAmount; + + setIsError(isOverLimit); + setCredit(newCredit); + + if (isOverLimit) { + if (!isTargetErrorToastShown) { + // 1. 초과했으면 토스트 띄우기 (이미 뜬 상태가 아니면) + toast.error("목표 금액을 초과할 수 없습니다.", { + toastId: "target-error", + }); + isTargetErrorToastShown = true; + } + // 2. 초과했으면 인풋을 현재 보유 크레딧으로 리셋 + setCredit(availableCredit); + + // 3. 에러 상태도 해제 (버튼 disabled 해제) + setIsError(false); + + // 4. 토스트 상태 초기화 + isTargetErrorToastShown = false; + } else { + setCredit(newCredit); + setIsError(false); + + // 이미 에러 토스트가 떠 있었으면 닫기 + if (isTargetErrorToastShown) { + toast.dismiss("target-error"); + isTargetErrorToastShown = false; + } + } + }; + return ( <>
From 222da73313e3c2db9b0fc523e4be1f9907db5a19 Mon Sep 17 00:00:00 2001 From: sumin Date: Tue, 29 Apr 2025 14:09:12 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=A8=20Fix:=20=ED=98=84=EC=A0=9C=20?= =?UTF-8?q?=ED=81=AC=EB=A0=88=EB=94=A7=20=EC=B4=88=EA=B3=BC=20=EA=B9=8C?= =?UTF-8?q?=EC=A7=80=EB=A7=8C=20=EA=B5=AC=ED=98=84=20/=20=EB=AA=A9?= =?UTF-8?q?=ED=91=9C=20=EA=B8=88=EC=95=A1=20=EC=B4=88=EA=B3=BC=20=EC=B6=94?= =?UTF-8?q?=ED=9B=84=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 목표 금액 초과 에러처리 추후 구현 예정 --- .../components/DonationDetailInfo.jsx | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/src/pages/DonationDetail/components/DonationDetailInfo.jsx b/src/pages/DonationDetail/components/DonationDetailInfo.jsx index 18dcc60..f2af28c 100644 --- a/src/pages/DonationDetail/components/DonationDetailInfo.jsx +++ b/src/pages/DonationDetail/components/DonationDetailInfo.jsx @@ -11,7 +11,6 @@ import { toast } from "react-toastify"; import DonationDetailTimer from "./DonationDetailTimer"; let isCreditErrorToastShown = false; -let isTargetErrorToastShown = false; export default function DonationDetailInfo({ donation, loading }) { const { idol, receivedDonations, targetDonation, deadline, subtitle, title } = @@ -138,41 +137,6 @@ export default function DonationDetailInfo({ donation, loading }) { checkIsTargetOver(newValue); }; - const checkIsTargetOver = (newCredit) => { - const isOverLimit = newCredit + donatedAmount > targetDonation; - const availableCredit = isOverLimit ? 0 : targetDonation - donatedAmount; - - setIsError(isOverLimit); - setCredit(newCredit); - - if (isOverLimit) { - if (!isTargetErrorToastShown) { - // 1. 초과했으면 토스트 띄우기 (이미 뜬 상태가 아니면) - toast.error("목표 금액을 초과할 수 없습니다.", { - toastId: "target-error", - }); - isTargetErrorToastShown = true; - } - // 2. 초과했으면 인풋을 현재 보유 크레딧으로 리셋 - setCredit(availableCredit); - - // 3. 에러 상태도 해제 (버튼 disabled 해제) - setIsError(false); - - // 4. 토스트 상태 초기화 - isTargetErrorToastShown = false; - } else { - setCredit(newCredit); - setIsError(false); - - // 이미 에러 토스트가 떠 있었으면 닫기 - if (isTargetErrorToastShown) { - toast.dismiss("target-error"); - isTargetErrorToastShown = false; - } - } - }; - return ( <>