Adds proposals + proposal_votes + policies + incidents + incident_updates
tables with full RLS, async voting flow, dismissal-appeal pathway,
versioned policies with provenance, and an anonymous-incident token mode.
Adds per-space configurable areas, financial visibility settings, member
self-profile + COI disclosure, and a mission statement that renders in
the app footer.
Reorganises lib/actions.ts into per-domain files (tasks, projects,
members, payments, contacts, knowledge-base, secrets, area-leads,
settings, imports, proposals, incidents, policies, areas) plus a barrel.
Adds lib/permissions.ts and lib/auth-helpers.ts so action bodies stop
duplicating the user-to-member-to-role check. Wires every action that has
a Zod schema; introduces a flexibleDateTime preprocessor so HTML date
pickers no longer hit "Invalid datetime".
Hardens RLS: drops NOT NULL on space_members.user_id for offline members,
adds a privilege-escalation trigger that blocks self-edits to role / tier
/ status / approved / has_card_access / space_id, closes four
cross-tenant holes in the governance kernel, and adds a partial unique
index so two admins cannot concurrently activate two drafts of the same
policy slug.
Ships every deployment artifact: Dockerfile, docker-compose,
.do/app.yaml, .env.example, /api/health, plus a managed-Supabase guide
(docs/DEPLOYMENT.md), an end-to-end self-hosted Droplet guide
(docs/DEPLOY_DO_SELFHOSTED.md), and a Supabase-CLI local-dev quickstart
(docs/LOCAL_DEV.md). Replaces middleware.ts with proxy.ts for Next.js 16.
Adds scripts/schema.sql as the canonical idempotent full deploy plus
fourteen numbered incremental migrations.
Adds scripts/seed.sql so a fresh local DB renders something instead of
empty pages: a demo space, five members across all roles, a v1 code of
conduct, three proposals in different states with seven votes already
cast, an open incident, a project, three tasks, a KB entry, and matching
activity-log rows.
Replaces v0-generated test scaffolding with 266 real tests across
__tests__/{actions,auth-helpers,components,governance,permissions,
security,utils,validations}.test.ts. Adds react-markdown + remark-gfm
for proposal / incident / policy body rendering. Deletes four dead v0
fix-* scripts, the unused components/app-shell.tsx, and the duplicate
app/auth/login/page.tsx.
Routes (31 total): /api/health, /api/paypal/sync, /auth/callback, /,
/login, /signup, /signup/confirm, /dashboard, /tasks, /projects,
/members, /payments, /financials, /contacts, /ops, /ops/[id], /ops/new,
/proposals, /proposals/[id], /proposals/new, /incidents, /incidents/[id],
/incidents/new, /policies, /policies/[slug], /policies/new, /profile,
/recruitment, /settings, /comms, /import.
Full pass-by-pass history is in docs/HANDOFF.md; the roadmap is in
docs/GOVERNANCE_FEATURES.md.
200 lines
6.9 KiB
TypeScript
200 lines
6.9 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { useRouter } from 'next/navigation'
|
|
import Link from 'next/link'
|
|
import { fileIncident } from '@/lib/actions'
|
|
import { incidentSeverities } from '@/lib/validations'
|
|
|
|
type Member = { id: string; display_name: string | null }
|
|
|
|
export function IncidentForm({ members }: { members: Member[] }) {
|
|
const router = useRouter()
|
|
const [title, setTitle] = useState('')
|
|
const [body, setBody] = useState('')
|
|
const [category, setCategory] = useState('general')
|
|
const [severity, setSeverity] = useState<string>('medium')
|
|
const [subjects, setSubjects] = useState<string[]>([])
|
|
const [isAnonymous, setIsAnonymous] = useState(false)
|
|
const [error, setError] = useState('')
|
|
const [submitting, setSubmitting] = useState(false)
|
|
const [token, setToken] = useState<string | null>(null)
|
|
|
|
function toggleSubject(id: string) {
|
|
setSubjects(prev => (prev.includes(id) ? prev.filter(x => x !== id) : [...prev, id]))
|
|
}
|
|
|
|
async function handleSubmit(e: React.FormEvent) {
|
|
e.preventDefault()
|
|
setSubmitting(true)
|
|
setError('')
|
|
|
|
const result = await fileIncident({
|
|
title,
|
|
body,
|
|
category,
|
|
severity,
|
|
subjects,
|
|
is_anonymous: isAnonymous,
|
|
})
|
|
|
|
if ('error' in result && result.error) {
|
|
setError(result.error)
|
|
setSubmitting(false)
|
|
return
|
|
}
|
|
|
|
if (isAnonymous && 'token' in result && result.token) {
|
|
setToken(result.token as string)
|
|
setSubmitting(false)
|
|
return
|
|
}
|
|
|
|
if ('data' in result && result.data) {
|
|
router.push(`/incidents/${(result.data as { id: string }).id}`)
|
|
} else {
|
|
router.push('/incidents')
|
|
}
|
|
}
|
|
|
|
if (token) {
|
|
return (
|
|
<div className="bg-card rounded border border-border p-5 space-y-3">
|
|
<p className="font-mono text-[10px] tracking-widest text-muted-foreground uppercase">Report filed anonymously</p>
|
|
<p className="font-sans text-sm text-foreground">
|
|
Save this tracking token. It is the only way to look the report up later. We never email
|
|
or display it elsewhere.
|
|
</p>
|
|
<pre className="bg-background border border-border rounded p-3 font-mono text-sm break-all">{token}</pre>
|
|
<Link
|
|
href="/incidents"
|
|
className="inline-block bg-primary text-white font-sans text-sm font-medium px-4 py-2 rounded hover:bg-primary/90 transition"
|
|
>
|
|
Done
|
|
</Link>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit} className="space-y-5 bg-card rounded border border-border p-5">
|
|
<div>
|
|
<label className="font-mono text-[10px] tracking-widest text-muted-foreground uppercase block mb-1">
|
|
Title
|
|
</label>
|
|
<input
|
|
type="text"
|
|
value={title}
|
|
onChange={e => setTitle(e.target.value)}
|
|
maxLength={200}
|
|
required
|
|
className="w-full bg-background border border-border text-foreground font-sans text-sm rounded px-3 py-2 focus:outline-none focus:border-primary"
|
|
placeholder="Brief summary"
|
|
/>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="font-mono text-[10px] tracking-widest text-muted-foreground uppercase block mb-1">
|
|
What happened
|
|
</label>
|
|
<textarea
|
|
value={body}
|
|
onChange={e => setBody(e.target.value)}
|
|
rows={8}
|
|
maxLength={20000}
|
|
required
|
|
className="w-full bg-background border border-border text-foreground font-sans text-sm rounded px-3 py-2 focus:outline-none focus:border-primary"
|
|
placeholder="When, where, who was present, what was said or done."
|
|
/>
|
|
</div>
|
|
|
|
<div className="grid md:grid-cols-2 gap-4">
|
|
<div>
|
|
<label className="font-mono text-[10px] tracking-widest text-muted-foreground uppercase block mb-1">
|
|
Category
|
|
</label>
|
|
<input
|
|
type="text"
|
|
value={category}
|
|
onChange={e => setCategory(e.target.value)}
|
|
maxLength={50}
|
|
className="w-full bg-background border border-border text-foreground font-sans text-sm rounded px-3 py-2 focus:outline-none focus:border-primary"
|
|
placeholder="general, safety, harassment, theft..."
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="font-mono text-[10px] tracking-widest text-muted-foreground uppercase block mb-1">
|
|
Severity
|
|
</label>
|
|
<select
|
|
value={severity}
|
|
onChange={e => setSeverity(e.target.value)}
|
|
className="w-full bg-background border border-border text-foreground font-sans text-sm rounded px-3 py-2 focus:outline-none focus:border-primary"
|
|
>
|
|
{incidentSeverities.map(s => (
|
|
<option key={s} value={s}>{s}</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="font-mono text-[10px] tracking-widest text-muted-foreground uppercase block mb-2">
|
|
Subjects (optional)
|
|
</label>
|
|
<div className="bg-background border border-border rounded p-3 max-h-48 overflow-y-auto">
|
|
{members.length === 0 ? (
|
|
<p className="font-sans text-xs text-muted-foreground">No other members in the space.</p>
|
|
) : (
|
|
members.map(m => (
|
|
<label key={m.id} className="flex items-center gap-2 py-1 text-sm">
|
|
<input
|
|
type="checkbox"
|
|
checked={subjects.includes(m.id)}
|
|
onChange={() => toggleSubject(m.id)}
|
|
className="rounded border-border"
|
|
/>
|
|
<span className="font-sans">{m.display_name ?? 'Unnamed'}</span>
|
|
</label>
|
|
))
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="flex items-start gap-2 text-sm">
|
|
<input
|
|
type="checkbox"
|
|
checked={isAnonymous}
|
|
onChange={e => setIsAnonymous(e.target.checked)}
|
|
className="rounded border-border mt-0.5"
|
|
/>
|
|
<span className="font-sans">
|
|
File anonymously. Your name is omitted from the record. You will get a tracking
|
|
token in exchange. Be aware: an admin with direct database access can still see
|
|
the row exists; this is not cryptographic anonymity.
|
|
</span>
|
|
</label>
|
|
</div>
|
|
|
|
{error && <p className="font-mono text-xs text-red-500">{error}</p>}
|
|
|
|
<div className="flex items-center justify-end gap-3">
|
|
<Link
|
|
href="/incidents"
|
|
className="font-sans text-sm text-muted-foreground hover:text-foreground"
|
|
>
|
|
Cancel
|
|
</Link>
|
|
<button
|
|
type="submit"
|
|
disabled={submitting || !title.trim() || !body.trim()}
|
|
className="bg-primary text-white font-sans text-sm font-medium px-4 py-2 rounded hover:bg-primary/90 transition disabled:opacity-50"
|
|
>
|
|
{submitting ? 'Submitting...' : 'File report'}
|
|
</button>
|
|
</div>
|
|
</form>
|
|
)
|
|
}
|