'use client' import { useCallback, useState } from 'react' import { useTranslations } from 'next-intl' import { getTemplateOrDefaultClient } from '@nextsparkjs/registries/template-registry.client' import { PricingTable } from '@nextsparkjs/core/components/billing' import { fetchWithTeam } from '@nextsparkjs/core/lib/api/entities' import { toast } from 'sonner' /** * Plans Settings Page * * Displays the pricing table with plan comparison. * Users can select a plan to initiate checkout. */ function PlansPage() { const t = useTranslations('settings') const [loading, setLoading] = useState(null) const handleSelectPlan = useCallback(async (planSlug: string) => { setLoading(planSlug) try { const res = await fetchWithTeam('/api/v1/billing/checkout', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ planSlug, billingPeriod: 'monthly' }), }) const data = await res.json() if (data.success && data.data?.url) { // New subscription — redirect to provider checkout window.location.href = data.data.url } else if (data.success && data.data?.changed) { // Plan changed via proration (existing subscription) toast.success('Plan changed successfully') window.location.reload() } else { toast.error(data.error || 'Failed to process plan change') } } catch { toast.error('Failed to start checkout') } finally { setLoading(null) } }, []) return (
{/* Header */}

{t('plans.title')}

{t('plans.description')}

{/* Pricing Table */}
) } export default getTemplateOrDefaultClient('app/dashboard/settings/plans/page.tsx', PlansPage)