import { createFileRoute, useSearch } from "@tanstack/react-router"; import { useEffect, useState } from "react"; import { Card, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { CheckCircle2, CreditCard, XCircle, Loader2 } from "lucide-react"; import { formatCurrency } from "@/lib/format"; import { getPublicPaymentRequest, startPublicCheckout } from "@/lib/payments.functions"; import { JusticeIcon } from "@/components/justice-icon"; import { toast } from "sonner"; export const Route = createFileRoute("/pay/$id")({ validateSearch: (s: Record) => ({ status: typeof s.status === "string" ? (s.status as string) : undefined, }), loader: async ({ params }) => { return getPublicPaymentRequest({ data: { id: params.id } }); }, component: PayPage, errorComponent: () => (

Payment request not found.

), }); function Shell({ children }: { children: React.ReactNode }) { return (
Stage Law Firm, PLLC
{children}
); } function PayPage() { const data = Route.useLoaderData(); const search = useSearch({ from: "/pay/$id" }); const [row, setRow] = useState(data); const [starting, setStarting] = useState(false); useEffect(() => { setRow(data); }, [data]); if (search.status === "success" || row.status === "paid") { return (

Payment received

Thank you, {row.recipient_name}. Your payment of{" "} {formatCurrency(row.total_amount_cents / 100)} has been received.

); } if (row.status === "canceled") { return (

Payment canceled

This payment request is no longer active. Please contact our office.

); } return (

Payment request

For {row.recipient_name}

{row.description && (

{row.description}

)}
Amount {formatCurrency(row.base_amount_cents / 100)}
Processing fee {formatCurrency(row.fee_amount_cents / 100)}
Total {formatCurrency(row.total_amount_cents / 100)}
{search.status === "cancel" && (

Payment was not completed. You can try again above.

)}
); }