Add notification preferences and alternate dues payment options
Notification preferences (migration 048): - Per-member opt-out of muteable categories (bookings, classes, forms, admin alerts); billing is always-on. Opt-out model, default on. - Dispatcher reads prefs and marks muted outbox rows 'skipped' instead of sending; pure isMuted logic, fail-open on a prefs lookup error. - notification_preferences table (default-deny RLS); /me toggles and self-view via validated service-client actions. Alternate dues payment methods (migration 049): - Admin sets external pay-here URLs per platform (PayPal/Zeffy/Venmo) in /settings; members see active ones on /me and pay off-platform; the treasurer reconciles manually (platform pre-tagged). https-only. - dues_payment_methods table (SELECT space member, write admin/board). /me visual pass: - Restore the chip/preset profile editor (skills/interests/willing-to/ affiliations); promote ChipInput and presets to shared modules. - Gate the Stripe pay-dues button on whether the space has Stripe configured; show external links or a contact-admin note otherwise.
This commit is contained in:
@@ -5,25 +5,45 @@ import { toast } from 'sonner'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { startDuesCheckout, startBillingPortal } from '@/lib/actions'
|
||||
import { DUES_PLATFORM_LABEL, type DuesLinkPlatform } from '@/lib/dues-payments-logic'
|
||||
|
||||
type Billing = { status: string | null; currentPeriodEnd: string | null; hasCustomer: boolean } | null
|
||||
type Billing = {
|
||||
status: string | null
|
||||
currentPeriodEnd: string | null
|
||||
hasCustomer: boolean
|
||||
configured: boolean
|
||||
} | null
|
||||
|
||||
export type DuesMethod = {
|
||||
platform: string
|
||||
url: string
|
||||
instructions: string | null
|
||||
}
|
||||
|
||||
const PAID = new Set(['active', 'trialing'])
|
||||
|
||||
export function DuesCard({ billing }: { billing: Billing }) {
|
||||
const platformLabel = (p: string) =>
|
||||
DUES_PLATFORM_LABEL[p as DuesLinkPlatform] ?? p
|
||||
|
||||
export function DuesCard({ billing, methods = [] }: { billing: Billing; methods?: DuesMethod[] }) {
|
||||
const [busy, setBusy] = useState(false)
|
||||
const paid = !!billing?.status && PAID.has(billing.status)
|
||||
const stripeReady = !!billing?.configured
|
||||
const hasAltMethods = methods.length > 0
|
||||
|
||||
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) }
|
||||
if ('error' in res && res.error) {
|
||||
setBusy(false)
|
||||
return toast.error(res.error)
|
||||
}
|
||||
window.location.href = (res as { data: { url: string } }).data.url
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-card rounded border border-border p-4">
|
||||
<div className="flex items-center justify-between gap-3 flex-wrap">
|
||||
<div className="bg-card rounded-lg border border-border p-5 space-y-4">
|
||||
<div className="flex items-start justify-between gap-3 flex-wrap">
|
||||
<div>
|
||||
<p className="font-sans text-sm font-medium text-foreground">Membership dues</p>
|
||||
{billing?.status ? (
|
||||
@@ -41,18 +61,61 @@ export function DuesCard({ billing }: { billing: Billing }) {
|
||||
<Badge variant={paid ? 'default' : 'outline'}>{paid ? 'Current' : 'Action needed'}</Badge>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex gap-2 mt-3">
|
||||
{!paid && (
|
||||
<Button size="sm" disabled={busy} onClick={() => go(startDuesCheckout)}>
|
||||
{busy ? 'Opening…' : 'Pay dues'}
|
||||
</Button>
|
||||
)}
|
||||
{billing?.hasCustomer && (
|
||||
<Button size="sm" variant="outline" disabled={busy} onClick={() => go(startBillingPortal)}>
|
||||
Manage billing
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Stripe Checkout / Portal: only when the space has Stripe set up. */}
|
||||
{(stripeReady && (!paid || billing?.hasCustomer)) && (
|
||||
<div className="flex gap-2">
|
||||
{!paid && (
|
||||
<Button size="sm" disabled={busy} onClick={() => go(startDuesCheckout)}>
|
||||
{busy ? 'Opening…' : 'Pay dues with card'}
|
||||
</Button>
|
||||
)}
|
||||
{billing?.hasCustomer && (
|
||||
<Button size="sm" variant="outline" disabled={busy} onClick={() => go(startBillingPortal)}>
|
||||
Manage billing
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Admin-configured external links. Shown when the member still owes dues. */}
|
||||
{!paid && hasAltMethods && (
|
||||
<div className="space-y-2">
|
||||
<p className="font-mono text-[10px] uppercase tracking-widest text-muted-foreground">
|
||||
{stripeReady ? 'Other ways to pay' : 'Pay your dues'}
|
||||
</p>
|
||||
<div className="flex flex-col gap-2">
|
||||
{methods.map(m => (
|
||||
<a
|
||||
key={m.platform}
|
||||
href={m.url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="flex items-center justify-between gap-3 rounded border border-border bg-background px-3 py-2 hover:border-primary transition"
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<span className="font-sans text-sm text-foreground">Pay with {platformLabel(m.platform)}</span>
|
||||
{m.instructions && (
|
||||
<p className="font-sans text-xs text-muted-foreground mt-0.5">{m.instructions}</p>
|
||||
)}
|
||||
</div>
|
||||
<span className="font-mono text-[10px] text-muted-foreground shrink-0">open ↗</span>
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
<p className="font-sans text-xs text-muted-foreground">
|
||||
These open an external payment page. Your payment is recorded by a treasurer after it
|
||||
clears.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Nothing set up at all. */}
|
||||
{!paid && !stripeReady && !hasAltMethods && (
|
||||
<p className="font-sans text-sm text-muted-foreground">
|
||||
Online dues payment isn’t set up for this space yet. Contact an admin to pay your dues.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user