'use client' import { useState, useTransition } from 'react' import { useRouter } from 'next/navigation' import { supersedePolicy, updatePolicyStatus } from '@/lib/actions' import { policyStatuses } from '@/lib/validations' import type { Policy } from '@/lib/types' export function PolicyActions({ policy }: { policy: Policy }) { const router = useRouter() const [isPending, startTransition] = useTransition() const [error, setError] = useState('') const [showSupersede, setShowSupersede] = useState(false) const [newBody, setNewBody] = useState(policy.body_formal) const [newPlain, setNewPlain] = useState(policy.body_plain ?? '') function run(fn: () => Promise, after?: () => void) { setError('') startTransition(async () => { const r = (await fn()) as unknown as { error?: string } if (r && r.error) setError(r.error) else after?.() router.refresh() }) } return (

Manage

{policy.status !== 'active' && ( )} {policy.status === 'active' && ( <> )} {policyStatuses .filter(s => s !== policy.status && s !== 'active') .map(s => ( ))}
{showSupersede && (

Supersede v{policy.version} with v{policy.version + 1}