Files
gruperly/apps/web/src/features/admin/AdminPlansView.tsx
Jose Selesan aac142d324 feat(billing): configurable plans from the backoffice and MP payment notifications
Plans:
- Plan limits and Pro prices per country live in the database
  (plan_configs, plan_prices, seeded with the previous constants) and are
  read through PlanCatalog (30 s cache, defaults as fallback).
- /admin/plans edits limits (with the count of accounts that would become
  read-only) and prices, optionally pushing the new price to live
  subscriptions from their next charge (MP preapproval amount, Stripe item
  without proration) via the ApplyPriceChanges job, with an email and a
  notice on /billing.
- GET /billing/plans feeds the onboarding and the billing screen.

Mercado Pago:
- The Pro checkout returns through GET /billing/return on API_PUBLIC_URL,
  since MP refuses a back_url on localhost.
- The OAuth callback bounces from the tunnel to BETTER_AUTH_URL to find the
  session, requires the session to own the state, and redirects instead of
  answering JSON on unexpected errors.
- Checkout Pro links skip auto_return off public HTTPS and carry a
  notification_url to POST /payments/webhooks/mp/:paymentId, which confirms
  the payment with the owner's token (same rule as the polling job, which
  stays as fallback). The search now prefers the approved attempt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 07:50:14 -03:00

62 lines
2.3 KiB
TypeScript

import { Loader2 } from 'lucide-react'
import { Button } from '../../components/ui'
import { useAdminPlans } from './AdminPlansProvider'
import { PlanLimitsCard } from './PlanLimitsCard'
import { PlanPriceRow } from './PlanPriceRow'
import { useTranslation } from 'react-i18next'
export function AdminPlansView() {
const { plans, isPending, isError, errorMessage, retry } = useAdminPlans()
const { t } = useTranslation(['admin', 'common'])
return (
<section>
<h1 className="text-2xl font-bold text-primary">{t('plans.title')}</h1>
<p className="mt-1 text-sm text-foreground/60">{t('plans.subtitle')}</p>
{isPending ? (
<div className="mt-8 flex items-center justify-center py-16" role="status">
<Loader2 className="size-6 animate-spin text-secondary/50" aria-hidden="true" />
<span className="sr-only">{t('plans.loading')}</span>
</div>
) : null}
{isError ? (
<div className="mt-8 space-y-3 rounded-xl bg-danger-soft px-4 py-3 text-sm text-danger">
<p>{errorMessage}</p>
<Button variant="outline" size="sm" onClick={retry}>
{t('common:actions.retry')}
</Button>
</div>
) : null}
{plans ? (
<div className="mt-6 space-y-8">
<div>
<h2 className="text-sm font-semibold uppercase tracking-wide text-foreground/50">
{t('plans.limits.title')}
</h2>
<p className="mt-1 text-xs text-foreground/50">{t('plans.limits.hint')}</p>
<div className="mt-3 grid gap-4 sm:grid-cols-2">
<PlanLimitsCard plan="FREE" limits={plans.limits.FREE} />
<PlanLimitsCard plan="PRO" limits={plans.limits.PRO} />
</div>
</div>
<div>
<h2 className="text-sm font-semibold uppercase tracking-wide text-foreground/50">
{t('plans.prices.title')}
</h2>
<p className="mt-1 text-xs text-foreground/50">{t('plans.prices.hint')}</p>
<ul className="mt-3 divide-y divide-border rounded-xl border border-border bg-surface">
{plans.prices.map((price) => (
<PlanPriceRow key={price.country} price={price} />
))}
</ul>
</div>
</div>
) : null}
</section>
)
}