'use client' import { useState, useTransition } from 'react' import { uuidv7 } from '@/lib/uuidv7' import { departmentEntryText, departmentText } from '@/lib/i18n/departments' import { commonText } from '@/lib/i18n/common' import { createEntryAction, editEntryAction, retractEntryAction } from './actions' export type EntryView = { id: string body: string minClearance: number authorId: string authorName: string createdAt: string version: number editedAt: string | null retractedAt: string | null retractedByName: string | null retractionReason: string | null } /** * Die Vermerke einer Abteilung. * * Dieselbe Zusicherung wie im Verlauf einer Akte, und sie steht auch so da: * ein geänderter Vermerk trägt seine Fassungsnummer, ein zurückgezogener * bleibt als Grabstein mit Grund und Namen stehen. Nichts verschwindet. */ export function DepartmentEntries({ departmentKey, entries, currentUserId, canWrite, canRetract, canEditAny, canEditOwn, levels, }: { departmentKey: string entries: EntryView[] currentUserId: string canWrite: boolean canRetract: boolean canEditAny: boolean canEditOwn: boolean levels: { level: number; name: string }[] }) { const [liste, setListe] = useState(entries) const [text, setText] = useState('') const [stufe, setStufe] = useState(0) const [fehler, setFehler] = useState(null) const [pending, startTransition] = useTransition() function schreiben() { const inhalt = text.trim() if (!inhalt) return const id = uuidv7() setFehler(null) startTransition(async () => { const ergebnis = await createEntryAction({ id, departmentKey, body: inhalt, minClearance: stufe, }) if (!ergebnis.ok) { setFehler(ergebnis.error) return } setListe((bisher) => [ { id, body: inhalt, minClearance: stufe, authorId: currentUserId, authorName: '', createdAt: new Date().toISOString(), version: 1, editedAt: null, retractedAt: null, retractedByName: null, retractionReason: null, }, ...bisher, ]) setText('') }) } return (
{canWrite ? (