diff --git a/app/(app)/clients/page.tsx b/app/(app)/clients/page.tsx index 06e3494..2d26890 100644 --- a/app/(app)/clients/page.tsx +++ b/app/(app)/clients/page.tsx @@ -53,11 +53,21 @@ export default function ClientsPage() { queryFn: async () => { const r = await api.get("/api/v1/areas"); return r.data; }, }); - const { data: plans = [] } = useQuery({ - queryKey: ["plans"], - queryFn: async () => { const r = await api.get("/api/v1/plans"); return Array.isArray(r.data) ? r.data : (r.data as any).data ?? []; }, + // Fetch only active plans, filter client-side by billing type + const { data: allActivePlans = [] } = useQuery<(Plan & { type: string; isActive: boolean })[]>({ + queryKey: ["plans", "active"], + queryFn: async () => { + const r = await api.get("/api/v1/plans?isActive=true"); + const raw = Array.isArray(r.data) ? r.data : (r.data as any).data ?? []; + return raw; + }, }); + // Filter plans by selected billing type + const filteredPlans = allActivePlans.filter(p => + !form.billingType || p.type === form.billingType + ); + const createClient = useMutation({ mutationFn: async () => { const res = await api.post("/api/v1/clients", { @@ -186,10 +196,11 @@ export default function ClientsPage() { Billing Type setForm(f => ({ ...f, billingType: e.target.value }))}> + value={form.billingType} onChange={e => setForm(f => ({ ...f, billingType: e.target.value, planId: "" }))}> Postpaid Prepaid + Plan list filters to match this type @@ -197,8 +208,11 @@ export default function ClientsPage() { setForm(f => ({ ...f, planId: e.target.value }))}> — Select plan — - {plans.map(p => {p.name} — ₱{Number(p.monthlyPrice).toLocaleString()}/mo)} + {filteredPlans.map(p => {p.name} — ₱{Number(p.monthlyPrice).toLocaleString()}/mo)} + {filteredPlans.length === 0 && form.billingType && ( + No active {form.billingType.toLowerCase()} plans available. + )} setShowAdd(false)}>Cancel
Plan list filters to match this type
No active {form.billingType.toLowerCase()} plans available.