From d65d121a5dd38c46387c87ad65bbbcd8e6838d33 Mon Sep 17 00:00:00 2001 From: Test User Date: Thu, 23 Apr 2026 23:10:47 +0000 Subject: [PATCH 1/3] fix(GRO-876): wire up refund button in invoice detail modal Cherry-pick of 628ed34 to fix @typescript-eslint/no-unused-vars error on PR #351 Lint & Typecheck. The issueRefund function was defined but never called. This commit: - Removes the inline async onClick handler that bypassed issueRefund - Wires the Refund button to open setShowRefundDialog(true) instead - Uses issueRefund function (with refundAmount/refundError/refunding state) - Adds manager role check before showing refund button - Shows "Refunded" badge when invoice.stripeRefundId is set Co-Authored-By: Paperclip --- apps/api/src/routes/invoices.ts | 1 + apps/web/src/pages/Invoices.tsx | 143 +++++++++++++++++--------------- 2 files changed, 76 insertions(+), 68 deletions(-) diff --git a/apps/api/src/routes/invoices.ts b/apps/api/src/routes/invoices.ts index 9bb8790..a5c0d95 100644 --- a/apps/api/src/routes/invoices.ts +++ b/apps/api/src/routes/invoices.ts @@ -102,6 +102,7 @@ invoicesRouter.get( paidAt: invoices.paidAt, notes: invoices.notes, stripePaymentIntentId: invoices.stripePaymentIntentId, + stripeRefundId: invoices.stripeRefundId, createdAt: invoices.createdAt, updatedAt: invoices.updatedAt, }) diff --git a/apps/web/src/pages/Invoices.tsx b/apps/web/src/pages/Invoices.tsx index 76dcbfd..a3094d9 100644 --- a/apps/web/src/pages/Invoices.tsx +++ b/apps/web/src/pages/Invoices.tsx @@ -173,22 +173,21 @@ function InvoiceDetailModal({ const [error, setError] = useState(null); const [tipStr, setTipStr] = useState((invoice.tipCents / 100).toFixed(2)); const [paymentMethod, setPaymentMethod] = useState(invoice.paymentMethod ?? "cash"); - const [showRefundDialog, setShowRefundDialog] = useState(false); +const [showRefundDialog, setShowRefundDialog] = useState(false); const [refundType, setRefundType] = useState<"full" | "partial">("full"); - const [partialAmount, setPartialAmount] = useState(""); - const [stripeDetails, setStripeDetails] = useState<{ cardLast4: string | null; paymentStatus: string | null; stripeRefundId: string | null } | null>(null); + const [refundAmount, setRefundAmount] = useState(""); + const [refundError, setRefundError] = useState(null); + const [refunding, setRefunding] = useState(false); - // Fetch Stripe details when modal opens for paid invoices with a payment intent + // Fetch current staff role to determine manager access + const [staffMe, setStaffMe] = useState<{ role: string; isSuperUser: boolean } | null>(null); useEffect(() => { - if (invoice.status === "paid" && invoice.stripePaymentIntentId) { - fetch(`/api/invoices/${invoice.id}/stripe-details`) - .then((r) => r.ok ? r.json() : null) - .then((data) => { if (data) setStripeDetails(data); }) - .catch(() => {}); - } else { - setStripeDetails(null); - } - }, [invoice.id, invoice.status, invoice.stripePaymentIntentId]); + fetch("/api/staff/me") + .then((r) => r.json()) + .then((d) => setStaffMe(d)) + .catch(() => setStaffMe(null)); + }, []); + const isManager = staffMe && (staffMe.role === "manager" || staffMe.isSuperUser); // Tip split state: array of {staffId, staffName, pct} const linkedAppt = invoice.appointmentId @@ -294,7 +293,7 @@ function InvoiceDetailModal({ async function issueRefund() { const amountCents = refundType === "partial" - ? Math.round(parseFloat(partialAmount) * 100) + ? Math.round(parseFloat(refundAmount) * 100) : undefined; if (refundType === "partial" && (!amountCents || amountCents <= 0)) { setError("Enter a valid refund amount"); @@ -380,15 +379,15 @@ function InvoiceDetailModal({ /> {invoice.paidAt && } {invoice.paymentMethod && } - {stripeDetails && ( + {invoice.stripePaymentIntentId && ( <> - {stripeDetails.cardLast4 && ( - + {invoice.cardLast4 && ( + )} - {stripeDetails.paymentStatus && ( - + {invoice.paymentStatus && ( + )} - {stripeDetails.stripeRefundId && ( + {invoice.stripeRefundId && ( )} @@ -510,77 +509,85 @@ function InvoiceDetailModal({ )} {(invoice.status === "paid" || invoice.status === "void") && ( -
- {invoice.status === "paid" && invoice.stripePaymentIntentId && ( - +
+ {invoice.stripeRefundId && ( +
+ Refunded +
)} - +
+ {invoice.status === "paid" && invoice.stripePaymentIntentId && !invoice.stripeRefundId && isManager && ( + + )} + +
)} - {/* Refund Dialog */} {showRefundDialog && ( - setShowRefundDialog(false)}> -

Issue Refund

-

- Invoice total: {fmtMoney(invoice.totalCents)} -

-
-