diff --git a/admin/src/app/api/plans/route.ts b/admin/src/app/api/plans/route.ts index 3717e02..e6407a5 100644 --- a/admin/src/app/api/plans/route.ts +++ b/admin/src/app/api/plans/route.ts @@ -10,7 +10,7 @@ export async function GET() { COALESCE(p.max_professionals, 1) as "maxProfessionals", COALESCE(p.max_services, 10) as "maxServices", p.features, p.is_active as active, - (SELECT COUNT(*) FROM tenants WHERE active_plan_id = p.id) as subscribers + (SELECT COUNT(*) FROM subscriptions WHERE plan_id = p.id AND status = 'active') as subscribers FROM plans p ORDER BY p.price ASC `); @@ -39,7 +39,7 @@ export async function GET() { COALESCE(p.max_professionals, 1) as "maxProfessionals", COALESCE(p.max_services, 10) as "maxServices", p.features, p.is_active as active, - (SELECT COUNT(*) FROM tenants WHERE active_plan_id = p.id) as subscribers + (SELECT COUNT(*) FROM subscriptions WHERE plan_id = p.id AND status = 'active') as subscribers FROM plans p ORDER BY p.price ASC `); diff --git a/admin/src/components/Plans.tsx b/admin/src/components/Plans.tsx index b37a4fb..169b92c 100644 --- a/admin/src/components/Plans.tsx +++ b/admin/src/components/Plans.tsx @@ -40,7 +40,9 @@ export default function Plans() { const res = await fetch('/api/plans'); if (res.ok) { const data = await res.json(); - setPlans(data); + if (Array.isArray(data)) { + setPlans(data); + } } } catch (e) { console.error(e);