A new member who joins via invite code now walks through an admin-defined onboarding sequence before reaching the app. Schema (migration 022, folded into schema.sql Section 14): - space_onboarding_steps: step_key, step_type (welcome|code_of_conduct|profile|payment|content), title, body, config jsonb, is_enabled, is_required, is_system, sort_order, unique per (space, step_key). Full RLS: members read, admin/board write, admin delete non-system. - space_members.onboarding_completed_at + onboarding_progress jsonb. - Trigger seeds four default steps per space (welcome, code of conduct [required], profile, dues). Backfill seeds existing spaces and marks all existing members complete so the new gate never traps them. Flow: - /onboarding (top-level route, outside the (app) group so no redirect loop). Progress bar, step counter, back/continue, per-type rendering. Profile step calls updateMyProfile; payment step is a non-blocking nudge with optional link and "Remind me later". - (app)/layout.tsx redirects to /onboarding while onboarding_completed_at is null. - createSpace marks the founder complete: founders configure the space, they do not run the member flow (matches admin-vs-end-user persona research). - finishOnboarding re-checks required steps server-side so a tampered client cannot skip a required code-of-conduct acknowledgement. skipOnboarding only works when nothing is required. Admin config: - Settings -> Onboarding tab: reorder, edit title/body/payment link, toggle enabled/required, add custom content steps, delete non-system steps. Safety: - components/safe-markdown.tsx renders admin-authored markdown and a sanitized subset of HTML (rehype-raw + rehype-sanitize). Added those two deps. Also: - bio added to updateMyProfileSchema (members can self-set it; not blocked by the migration-015 trigger). - docs/UX_AND_PERSONAS.md: 4 personas and prioritized UX audit findings. Onboarding was finding #1; 2-6 deferred and tracked. 266/266 unit tests pass. Production build clean, /onboarding in the route table. Migration 022 applies idempotently on the next deploy.
65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import { redirect } from 'next/navigation'
|
|
import { createClient } from '@/lib/supabase/server'
|
|
import { OnboardingFlow } from './onboarding-flow'
|
|
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
export default async function OnboardingPage() {
|
|
const supabase = await createClient()
|
|
const { data: { user } } = await supabase.auth.getUser()
|
|
if (!user) redirect('/login')
|
|
|
|
const { data: member } = await supabase
|
|
.from('space_members')
|
|
.select('id, space_id, display_name, handle, bio, phone, skills, interests, onboarding_completed_at, spaces(name)')
|
|
.eq('user_id', user.id)
|
|
.in('status', ['current', 'unverified', 'late'])
|
|
.order('joined_at', { ascending: true })
|
|
.limit(1)
|
|
.maybeSingle()
|
|
|
|
if (!member) redirect(`/signup?email=${encodeURIComponent(user.email || '')}`)
|
|
if (member.onboarding_completed_at) redirect('/dashboard')
|
|
|
|
const { data: steps } = await supabase
|
|
.from('space_onboarding_steps')
|
|
.select('id, step_key, step_type, title, body, config, is_required')
|
|
.eq('space_id', member.space_id)
|
|
.eq('is_enabled', true)
|
|
.order('sort_order', { ascending: true })
|
|
|
|
// No steps configured: nothing to show. Mark complete and move on.
|
|
if (!steps || steps.length === 0) {
|
|
await supabase
|
|
.from('space_members')
|
|
.update({ onboarding_completed_at: new Date().toISOString() })
|
|
.eq('id', member.id)
|
|
redirect('/dashboard')
|
|
}
|
|
|
|
const canSkip = !steps.some(s => s.is_required)
|
|
const spaceName = (member.spaces as { name?: string } | null)?.name ?? 'your space'
|
|
|
|
return (
|
|
<OnboardingFlow
|
|
spaceName={spaceName}
|
|
steps={steps.map(s => ({
|
|
id: s.id,
|
|
step_type: s.step_type as 'welcome' | 'code_of_conduct' | 'profile' | 'payment' | 'content',
|
|
title: s.title,
|
|
body: s.body,
|
|
config: (s.config ?? {}) as Record<string, unknown>,
|
|
is_required: s.is_required,
|
|
}))}
|
|
canSkip={canSkip}
|
|
profile={{
|
|
display_name: member.display_name ?? '',
|
|
handle: member.handle ?? '',
|
|
bio: member.bio ?? '',
|
|
skills: (member.skills as string[] | null) ?? [],
|
|
interests: (member.interests as string[] | null) ?? [],
|
|
}}
|
|
/>
|
|
)
|
|
}
|