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:
@@ -0,0 +1,124 @@
|
||||
'use server'
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import { requireMember, requireMemberWithRole, parseInput } from '@/lib/auth-helpers'
|
||||
import { ADMIN_ROLES } from '@/lib/permissions'
|
||||
import { duesPaymentMethodSchema } from '@/lib/validations'
|
||||
|
||||
export type DuesPaymentMethod = {
|
||||
platform: string
|
||||
url: string
|
||||
instructions: string | null
|
||||
isActive: boolean
|
||||
sortOrder: number
|
||||
}
|
||||
|
||||
// Member-facing: the ACTIVE external dues payment links for the caller's space,
|
||||
// in display order. RLS (SELECT = space member) scopes this; we still pin
|
||||
// space_id for clarity. Used by the /me dues UI to render click-out buttons.
|
||||
export async function listActiveDuesPaymentMethods(): Promise<
|
||||
{ data: DuesPaymentMethod[] } | { error: string }
|
||||
> {
|
||||
const supabase = await createClient()
|
||||
const auth = await requireMember(supabase)
|
||||
if (!auth.ok) return { error: auth.error }
|
||||
const { member } = auth
|
||||
|
||||
const { data } = await supabase
|
||||
.from('dues_payment_methods')
|
||||
.select('platform, url, instructions, is_active, sort_order')
|
||||
.eq('space_id', member.space_id)
|
||||
.eq('is_active', true)
|
||||
.order('sort_order', { ascending: true })
|
||||
|
||||
return { data: (data ?? []).map(toMethod) }
|
||||
}
|
||||
|
||||
// Admin-facing: every configured method (active + inactive) for the management
|
||||
// UI in /settings.
|
||||
export async function listDuesPaymentMethods(): Promise<
|
||||
{ data: DuesPaymentMethod[] } | { error: string }
|
||||
> {
|
||||
const supabase = await createClient()
|
||||
const auth = await requireMemberWithRole(supabase, ADMIN_ROLES, 'Admin access required')
|
||||
if (!auth.ok) return { error: auth.error }
|
||||
const { member } = auth
|
||||
|
||||
const { data } = await supabase
|
||||
.from('dues_payment_methods')
|
||||
.select('platform, url, instructions, is_active, sort_order')
|
||||
.eq('space_id', member.space_id)
|
||||
.order('sort_order', { ascending: true })
|
||||
|
||||
return { data: (data ?? []).map(toMethod) }
|
||||
}
|
||||
|
||||
// Admin: create or update the link for one platform (idempotent on
|
||||
// (space_id, platform)). The RLS write policies re-check the admin/board role.
|
||||
export async function upsertDuesPaymentMethod(
|
||||
input: unknown,
|
||||
): Promise<{ ok: true } | { error: string }> {
|
||||
const supabase = await createClient()
|
||||
const auth = await requireMemberWithRole(supabase, ADMIN_ROLES, 'Admin access required')
|
||||
if (!auth.ok) return { error: auth.error }
|
||||
const { member } = auth
|
||||
|
||||
const v = parseInput(duesPaymentMethodSchema, input)
|
||||
if (!v.ok) return { error: v.error }
|
||||
const s = v.data
|
||||
|
||||
const { error } = await supabase.from('dues_payment_methods').upsert(
|
||||
{
|
||||
space_id: member.space_id,
|
||||
platform: s.platform,
|
||||
url: s.url,
|
||||
instructions: s.instructions ?? null,
|
||||
is_active: s.is_active ?? true,
|
||||
sort_order: s.sort_order ?? 0,
|
||||
},
|
||||
{ onConflict: 'space_id,platform' },
|
||||
)
|
||||
if (error) return { error: 'Could not save the payment method.' }
|
||||
|
||||
revalidatePath('/settings')
|
||||
revalidatePath('/me')
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
// Admin: remove the link for one platform entirely.
|
||||
export async function deleteDuesPaymentMethod(input: {
|
||||
platform: string
|
||||
}): Promise<{ ok: true } | { error: string }> {
|
||||
const supabase = await createClient()
|
||||
const auth = await requireMemberWithRole(supabase, ADMIN_ROLES, 'Admin access required')
|
||||
if (!auth.ok) return { error: auth.error }
|
||||
const { member } = auth
|
||||
|
||||
const { error } = await supabase
|
||||
.from('dues_payment_methods')
|
||||
.delete()
|
||||
.eq('space_id', member.space_id)
|
||||
.eq('platform', input.platform)
|
||||
if (error) return { error: 'Could not remove the payment method.' }
|
||||
|
||||
revalidatePath('/settings')
|
||||
revalidatePath('/me')
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
function toMethod(r: {
|
||||
platform: string
|
||||
url: string
|
||||
instructions: string | null
|
||||
is_active: boolean
|
||||
sort_order: number
|
||||
}): DuesPaymentMethod {
|
||||
return {
|
||||
platform: r.platform,
|
||||
url: r.url,
|
||||
instructions: r.instructions ?? null,
|
||||
isActive: r.is_active,
|
||||
sortOrder: r.sort_order,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user