Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions src/pages/DonationDetail/components/DonationDetailInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
};

Expand All @@ -62,6 +82,7 @@ export default function DonationDetailInfo({ donation, loading }) {
}

checkIsLimitOver(newCredit);
checkIsTargetOver(newCredit);
};

const creditList = [
Expand Down Expand Up @@ -91,6 +112,7 @@ export default function DonationDetailInfo({ donation, loading }) {
setIsModalOpen(false);
};

// 슀크둀 내리면 box 내뢀에 제λͺ© ν‘œμ‹œ
useEffect(() => {
if (window.innerWidth <= 768) return;
const handleWindowScroll = () => {
Expand All @@ -112,7 +134,9 @@ export default function DonationDetailInfo({ donation, loading }) {
const newValue = value === "" ? 0 : Number(value);

checkIsLimitOver(newValue);
checkIsTargetOver(newValue);
};

return (
<>
<form onSubmit={safeSubmit} css={DonationDetailInfoStyle}>
Expand Down