Skip to main content

Questionnaires

Flow

  1. Admin creates a template at /admin/questionnaires/new
  2. Admin sends a questionnaire from the lead detail → QuickActions → "Send Questionnaire"
  3. sendQuestionnaire (in app/actions/questionnaires.ts) emails the client a token link and saves a questionnaire_responses row to Supabase
  4. Client fills the form at /onboarding/[token] — no login required
  5. submitQuestionnaire marks the response complete and notifies admin
  6. Lead status advances to questionnaire

Data layer

  • Templates: lib/questionnaire-db.ts — Supabase CRUD (source of truth)
  • Responses: also in lib/questionnaire-db.ts via getResponseByToken
  • Legacy: lib/questionnaire-data.ts still exists but file-based helpers are unused — do not call them in new code

Types

// lib/questionnaire-types.ts
type QuestionnaireTemplate = { ... }
type QuestionnaireResponse = { ... }

Both use camelCase — the DB layer maps snake_case rows before returning.

Important

  • Import template functions from questionnaire-db.ts, never from questionnaire-data.ts
  • 'use server' belongs only in app/actions/lib/ files use import 'server-only'