From 6f5dd86cd15312caf2c96a5351b67444af3492d8 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Thu, 7 Dec 2023 16:36:57 +0000 Subject: [PATCH] Updated so the new payment prefills with all of the corporate's payment information --- src/components/UserCard.tsx | 2 +- src/pages/payment-record.tsx | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/UserCard.tsx b/src/components/UserCard.tsx index 682b32d8..76e8a830 100644 --- a/src/components/UserCard.tsx +++ b/src/components/UserCard.tsx @@ -58,7 +58,7 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers, ); const [userAmount, setUserAmount] = useState(user.type === "corporate" ? user.corporateInformation?.companyInformation.userAmount : undefined); const [paymentValue, setPaymentValue] = useState(user.type === "corporate" ? user.corporateInformation?.payment?.value : undefined); - const [paymentCurrency, setPaymentCurrency] = useState(user.type === "corporate" ? user.corporateInformation?.payment?.currency : undefined); + const [paymentCurrency, setPaymentCurrency] = useState(user.type === "corporate" ? user.corporateInformation?.payment?.currency : "EUR"); const [monthlyDuration, setMonthlyDuration] = useState(user.type === "corporate" ? user.corporateInformation?.monthlyDuration : undefined); const {stats} = useStats(user.id); diff --git a/src/pages/payment-record.tsx b/src/pages/payment-record.tsx index ee58653b..70f094d7 100644 --- a/src/pages/payment-record.tsx +++ b/src/pages/payment-record.tsx @@ -75,6 +75,13 @@ const PaymentCreator = ({onClose, reload}: {onClose: () => void; reload: () => v setReferralAgent(referralAgent as AgentUser | undefined); }, [corporate, users]); + useEffect(() => { + const payment = corporate?.corporateInformation?.payment; + + setPrice(payment?.value || 0); + setCurrency(payment?.currency || "EUR"); + }, [corporate]); + const submit = () => { axios .post(`/api/payments`, { @@ -138,14 +145,15 @@ const PaymentCreator = ({onClose, reload}: {onClose: () => void; reload: () => v name="paymentValue" onChange={(e) => setPrice(e ? parseInt(e) : 0)} type="number" - defaultValue={0} + value={price} className="col-span-3" />