import { useState } from "react"; import { apiPatch } from "../api/http"; import { formatDateInTimezone } from "../utils/timezone"; interface EarlyFundingModalProps { planId: string; planName: string; nextDueDate?: string; timezone: string; onClose: () => void; } export default function EarlyFundingModal({ planId, planName, nextDueDate, timezone, onClose }: EarlyFundingModalProps) { const [loading, setLoading] = useState(false); const handleResponse = async (enableEarlyFunding: boolean) => { setLoading(true); try { await apiPatch(`/fixed-plans/${planId}/early-funding`, { enableEarlyFunding }); onClose(); } catch (error) { console.error("Failed to update early funding:", error); // Still close the modal even if it fails onClose(); } finally { setLoading(false); } }; const nextDueLabel = nextDueDate ? formatDateInTimezone(nextDueDate, timezone, { month: 'long', day: 'numeric', year: 'numeric' }) : "next billing cycle"; return (
You've paid {planName} which is due on {nextDueLabel}.
Would you like to start funding for the next payment now, or wait until closer to the due date?
Start Now: Your next income will begin funding this bill.
Wait: Funding will resume automatically on {nextDueLabel}.