'use client' import { useState } from 'react' import { toast } from 'sonner' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { startDuesCheckout, startBillingPortal } from '@/lib/actions' type Billing = { status: string | null; currentPeriodEnd: string | null; hasCustomer: boolean } | null const PAID = new Set(['active', 'trialing']) export function DuesCard({ billing }: { billing: Billing }) { const [busy, setBusy] = useState(false) const paid = !!billing?.status && PAID.has(billing.status) async function go(fn: () => Promise<{ error?: string } | { data: { url: string } }>) { setBusy(true) const res = await fn() if ('error' in res && res.error) { setBusy(false); return toast.error(res.error) } window.location.href = (res as { data: { url: string } }).data.url } return (
Membership dues
{billing?.status ? ({billing.status} {billing.currentPeriodEnd ? ` · renews ${new Date(billing.currentPeriodEnd).toLocaleDateString()}` : ''}
) : (No active dues subscription.
)}