Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot]
2026-04-26 08:51:42 +00:00
co-authored by renee-png
parent b72c83d7d3
commit 7ac19ab20d
@@ -65,7 +65,13 @@ function addInterval(dateStr: string, frequency: Frequency, n: number) {
return d.toISOString().slice(0, 10);
}
export function PaymentPlansPanel({ collectionId }: { collectionId: string }) {
export function PaymentPlansPanel({
collectionId,
caseId,
}: {
collectionId: string;
caseId?: string | null;
}) {
const { user } = useAuth();
const [plans, setPlans] = useState<Plan[]>([]);
const [installments, setInstallments] = useState<Record<string, Installment[]>>({});
@@ -119,6 +125,25 @@ export function PaymentPlansPanel({ collectionId }: { collectionId: string }) {
else load();
};
const updatePaidAmount = async (id: string, value: string) => {
const num = value === "" ? null : parseFloat(value) || 0;
setInstallments((prev) => {
const next: Record<string, Installment[]> = {};
Object.entries(prev).forEach(([k, list]) => {
next[k] = list.map((x) => (x.id === id ? { ...x, paid_amount: num } : x));
});
return next;
});
const { error } = await supabase
.from("payment_plan_installments")
.update({ paid_amount: num })
.eq("id", id);
if (error) {
toast.error("Could not save", { description: error.message });
load();
}
};
const updatePlanStatus = async (planId: string, status: PlanStatus) => {
const { error } = await supabase
.from("payment_plans")