Phase 4 abgeschlossen: Personalakten, Dokumente, Beteiligte, Verknüpfungen
Die Dokumentebene aus docs/13 ist gebaut, additiv: Document, DocumentSection und DocumentSectionVersion neben Case, CaseSection und CaseEntry. Ein Dokument hängt an einer Fallakte, an einer Personalakte oder an nichts, höchstens an einem — gesichert durch eine CHECK-Bedingung. Es gibt kein DELETE; eine Zurücknahme lässt einen Grabstein stehen, der auch für den Admin zu ist. Eine neue Dokumentart ist damit ein Datensatz, kein Deployment. Im Seed stehen vier: vermerk, vorfallsbericht, sonderarbeitsvertrag (mehrseitiger Vertragstext mit Platzhaltern und Unterschriftenzeilen) und bussgeld. Zwei Umbenennungen, beide von Hand migriert, damit die vorhandenen Zeilen und Zählerstände stehen bleiben: - CaseTemplate -> DocumentTemplate, plus uses[] und layout - CaseCounter -> NumberSeries, ein Nummernkreis je Präfix für Aktenzeichen und Dokumentnummern Die Regeln für Abschnitte stehen jetzt einmal in lib/sections/render.ts und gelten für Fallakten und Dokumente gleichermaßen. Die Frage aus docs/13, ob CaseSection langfristig in die Dokumentebene wandert, ist damit verneint und begründet. Rückverweise auf der Personalakte laufen durch visibleCaseWhere, die Zahl daneben entsteht aus dem gefilterten Ergebnis. Auch die Rollengruppe verschwindet mit, sonst verriete "Betroffener" ohne Eintrag die Ermittlung. Die eigene Personalakte ist keine Ausnahme von der Freigabestufe. Vier neue Rechte: document.create, .edit, .finalize, .retract. Das letzte steht bei den zurückgehaltenen, es greift in Geschriebenes ein. 91 Tests im Web-Paket, 15 in der Datenbank, 28 e2e. Größte Route 118 kB gegen das Budget von 120 kB — die Luft wird knapp.
This commit is contained in:
@@ -24,7 +24,7 @@ export async function savePolicy(input: unknown): Promise<PolicyResult> {
|
||||
const user = await requirePermissionForAction('admin')
|
||||
|
||||
const parsed = schema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, error: de.case.errors.default! }
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors.default! }
|
||||
|
||||
const before = await db.appSetting.findUnique({ where: { id: 1 } })
|
||||
|
||||
|
||||
@@ -36,13 +36,13 @@ export async function saveTemplate(input: unknown): Promise<TemplateResult> {
|
||||
const erste = parsed.error.issues[0]
|
||||
return {
|
||||
ok: false,
|
||||
error: erste ? `${erste.path.join('.')}: ${erste.message}` : de.case.errors.default!,
|
||||
error: erste ? `${erste.path.join('.')}: ${erste.message}` : de.actionErrors.default!,
|
||||
}
|
||||
}
|
||||
|
||||
const { key, fields, ...rest } = parsed.data
|
||||
|
||||
const neueste = await db.caseTemplate.findFirst({
|
||||
const neueste = await db.documentTemplate.findFirst({
|
||||
where: { key },
|
||||
orderBy: { version: 'desc' },
|
||||
select: { version: true },
|
||||
@@ -51,9 +51,9 @@ export async function saveTemplate(input: unknown): Promise<TemplateResult> {
|
||||
|
||||
await db.$transaction(async (tx) => {
|
||||
// Ältere Versionen bleiben stehen, aber nur die neueste ist auswählbar.
|
||||
await tx.caseTemplate.updateMany({ where: { key }, data: { isActive: false } })
|
||||
await tx.documentTemplate.updateMany({ where: { key }, data: { isActive: false } })
|
||||
|
||||
await tx.caseTemplate.create({
|
||||
await tx.documentTemplate.create({
|
||||
data: {
|
||||
key,
|
||||
version,
|
||||
@@ -68,7 +68,7 @@ export async function saveTemplate(input: unknown): Promise<TemplateResult> {
|
||||
await writeAudit(tx, {
|
||||
actorId: user.id,
|
||||
action: 'roles.update',
|
||||
targetType: 'CaseTemplate',
|
||||
targetType: 'DocumentTemplate',
|
||||
targetId: `${key}:${version}`,
|
||||
clearanceAtTime: user.permissions.clearanceLevel,
|
||||
meta: { key, version, fieldCount: fields.length },
|
||||
|
||||
@@ -11,7 +11,7 @@ export default async function TemplateAdminPage() {
|
||||
await requirePermission('template.manage')
|
||||
|
||||
// Je Schlüssel die neueste Version; ältere bleiben für bestehende Akten stehen.
|
||||
const vorlagen = await db.caseTemplate.findMany({
|
||||
const vorlagen = await db.documentTemplate.findMany({
|
||||
orderBy: [{ key: 'asc' }, { version: 'desc' }],
|
||||
distinct: ['key'],
|
||||
})
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useTransition } from 'react'
|
||||
import { de } from '@/lib/i18n/de'
|
||||
import {
|
||||
finalizeDocumentAction,
|
||||
reclassifyDocumentAction,
|
||||
retractDocumentAction,
|
||||
} from '../actions'
|
||||
|
||||
/**
|
||||
* Ausfertigen, Zurückziehen, Umklassifizieren.
|
||||
*
|
||||
* Wie beim Fall bewusst **nicht** optimistisch: alle drei sind folgenreich.
|
||||
* Das Ausfertigen fragt nach, das Zurückziehen verlangt eine Begründung — es
|
||||
* gibt kein Löschen, der Grabstein bleibt stehen.
|
||||
*/
|
||||
export function DocumentActions({
|
||||
documentNumber,
|
||||
classification,
|
||||
canFinalize,
|
||||
canRetract,
|
||||
canReclassify,
|
||||
levels,
|
||||
}: {
|
||||
documentNumber: string
|
||||
classification: number
|
||||
canFinalize: boolean
|
||||
canRetract: boolean
|
||||
canReclassify: boolean
|
||||
levels: { level: number; name: string }[]
|
||||
}) {
|
||||
const [reason, setReason] = useState('')
|
||||
const [retracting, setRetracting] = useState(false)
|
||||
const [nextLevel, setNextLevel] = useState(classification)
|
||||
const [levelReason, setLevelReason] = useState('')
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [pending, startTransition] = useTransition()
|
||||
|
||||
if (!canFinalize && !canRetract && !canReclassify) return null
|
||||
|
||||
const lowering = nextLevel < classification
|
||||
|
||||
function run(action: () => Promise<{ ok: boolean; error?: string }>) {
|
||||
setError(null)
|
||||
startTransition(async () => {
|
||||
const result = await action()
|
||||
if (!result.ok) setError(result.error ?? de.actionErrors.default!)
|
||||
else setRetracting(false)
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mt-6 flex flex-wrap gap-x-10 gap-y-5 border-t border-line pt-5 text-xs">
|
||||
{canFinalize ? (
|
||||
<div>
|
||||
<button
|
||||
type="button"
|
||||
disabled={pending}
|
||||
onClick={() => {
|
||||
if (!confirm(de.document.finalizeHint)) return
|
||||
run(() => finalizeDocumentAction({ documentNumber }))
|
||||
}}
|
||||
className="border border-line bg-raised px-3 py-1 font-condensed text-accent disabled:text-text-dim"
|
||||
>
|
||||
{de.document.finalize}
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{canReclassify ? (
|
||||
<div>
|
||||
<p className="font-condensed text-text-dim">{de.document.reclassify}</p>
|
||||
<div className="mt-1.5 flex flex-wrap items-center gap-2">
|
||||
<select
|
||||
value={nextLevel}
|
||||
onChange={(event) => setNextLevel(Number(event.target.value))}
|
||||
aria-label={de.clearance.classification}
|
||||
className="border border-line bg-raised px-2 py-1"
|
||||
>
|
||||
{levels.map((level) => (
|
||||
<option key={level.level} value={level.level}>
|
||||
{level.level} · {level.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
disabled={pending || nextLevel === classification}
|
||||
onClick={() =>
|
||||
run(() =>
|
||||
reclassifyDocumentAction({
|
||||
documentNumber,
|
||||
to: nextLevel,
|
||||
reason: levelReason,
|
||||
}),
|
||||
)
|
||||
}
|
||||
className="border border-line bg-raised px-3 py-1 font-condensed text-accent disabled:text-text-dim"
|
||||
>
|
||||
{de.common.save}
|
||||
</button>
|
||||
</div>
|
||||
{lowering ? (
|
||||
<textarea
|
||||
value={levelReason}
|
||||
onChange={(event) => setLevelReason(event.target.value)}
|
||||
rows={2}
|
||||
placeholder={de.case.reclassifyReason}
|
||||
aria-label={de.case.reclassifyReason}
|
||||
className="mt-2 block w-full max-w-sm border border-line bg-raised px-3 py-2 text-2xs"
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{canRetract ? (
|
||||
<div>
|
||||
{retracting ? (
|
||||
<div>
|
||||
<textarea
|
||||
value={reason}
|
||||
onChange={(event) => setReason(event.target.value)}
|
||||
rows={2}
|
||||
placeholder={de.document.retractReason}
|
||||
aria-label={de.document.retractReason}
|
||||
className="block w-full max-w-sm border border-line bg-raised px-3 py-2 text-2xs"
|
||||
/>
|
||||
<div className="mt-2 flex gap-3">
|
||||
<button
|
||||
type="button"
|
||||
disabled={pending || reason.trim().length < 10}
|
||||
onClick={() => run(() => retractDocumentAction({ documentNumber, reason }))}
|
||||
className="border border-line bg-raised px-3 py-1 font-condensed text-stamp-4 disabled:text-text-dim"
|
||||
>
|
||||
{de.document.retract}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setRetracting(false)}
|
||||
className="font-condensed text-text-dim"
|
||||
>
|
||||
{de.common.cancel}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setRetracting(true)}
|
||||
className="font-condensed text-text-dim"
|
||||
>
|
||||
{de.document.retract}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{error ? <p className="w-full font-condensed text-2xs text-stamp-4">{error}</p> : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Skeleton, SkeletonLine } from '@/components/Skeleton'
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl px-6 py-10">
|
||||
<div className="pl-3">
|
||||
<Skeleton className="h-[0.9rem]" width="9rem" />
|
||||
<div className="mt-2">
|
||||
<Skeleton className="h-[1.6rem]" width="20rem" />
|
||||
</div>
|
||||
<div className="mt-3 flex gap-8">
|
||||
<Skeleton className="h-[0.8rem]" width="6rem" />
|
||||
<Skeleton className="h-[0.8rem]" width="7rem" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-10 space-y-6">
|
||||
<SkeletonLine width="10rem" />
|
||||
<SkeletonLine />
|
||||
<SkeletonLine width="12rem" />
|
||||
<SkeletonLine />
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
import type { Metadata } from 'next'
|
||||
import { Suspense } from 'react'
|
||||
import Link from 'next/link'
|
||||
import { notFound } from 'next/navigation'
|
||||
import { db } from '@/lib/db'
|
||||
import { requireUser } from '@/lib/auth/current'
|
||||
import { recordRead, READ_AUDIT_FROM_LEVEL } from '@/lib/audit'
|
||||
import { loadDocumentSections, loadVisibleDocument } from '@/lib/documents/service'
|
||||
import {
|
||||
canEditDocument,
|
||||
canFinalizeDocument,
|
||||
canRetractDocument,
|
||||
} from '@/lib/access/documentWrite'
|
||||
import { de } from '@/lib/i18n/de'
|
||||
import { StampMark, classificationEdgeStyle } from '@/components/StampMark'
|
||||
import { SkeletonLine } from '@/components/Skeleton'
|
||||
import { Sections } from '@/components/sections/Sections'
|
||||
import { saveDocumentSectionAction } from '../actions'
|
||||
import { DocumentActions } from './DocumentActions'
|
||||
import type { EffectivePermissions } from '@/lib/auth/permissions'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ documentNumber: string }>
|
||||
}): Promise<Metadata> {
|
||||
const { documentNumber } = await params
|
||||
return { title: documentNumber }
|
||||
}
|
||||
|
||||
async function Body({
|
||||
document,
|
||||
permissions,
|
||||
canEdit,
|
||||
}: {
|
||||
document: { id: string; templateId: string; documentNumber: string }
|
||||
permissions: EffectivePermissions
|
||||
canEdit: boolean
|
||||
}) {
|
||||
const sections = await loadDocumentSections(permissions, document)
|
||||
return (
|
||||
<Sections
|
||||
scope={`dokument:${document.documentNumber}`}
|
||||
save={saveDocumentSectionAction.bind(null, document.documentNumber)}
|
||||
sections={sections}
|
||||
canEdit={canEdit}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Ein Dokument.
|
||||
*
|
||||
* Dieselbe Darstellung trägt einen Vorfallsbericht und einen mehrseitigen
|
||||
* Vertrag: was sie unterscheidet, steht in der Vorlage, nicht hier.
|
||||
* Siehe docs/13-entscheidungen.md.
|
||||
*/
|
||||
export default async function DocumentPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ documentNumber: string }>
|
||||
}) {
|
||||
const user = await requireUser()
|
||||
const { documentNumber } = await params
|
||||
|
||||
const doc = await loadVisibleDocument(user.permissions, documentNumber)
|
||||
// Kein Zugriff heisst 404, nicht 403.
|
||||
if (!doc) notFound()
|
||||
|
||||
if (doc.classification >= READ_AUDIT_FROM_LEVEL) {
|
||||
recordRead({
|
||||
actorId: user.id,
|
||||
action: 'document.read',
|
||||
targetType: 'Document',
|
||||
targetId: doc.id,
|
||||
clearanceAtTime: user.permissions.clearanceLevel,
|
||||
meta: { documentNumber: doc.documentNumber, classification: doc.classification },
|
||||
})
|
||||
}
|
||||
|
||||
const [levels, besitzer, verfasser] = await Promise.all([
|
||||
db.clearanceLevelConfig.findMany({ orderBy: { level: 'asc' } }),
|
||||
doc.caseId
|
||||
? db.case.findUnique({ where: { id: doc.caseId }, select: { caseNumber: true, title: true } })
|
||||
: doc.personnelFileId
|
||||
? db.personnelFile.findUnique({
|
||||
where: { id: doc.personnelFileId },
|
||||
select: { id: true, displayName: true },
|
||||
})
|
||||
: Promise.resolve(null),
|
||||
db.user.findMany({
|
||||
where: {
|
||||
id: {
|
||||
in: [doc.createdById, doc.finalizedById, doc.retractedById].filter(
|
||||
(id): id is string => id !== null,
|
||||
),
|
||||
},
|
||||
},
|
||||
select: { id: true, displayName: true },
|
||||
}),
|
||||
])
|
||||
|
||||
const level = levels.find((l) => l.level === doc.classification)
|
||||
const nameOf = new Map(verfasser.map((v) => [v.id, v.displayName]))
|
||||
const canEdit = canEditDocument(user.permissions, doc).ok
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl px-6 py-10">
|
||||
<header className="pl-3" style={classificationEdgeStyle(doc.classification)}>
|
||||
<div className="flex flex-wrap items-baseline gap-x-4 gap-y-2">
|
||||
<span className="font-mono text-xs text-text-dim">{doc.documentNumber}</span>
|
||||
<StampMark level={doc.classification} name={level?.name ?? de.common.unknown} />
|
||||
</div>
|
||||
<h1 className="mt-2 font-condensed">{doc.title}</h1>
|
||||
|
||||
<dl className="mt-3 flex flex-wrap gap-x-8 gap-y-1 text-xs text-text-dim">
|
||||
<div className="flex gap-2">
|
||||
<dt className="font-condensed">{de.case.status}</dt>
|
||||
<dd>{de.document.statusNames[doc.status] ?? doc.status}</dd>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<dt className="font-condensed">{de.document.kind}</dt>
|
||||
<dd>{doc.templateKey}</dd>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<dt className="font-condensed">{de.case.createdBy}</dt>
|
||||
<dd>{nameOf.get(doc.createdById) ?? doc.createdById}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
{besitzer ? (
|
||||
<p className="mt-2 text-xs">
|
||||
{'caseNumber' in besitzer ? (
|
||||
<Link href={`/faelle/${besitzer.caseNumber}`}>
|
||||
{de.document.ownerCase} · {besitzer.title}
|
||||
</Link>
|
||||
) : (
|
||||
<Link href={`/personalakten/${besitzer.id}`}>
|
||||
{de.document.ownerPersonnel} · {besitzer.displayName}
|
||||
</Link>
|
||||
)}
|
||||
</p>
|
||||
) : (
|
||||
<p className="mt-2 text-xs text-text-dim">{de.document.ownerNone}</p>
|
||||
)}
|
||||
|
||||
{doc.retractedAt ? (
|
||||
<p className="mt-3 border-l-(length:--spacing-edge) border-stamp-4 pl-3 text-sm text-text-dim">
|
||||
{de.document.retracted(
|
||||
doc.retractedAt.toLocaleDateString('de-DE'),
|
||||
nameOf.get(doc.retractedById ?? '') ?? doc.retractedById ?? de.common.unknown,
|
||||
doc.retractionReason ?? '',
|
||||
)}
|
||||
</p>
|
||||
) : doc.finalizedAt ? (
|
||||
<p className="mt-3 font-condensed text-2xs text-text-dim">
|
||||
{de.document.finalized(
|
||||
doc.finalizedAt.toLocaleDateString('de-DE'),
|
||||
nameOf.get(doc.finalizedById ?? '') ?? doc.finalizedById ?? de.common.unknown,
|
||||
)}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
<DocumentActions
|
||||
documentNumber={doc.documentNumber}
|
||||
classification={doc.classification}
|
||||
canFinalize={canFinalizeDocument(user.permissions, doc).ok}
|
||||
canRetract={canRetractDocument(user.permissions, doc).ok}
|
||||
canReclassify={canEdit}
|
||||
levels={levels
|
||||
.filter((l) => l.level <= user.permissions.clearanceLevel)
|
||||
.map((l) => ({ level: l.level, name: l.name }))}
|
||||
/>
|
||||
</header>
|
||||
|
||||
<section className="mt-10">
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="space-y-6">
|
||||
<SkeletonLine width="10rem" />
|
||||
<SkeletonLine />
|
||||
<SkeletonLine width="12rem" />
|
||||
<SkeletonLine />
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Body document={doc} permissions={user.permissions} canEdit={canEdit} />
|
||||
</Suspense>
|
||||
</section>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
'use server'
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { z } from 'zod'
|
||||
import { requireUser } from '@/lib/auth/current'
|
||||
import { AccessError, ConflictError } from '@/lib/errors'
|
||||
import {
|
||||
createDocument,
|
||||
finalizeDocument,
|
||||
reclassifyDocument,
|
||||
retractDocument,
|
||||
saveDocumentSection,
|
||||
type Owner,
|
||||
} from '@/lib/documents/service'
|
||||
import { de } from '@/lib/i18n/de'
|
||||
import type { SaveSectionResult } from '@/components/sections/types'
|
||||
|
||||
export type ActionResult = { ok: true } | { ok: false; error: string }
|
||||
|
||||
function toMessage(error: unknown): string {
|
||||
if (error instanceof AccessError) {
|
||||
return de.actionErrors[error.code] ?? de.actionErrors.default!
|
||||
}
|
||||
console.error('[dokumente] unerwartet', error)
|
||||
return de.actionErrors.default!
|
||||
}
|
||||
|
||||
const createSchema = z.object({
|
||||
templateKey: z.string().min(1),
|
||||
title: z.string().max(200).optional(),
|
||||
classification: z.coerce.number().int().min(0).max(5),
|
||||
caseNumber: z.string().max(60).optional(),
|
||||
personnelFileId: z.string().max(64).optional(),
|
||||
})
|
||||
|
||||
export async function createDocumentAction(
|
||||
_prev: ActionResult | null,
|
||||
formData: FormData,
|
||||
): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = createSchema.safeParse(Object.fromEntries(formData))
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors.default! }
|
||||
|
||||
const owner: Owner = parsed.data.caseNumber
|
||||
? { kind: 'case', caseNumber: parsed.data.caseNumber }
|
||||
: parsed.data.personnelFileId
|
||||
? { kind: 'personnel', personnelFileId: parsed.data.personnelFileId }
|
||||
: { kind: 'standalone' }
|
||||
|
||||
let documentNumber: string
|
||||
try {
|
||||
const created = await createDocument(user.permissions, {
|
||||
templateKey: parsed.data.templateKey,
|
||||
title: parsed.data.title,
|
||||
classification: parsed.data.classification,
|
||||
owner,
|
||||
})
|
||||
documentNumber = created.documentNumber
|
||||
} catch (error) {
|
||||
return { ok: false, error: toMessage(error) }
|
||||
}
|
||||
|
||||
redirect(`/dokumente/${documentNumber}`)
|
||||
}
|
||||
|
||||
const sectionSchema = z.object({
|
||||
fieldKey: z.string().min(1),
|
||||
value: z.unknown(),
|
||||
baseVersion: z.coerce.number().int().min(0),
|
||||
minClearance: z.coerce.number().int().min(0).max(5).optional(),
|
||||
})
|
||||
|
||||
/** Das Dokument kommt gebunden herein, siehe `.bind`. */
|
||||
export async function saveDocumentSectionAction(
|
||||
documentNumber: string,
|
||||
input: unknown,
|
||||
): Promise<SaveSectionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = sectionSchema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, conflict: false, error: de.actionErrors.default! }
|
||||
|
||||
try {
|
||||
const { version } = await saveDocumentSection(user.permissions, {
|
||||
documentNumber,
|
||||
...parsed.data,
|
||||
})
|
||||
revalidatePath(`/dokumente/${documentNumber}`)
|
||||
return { ok: true, version }
|
||||
} catch (error) {
|
||||
if (error instanceof ConflictError) {
|
||||
return {
|
||||
ok: false,
|
||||
conflict: true,
|
||||
current: { value: error.current.value, version: error.current.version },
|
||||
}
|
||||
}
|
||||
return { ok: false, conflict: false, error: toMessage(error) }
|
||||
}
|
||||
}
|
||||
|
||||
const numberSchema = z.object({ documentNumber: z.string().min(1) })
|
||||
|
||||
export async function finalizeDocumentAction(input: unknown): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = numberSchema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors.default! }
|
||||
|
||||
try {
|
||||
await finalizeDocument(user.permissions, parsed.data.documentNumber)
|
||||
revalidatePath(`/dokumente/${parsed.data.documentNumber}`)
|
||||
return { ok: true }
|
||||
} catch (error) {
|
||||
return { ok: false, error: toMessage(error) }
|
||||
}
|
||||
}
|
||||
|
||||
const retractSchema = numberSchema.extend({ reason: z.string().min(10).max(2000) })
|
||||
|
||||
export async function retractDocumentAction(input: unknown): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = retractSchema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors['reason-required']! }
|
||||
|
||||
try {
|
||||
await retractDocument(user.permissions, parsed.data.documentNumber, parsed.data.reason)
|
||||
revalidatePath(`/dokumente/${parsed.data.documentNumber}`)
|
||||
return { ok: true }
|
||||
} catch (error) {
|
||||
return { ok: false, error: toMessage(error) }
|
||||
}
|
||||
}
|
||||
|
||||
const reclassifySchema = numberSchema.extend({
|
||||
to: z.coerce.number().int().min(0).max(5),
|
||||
reason: z.string().max(2000).optional(),
|
||||
})
|
||||
|
||||
export async function reclassifyDocumentAction(input: unknown): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = reclassifySchema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors.default! }
|
||||
|
||||
try {
|
||||
await reclassifyDocument(
|
||||
user.permissions,
|
||||
parsed.data.documentNumber,
|
||||
parsed.data.to,
|
||||
parsed.data.reason,
|
||||
)
|
||||
revalidatePath(`/dokumente/${parsed.data.documentNumber}`)
|
||||
return { ok: true }
|
||||
} catch (error) {
|
||||
return { ok: false, error: toMessage(error) }
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ export function CaseActions({
|
||||
setError(null)
|
||||
startTransition(async () => {
|
||||
const result = await action()
|
||||
if (!result.ok) setError(result.error ?? de.case.errors.default!)
|
||||
if (!result.ok) setError(result.error ?? de.actionErrors.default!)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useTransition } from 'react'
|
||||
import Link from 'next/link'
|
||||
import { de } from '@/lib/i18n/de'
|
||||
import { LINK_KINDS } from '@/lib/cases/terms'
|
||||
import { linkCasesAction, unlinkCasesAction } from '../actions'
|
||||
import { classificationEdgeStyle } from '@/components/StampMark'
|
||||
|
||||
type Verknuepfung = {
|
||||
kind: string
|
||||
direction: 'in' | 'out'
|
||||
other: { id: string; caseNumber: string; title: string; status: string; classification: number }
|
||||
}
|
||||
|
||||
/**
|
||||
* Verknüpfungen zwischen Akten.
|
||||
*
|
||||
* Lösen ohne Bestätigungsdialog: eine Verknüpfung ist umkehrbar, sie lässt
|
||||
* sich in zwei Klicks neu ziehen. Siehe docs/09-performance-und-ux.md.
|
||||
*/
|
||||
export function CaseLinks({
|
||||
caseNumber,
|
||||
links,
|
||||
canEdit,
|
||||
}: {
|
||||
caseNumber: string
|
||||
links: Verknuepfung[]
|
||||
canEdit: boolean
|
||||
}) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [target, setTarget] = useState('')
|
||||
const [kind, setKind] = useState<string>('RELATED')
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [pending, startTransition] = useTransition()
|
||||
|
||||
return (
|
||||
<div>
|
||||
{links.length === 0 ? (
|
||||
<p className="text-text-dim">{de.link.empty}</p>
|
||||
) : (
|
||||
<ul className="border-t border-line">
|
||||
{links.map((link) => (
|
||||
<li
|
||||
key={`${link.direction}:${link.kind}:${link.other.id}`}
|
||||
className="flex flex-wrap items-baseline gap-x-4 gap-y-1 border-b border-line py-2 pl-3"
|
||||
style={classificationEdgeStyle(link.other.classification)}
|
||||
>
|
||||
<span className="font-condensed text-2xs text-text-dim">
|
||||
{(link.direction === 'in' ? de.link.incoming : de.link.kinds)[link.kind] ??
|
||||
link.kind}
|
||||
</span>
|
||||
<Link
|
||||
href={`/faelle/${link.other.caseNumber}`}
|
||||
prefetch
|
||||
className="font-mono text-xs text-text-dim"
|
||||
>
|
||||
{link.other.caseNumber}
|
||||
</Link>
|
||||
<span className="grow text-sm">{link.other.title}</span>
|
||||
{canEdit ? (
|
||||
<button
|
||||
type="button"
|
||||
disabled={pending}
|
||||
onClick={() =>
|
||||
startTransition(async () => {
|
||||
const result = await unlinkCasesAction({
|
||||
fromCaseNumber: caseNumber,
|
||||
toCaseNumber: link.other.caseNumber,
|
||||
kind: link.kind,
|
||||
})
|
||||
if (!result.ok) setError(result.error)
|
||||
})
|
||||
}
|
||||
className="font-condensed text-2xs text-text-dim"
|
||||
>
|
||||
{de.link.remove}
|
||||
</button>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
{error ? <p className="mt-2 font-condensed text-2xs text-stamp-4">{error}</p> : null}
|
||||
|
||||
{canEdit ? (
|
||||
open ? (
|
||||
<div className="mt-4 flex flex-wrap items-center gap-2">
|
||||
<select
|
||||
value={kind}
|
||||
onChange={(event) => setKind(event.target.value)}
|
||||
aria-label={de.link.kind}
|
||||
className="border border-line bg-raised px-2 py-1 text-2xs"
|
||||
>
|
||||
{LINK_KINDS.map((value) => (
|
||||
<option key={value} value={value}>
|
||||
{de.link.kinds[value] ?? value}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<input
|
||||
value={target}
|
||||
onChange={(event) => setTarget(event.target.value)}
|
||||
placeholder={de.link.target}
|
||||
aria-label={de.link.target}
|
||||
className="border border-line bg-raised px-2 py-1 font-mono text-2xs"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
disabled={pending || target.trim() === ''}
|
||||
onClick={() =>
|
||||
startTransition(async () => {
|
||||
setError(null)
|
||||
const result = await linkCasesAction({
|
||||
fromCaseNumber: caseNumber,
|
||||
toCaseNumber: target.trim(),
|
||||
kind,
|
||||
})
|
||||
if (result.ok) {
|
||||
setTarget('')
|
||||
setOpen(false)
|
||||
} else {
|
||||
setError(result.error)
|
||||
}
|
||||
})
|
||||
}
|
||||
className="border border-line bg-raised px-3 py-1 font-condensed text-2xs text-accent disabled:text-text-dim"
|
||||
>
|
||||
{de.link.add}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(false)}
|
||||
className="font-condensed text-2xs text-text-dim"
|
||||
>
|
||||
{de.common.cancel}
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(true)}
|
||||
className="mt-4 border border-line bg-raised px-3 py-1 font-condensed text-2xs text-accent"
|
||||
>
|
||||
{de.link.add}
|
||||
</button>
|
||||
)
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -39,7 +39,7 @@ export function EntryActions({
|
||||
setMode('idle')
|
||||
setReason('')
|
||||
} else {
|
||||
setError(result.error ?? de.case.errors.default!)
|
||||
setError(result.error ?? de.actionErrors.default!)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useTransition } from 'react'
|
||||
import Link from 'next/link'
|
||||
import { de } from '@/lib/i18n/de'
|
||||
import { PARTICIPANT_ROLES } from '@/lib/cases/terms'
|
||||
import { addParticipantAction, removeParticipantAction } from '../actions'
|
||||
|
||||
type Beteiligter = {
|
||||
id: string
|
||||
role: string
|
||||
userId: string | null
|
||||
displayName: string | null
|
||||
personnelFileId: string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Beteiligte einer Akte.
|
||||
*
|
||||
* Der Hinweis über dem Formular ist wichtig und steht deshalb dort und nicht
|
||||
* in einer Hilfeseite: wer hier eingetragen wird, liest die Akte unabhängig
|
||||
* von seiner Freigabestufe.
|
||||
*/
|
||||
export function Participants({
|
||||
caseNumber,
|
||||
participants,
|
||||
canEdit,
|
||||
members,
|
||||
files,
|
||||
}: {
|
||||
caseNumber: string
|
||||
participants: Beteiligter[]
|
||||
canEdit: boolean
|
||||
members: { id: string; displayName: string }[]
|
||||
files: { id: string; displayName: string }[]
|
||||
}) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [role, setRole] = useState<string>('INVESTIGATOR')
|
||||
const [target, setTarget] = useState('')
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [pending, startTransition] = useTransition()
|
||||
|
||||
function add() {
|
||||
if (!target) return
|
||||
setError(null)
|
||||
const [art, id] = target.split(':')
|
||||
startTransition(async () => {
|
||||
const result = await addParticipantAction({
|
||||
caseNumber,
|
||||
role,
|
||||
...(art === 'user' ? { userId: id } : { personnelFileId: id }),
|
||||
})
|
||||
if (result.ok) {
|
||||
setTarget('')
|
||||
setOpen(false)
|
||||
} else {
|
||||
setError(result.error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{participants.length === 0 ? (
|
||||
<p className="text-text-dim">{de.participant.empty}</p>
|
||||
) : (
|
||||
<ul className="border-t border-line">
|
||||
{participants.map((person) => (
|
||||
<li
|
||||
key={person.id}
|
||||
className="flex flex-wrap items-baseline gap-x-4 gap-y-1 border-b border-line py-2"
|
||||
>
|
||||
<span className="font-condensed text-2xs text-text-dim">
|
||||
{de.participant.roles[person.role] ?? person.role}
|
||||
</span>
|
||||
<span className="grow text-sm">
|
||||
{person.personnelFileId ? (
|
||||
<Link href={`/personalakten/${person.personnelFileId}`}>
|
||||
{person.displayName ?? de.common.unknown}
|
||||
</Link>
|
||||
) : (
|
||||
(person.displayName ?? de.common.unknown)
|
||||
)}
|
||||
</span>
|
||||
{canEdit ? (
|
||||
<button
|
||||
type="button"
|
||||
disabled={pending}
|
||||
onClick={() =>
|
||||
startTransition(async () => {
|
||||
const result = await removeParticipantAction({
|
||||
caseNumber,
|
||||
participantId: person.id,
|
||||
})
|
||||
if (!result.ok) setError(result.error)
|
||||
})
|
||||
}
|
||||
className="font-condensed text-2xs text-text-dim"
|
||||
>
|
||||
{de.participant.remove}
|
||||
</button>
|
||||
) : null}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
{error ? <p className="mt-2 font-condensed text-2xs text-stamp-4">{error}</p> : null}
|
||||
|
||||
{canEdit ? (
|
||||
open ? (
|
||||
<div className="mt-4 border border-line p-3">
|
||||
<p className="max-w-(--container-measure) text-2xs text-text-dim">
|
||||
{de.participant.hint}
|
||||
</p>
|
||||
<div className="mt-3 flex flex-wrap items-center gap-2">
|
||||
<select
|
||||
value={role}
|
||||
onChange={(event) => setRole(event.target.value)}
|
||||
aria-label={de.participant.role}
|
||||
className="border border-line bg-raised px-2 py-1 text-2xs"
|
||||
>
|
||||
{PARTICIPANT_ROLES.map((value) => (
|
||||
<option key={value} value={value}>
|
||||
{de.participant.roles[value] ?? value}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
value={target}
|
||||
onChange={(event) => setTarget(event.target.value)}
|
||||
aria-label={de.participant.person}
|
||||
className="border border-line bg-raised px-2 py-1 text-2xs"
|
||||
>
|
||||
<option value="">—</option>
|
||||
<optgroup label={de.participant.pickUser}>
|
||||
{members.map((member) => (
|
||||
<option key={member.id} value={`user:${member.id}`}>
|
||||
{member.displayName}
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
<optgroup label={de.participant.pickPersonnel}>
|
||||
{files.map((file) => (
|
||||
<option key={file.id} value={`file:${file.id}`}>
|
||||
{file.displayName}
|
||||
</option>
|
||||
))}
|
||||
</optgroup>
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
disabled={pending || !target}
|
||||
onClick={add}
|
||||
className="border border-line bg-raised px-3 py-1 font-condensed text-2xs text-accent disabled:text-text-dim"
|
||||
>
|
||||
{de.participant.add}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(false)}
|
||||
className="font-condensed text-2xs text-text-dim"
|
||||
>
|
||||
{de.common.cancel}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(true)}
|
||||
className="mt-4 border border-line bg-raised px-3 py-1 font-condensed text-2xs text-accent"
|
||||
>
|
||||
{de.participant.add}
|
||||
</button>
|
||||
)
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useRef, useState, useTransition } from 'react'
|
||||
import { de } from '@/lib/i18n/de'
|
||||
import { saveSectionAction } from './sectionActions'
|
||||
|
||||
type Props = {
|
||||
caseNumber: string
|
||||
fieldKey: string
|
||||
label: string
|
||||
type: string
|
||||
options?: string[]
|
||||
help?: string
|
||||
requiredToClose?: boolean
|
||||
initialValue: unknown
|
||||
initialVersion: number
|
||||
readOnly: boolean
|
||||
}
|
||||
|
||||
const AUTOSAVE_MS = 2000
|
||||
|
||||
/**
|
||||
* Ein Abschnitt zum Bearbeiten.
|
||||
*
|
||||
* Entwürfe werden alle zwei Sekunden **lokal** gesichert, damit ein
|
||||
* versehentlicher Tab-Wechsel keinen Text kostet. Gespeichert wird erst auf
|
||||
* Knopfdruck: ein Abschnitt ist der Sachstand der Akte, nicht ein Chatbeitrag.
|
||||
* Siehe docs/09-performance-und-ux.md.
|
||||
*
|
||||
* Beim Speichern geht die geladene Version mit. Weicht sie ab, gibt es kein
|
||||
* stilles Überschreiben, sondern beide Fassungen nebeneinander.
|
||||
*/
|
||||
export function SectionEditor(props: Props) {
|
||||
const speicherSchluessel = `afis:abschnitt:${props.caseNumber}:${props.fieldKey}`
|
||||
const [value, setValue] = useState(() => normalise(props.initialValue, props.type))
|
||||
const [version, setVersion] = useState(props.initialVersion)
|
||||
const [conflict, setConflict] = useState<{ value: unknown; version: number } | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [saved, setSaved] = useState(false)
|
||||
const [draftKept, setDraftKept] = useState(false)
|
||||
const [pending, startTransition] = useTransition()
|
||||
const timer = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||
|
||||
// Entwurf aus dem letzten Besuch übernehmen, falls er neuer ist.
|
||||
useEffect(() => {
|
||||
try {
|
||||
const stored = localStorage.getItem(speicherSchluessel)
|
||||
if (stored !== null && stored !== normalise(props.initialValue, props.type)) {
|
||||
setValue(stored)
|
||||
setDraftKept(true)
|
||||
}
|
||||
} catch {
|
||||
// Privates Fenster oder gesperrter Speicher: dann eben ohne Entwurf.
|
||||
}
|
||||
}, [speicherSchluessel, props.initialValue, props.type])
|
||||
|
||||
function change(next: string) {
|
||||
setValue(next)
|
||||
setSaved(false)
|
||||
if (timer.current) clearTimeout(timer.current)
|
||||
timer.current = setTimeout(() => {
|
||||
try {
|
||||
localStorage.setItem(speicherSchluessel, next)
|
||||
setDraftKept(true)
|
||||
} catch {
|
||||
// still ignorieren, der Entwurf ist eine Bequemlichkeit
|
||||
}
|
||||
}, AUTOSAVE_MS)
|
||||
}
|
||||
|
||||
function submit(override?: unknown, baseVersion = version) {
|
||||
setError(null)
|
||||
startTransition(async () => {
|
||||
const result = await saveSectionAction({
|
||||
caseNumber: props.caseNumber,
|
||||
fieldKey: props.fieldKey,
|
||||
value: override ?? parse(value, props.type),
|
||||
baseVersion,
|
||||
})
|
||||
|
||||
if (result.ok) {
|
||||
setVersion(result.version)
|
||||
setConflict(null)
|
||||
setSaved(true)
|
||||
setDraftKept(false)
|
||||
try {
|
||||
localStorage.removeItem(speicherSchluessel)
|
||||
} catch {
|
||||
// egal
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (result.conflict) setConflict(result.current)
|
||||
else setError(result.error)
|
||||
})
|
||||
}
|
||||
|
||||
if (props.readOnly) {
|
||||
return (
|
||||
<p className="mt-1 max-w-(--container-measure) text-sm whitespace-pre-wrap">
|
||||
{String(value || '—')}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="mt-1.5">
|
||||
{props.type === 'select' ? (
|
||||
<select
|
||||
value={value}
|
||||
onChange={(event) => change(event.target.value)}
|
||||
className="border border-line bg-raised px-3 py-2 text-sm"
|
||||
>
|
||||
<option value="">—</option>
|
||||
{props.options?.map((option) => (
|
||||
<option key={option} value={option}>
|
||||
{option}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
) : props.type === 'longtext' ? (
|
||||
<textarea
|
||||
value={value}
|
||||
onChange={(event) => change(event.target.value)}
|
||||
rows={6}
|
||||
className="block w-full max-w-(--container-measure) border border-line bg-raised px-3 py-2 text-sm"
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
type={props.type === 'date' ? 'date' : props.type === 'number' ? 'number' : 'text'}
|
||||
value={value}
|
||||
onChange={(event) => change(event.target.value)}
|
||||
className="block w-full max-w-(--container-measure) border border-line bg-raised px-3 py-2 text-sm"
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="mt-2 flex flex-wrap items-center gap-3 text-2xs">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => submit()}
|
||||
disabled={pending}
|
||||
className="border border-line bg-raised px-3 py-1 font-condensed text-accent disabled:text-text-dim"
|
||||
>
|
||||
{pending ? de.section.saving : de.section.save}
|
||||
</button>
|
||||
{version > 0 ? (
|
||||
<span className="font-mono text-text-dim">{de.section.version(version)}</span>
|
||||
) : null}
|
||||
{saved ? <span className="font-condensed text-text-dim">{de.section.saved}</span> : null}
|
||||
{draftKept && !saved ? (
|
||||
<span className="font-condensed text-text-dim">{de.section.draftKept}</span>
|
||||
) : null}
|
||||
{error ? <span className="font-condensed text-stamp-4">{error}</span> : null}
|
||||
</div>
|
||||
|
||||
{conflict ? (
|
||||
<div className="mt-3 border border-stamp-4 p-3">
|
||||
<p className="font-condensed text-2xs text-stamp-4">{de.section.conflict}</p>
|
||||
<div className="mt-3 grid gap-4 md:grid-cols-2">
|
||||
<div>
|
||||
<p className="font-condensed text-2xs text-text-dim">{de.section.mine}</p>
|
||||
<p className="mt-1 border-l-(length:--spacing-edge) border-steel pl-3 text-sm whitespace-pre-wrap">
|
||||
{value}
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => submit(parse(value, props.type), conflict.version)}
|
||||
className="mt-2 font-condensed text-2xs text-accent"
|
||||
>
|
||||
{de.section.takeMine}
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<p className="font-condensed text-2xs text-text-dim">{de.section.theirs}</p>
|
||||
<p className="mt-1 border-l-(length:--spacing-edge) border-line pl-3 text-sm whitespace-pre-wrap">
|
||||
{String(conflict.value ?? '')}
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setValue(normalise(conflict.value, props.type))
|
||||
setVersion(conflict.version)
|
||||
setConflict(null)
|
||||
}}
|
||||
className="mt-2 font-condensed text-2xs text-accent"
|
||||
>
|
||||
{de.section.takeTheirs}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function normalise(value: unknown, _type: string): string {
|
||||
if (value === null || value === undefined) return ''
|
||||
if (Array.isArray(value)) return value.join(', ')
|
||||
return String(value)
|
||||
}
|
||||
|
||||
function parse(value: string, type: string): unknown {
|
||||
if (type === 'number') return value === '' ? null : Number(value)
|
||||
if (type === 'multiselect' || type === 'checklist') {
|
||||
return value.split(',').map((part) => part.trim()).filter(Boolean)
|
||||
}
|
||||
return value === '' ? null : value
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
import { de } from '@/lib/i18n/de'
|
||||
import { fillPlaceholders, isInputField } from '@/lib/templates/fields'
|
||||
import { RedactedText } from '@/components/Redacted'
|
||||
import { SectionEditor } from './SectionEditor'
|
||||
import type { RenderedSection } from '@/lib/cases/sectionService'
|
||||
|
||||
/**
|
||||
* Abschnitte einer Fallakte: der aktuelle Sachstand, aus der Vorlage erzeugt.
|
||||
*
|
||||
* Feste Textbausteine der Vorlage werden gerendert, nicht bearbeitet — ihre
|
||||
* Platzhalter ziehen die Werte der Eingabefelder. Damit trägt dieselbe
|
||||
* Darstellung ein Formular und einen Vertragstext.
|
||||
*/
|
||||
export function Sections({
|
||||
caseNumber,
|
||||
sections,
|
||||
canEdit,
|
||||
}: {
|
||||
caseNumber: string
|
||||
sections: RenderedSection[]
|
||||
canEdit: boolean
|
||||
}) {
|
||||
if (sections.length === 0) {
|
||||
return <p className="text-text-dim">{de.section.empty}</p>
|
||||
}
|
||||
|
||||
const werte = Object.fromEntries(
|
||||
sections.filter((s) => s.visible).map((s) => [s.fieldKey, s.value]),
|
||||
)
|
||||
|
||||
return (
|
||||
<dl className="space-y-8">
|
||||
{sections.map((section) => {
|
||||
const field = section.field
|
||||
|
||||
// Feste Bausteine der Vorlage.
|
||||
if (!isInputField(field)) {
|
||||
if (field.type === 'pagebreak') return <hr key={field.key} className="border-line" />
|
||||
if (field.type === 'signature') {
|
||||
return (
|
||||
<div key={field.key} className="pt-8">
|
||||
<div className="w-64 border-t border-line" />
|
||||
<p className="mt-1 text-2xs text-text-dim">{field.label}</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
const text = fillPlaceholders(field.text ?? '', werte)
|
||||
return field.type === 'heading' ? (
|
||||
<h3 key={field.key} className="font-condensed">
|
||||
{text || field.label}
|
||||
</h3>
|
||||
) : (
|
||||
<p key={field.key} className="max-w-(--container-measure) text-sm whitespace-pre-wrap">
|
||||
{text}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div key={field.key}>
|
||||
<dt className="flex flex-wrap items-baseline gap-x-3">
|
||||
<span className="font-condensed text-xs text-text-dim">{field.label}</span>
|
||||
{field.requiredToClose ? (
|
||||
<span className="font-condensed text-2xs text-stamp-3">
|
||||
{de.section.requiredToClose}
|
||||
</span>
|
||||
) : null}
|
||||
</dt>
|
||||
<dd>
|
||||
{!section.visible ? (
|
||||
// Serverseitig ersetzt: der echte Wert ist gar nicht erst hier.
|
||||
<p className="mt-1.5 flex items-center gap-2">
|
||||
<span className="redaction inline-block h-[1.1rem] w-40" aria-hidden />
|
||||
<span className="font-mono text-2xs text-text-dim">
|
||||
{de.section.lockedField(section.value.requiredLevel)}
|
||||
</span>
|
||||
</p>
|
||||
) : section.segments ? (
|
||||
<div className="mt-1.5">
|
||||
<RedactedText segments={section.segments} />
|
||||
{canEdit ? (
|
||||
<SectionEditor
|
||||
caseNumber={caseNumber}
|
||||
fieldKey={field.key}
|
||||
label={field.label}
|
||||
type={field.type}
|
||||
options={field.options}
|
||||
requiredToClose={field.requiredToClose}
|
||||
initialValue={section.value}
|
||||
initialVersion={section.version}
|
||||
readOnly={false}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
) : (
|
||||
<SectionEditor
|
||||
caseNumber={caseNumber}
|
||||
fieldKey={field.key}
|
||||
label={field.label}
|
||||
type={field.type}
|
||||
options={field.options}
|
||||
requiredToClose={field.requiredToClose}
|
||||
initialValue={section.value}
|
||||
initialVersion={section.version}
|
||||
readOnly={!canEdit}
|
||||
/>
|
||||
)}
|
||||
</dd>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</dl>
|
||||
)
|
||||
}
|
||||
@@ -10,11 +10,20 @@ import { de } from '@/lib/i18n/de'
|
||||
import { StampMark, classificationEdgeStyle } from '@/components/StampMark'
|
||||
import { SkeletonLine } from '@/components/Skeleton'
|
||||
import { EntryComposer } from './EntryComposer'
|
||||
import { Sections } from './Sections'
|
||||
import { Sections } from '@/components/sections/Sections'
|
||||
import { saveSectionAction } from './sectionActions'
|
||||
import { loadSections } from '@/lib/cases/sectionService'
|
||||
import { canEditCase } from '@/lib/access/caseWrite'
|
||||
import { CaseActions } from './CaseActions'
|
||||
import { EntryActions } from './EntryActions'
|
||||
import { Participants } from './Participants'
|
||||
import { CaseLinks } from './CaseLinks'
|
||||
import { listParticipants } from '@/lib/cases/participants'
|
||||
import { listLinks } from '@/lib/cases/links'
|
||||
import { listDocuments, listTemplatesFor } from '@/lib/documents/service'
|
||||
import { visiblePersonnelWhere } from '@/lib/access/personnelFilter'
|
||||
import { DocumentList } from '@/components/documents/DocumentList'
|
||||
import { NewDocument } from '@/components/documents/NewDocument'
|
||||
import { allowedTargets, type CaseStatusName } from '@/lib/cases/lifecycle'
|
||||
import { evaluateEntryEdit, canRetract } from '@/lib/cases/entryPolicy'
|
||||
import Link from 'next/link'
|
||||
@@ -132,6 +141,87 @@ async function Timeline({
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Beteiligte, Verknüpfungen und Dokumente hängen in einer gemeinsamen
|
||||
* Suspense-Grenze: drei kleine Abfragen, die zusammen einen Block ergeben.
|
||||
* Getrennt zu streamen liesse den Kasten dreimal springen.
|
||||
*/
|
||||
async function Relations({
|
||||
akte,
|
||||
permissions,
|
||||
canEdit,
|
||||
}: {
|
||||
akte: { id: string; caseNumber: string; classification: number }
|
||||
permissions: EffectivePermissions
|
||||
canEdit: boolean
|
||||
}) {
|
||||
const [participants, links, documents, templates, levels, members, files] = await Promise.all([
|
||||
listParticipants(permissions, akte.id),
|
||||
listLinks(permissions, akte.id),
|
||||
listDocuments(permissions, { caseId: akte.id }),
|
||||
canEdit ? listTemplatesFor('CASE_DOCUMENT') : Promise.resolve([]),
|
||||
db.clearanceLevelConfig.findMany({ orderBy: { level: 'asc' } }),
|
||||
canEdit
|
||||
? db.user.findMany({
|
||||
orderBy: { displayName: 'asc' },
|
||||
take: 200,
|
||||
select: { id: true, displayName: true },
|
||||
})
|
||||
: Promise.resolve([]),
|
||||
// Nur Personalakten, die der Eintragende sehen darf, und nur, wenn er sie
|
||||
// überhaupt lesen darf: sonst verriete die Auswahlliste ihre Existenz.
|
||||
canEdit && (permissions.isAdmin || permissions.permissions.has('personnel.read'))
|
||||
? db.personnelFile.findMany({
|
||||
where: visiblePersonnelWhere(permissions),
|
||||
orderBy: { displayName: 'asc' },
|
||||
take: 200,
|
||||
select: { id: true, displayName: true },
|
||||
})
|
||||
: Promise.resolve([]),
|
||||
])
|
||||
|
||||
const levelName = new Map(levels.map((l) => [l.level, l.name]))
|
||||
|
||||
return (
|
||||
<div className="grid gap-10 md:grid-cols-2">
|
||||
<section>
|
||||
<h2 className="font-condensed">{de.participant.heading}</h2>
|
||||
<div className="mt-4">
|
||||
<Participants
|
||||
caseNumber={akte.caseNumber}
|
||||
participants={participants}
|
||||
canEdit={canEdit}
|
||||
members={members}
|
||||
files={files}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<h2 className="font-condensed">{de.link.heading}</h2>
|
||||
<div className="mt-4">
|
||||
<CaseLinks caseNumber={akte.caseNumber} links={links} canEdit={canEdit} />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="md:col-span-2">
|
||||
<h2 className="font-condensed">{de.document.heading}</h2>
|
||||
<div className="mt-4 space-y-4">
|
||||
<DocumentList documents={documents} levelName={levelName} />
|
||||
{canEdit ? (
|
||||
<NewDocument
|
||||
templates={templates}
|
||||
levels={levels.filter((l) => l.level <= permissions.clearanceLevel)}
|
||||
defaultLevel={Math.min(akte.classification, permissions.clearanceLevel)}
|
||||
caseNumber={akte.caseNumber}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
async function SectionBlock({
|
||||
caseId,
|
||||
caseNumber,
|
||||
@@ -146,7 +236,14 @@ async function SectionBlock({
|
||||
canEdit: boolean
|
||||
}) {
|
||||
const sections = await loadSections(permissions, caseId, templateId)
|
||||
return <Sections caseNumber={caseNumber} sections={sections} canEdit={canEdit} />
|
||||
return (
|
||||
<Sections
|
||||
scope={`fall:${caseNumber}`}
|
||||
save={saveSectionAction.bind(null, caseNumber)}
|
||||
sections={sections}
|
||||
canEdit={canEdit}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export default async function CasePage({
|
||||
@@ -236,7 +333,30 @@ export default async function CasePage({
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<nav className="mt-10 flex gap-4 border-b border-line pb-2 font-condensed text-xs">
|
||||
<div className="mt-12">
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="grid gap-10 md:grid-cols-2">
|
||||
<div className="space-y-3">
|
||||
<SkeletonLine width="8rem" />
|
||||
<SkeletonLine width="70%" />
|
||||
</div>
|
||||
<div className="space-y-3">
|
||||
<SkeletonLine width="9rem" />
|
||||
<SkeletonLine width="65%" />
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Relations
|
||||
akte={akte}
|
||||
permissions={user.permissions}
|
||||
canEdit={canEditCase(user.permissions, akte).ok}
|
||||
/>
|
||||
</Suspense>
|
||||
</div>
|
||||
|
||||
<nav className="mt-12 flex gap-4 border-b border-line pb-2 font-condensed text-xs">
|
||||
<span className="text-text-dim">{de.case.timeline}</span>
|
||||
<Link href={`/faelle/${akte.caseNumber}/aenderungen`}>{de.case.changes}</Link>
|
||||
</nav>
|
||||
|
||||
@@ -3,32 +3,30 @@
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { z } from 'zod'
|
||||
import { requireUser } from '@/lib/auth/current'
|
||||
import { AccessError } from '@/lib/cases/service'
|
||||
import { ConflictError, saveSection } from '@/lib/cases/sectionService'
|
||||
import { AccessError, ConflictError } from '@/lib/errors'
|
||||
import { saveSection } from '@/lib/cases/sectionService'
|
||||
import { de } from '@/lib/i18n/de'
|
||||
import type { SaveSectionResult } from '@/components/sections/types'
|
||||
|
||||
const schema = z.object({
|
||||
caseNumber: z.string().min(1),
|
||||
fieldKey: z.string().min(1),
|
||||
value: z.unknown(),
|
||||
baseVersion: z.coerce.number().int().min(0),
|
||||
minClearance: z.coerce.number().int().min(0).max(5).optional(),
|
||||
})
|
||||
|
||||
export type SaveSectionResult =
|
||||
| { ok: true; version: number }
|
||||
/** Kein stilles Überschreiben: die fremde Fassung kommt mit zurück. */
|
||||
| { ok: false; conflict: true; current: { value: unknown; version: number } }
|
||||
| { ok: false; conflict: false; error: string }
|
||||
|
||||
export async function saveSectionAction(input: unknown): Promise<SaveSectionResult> {
|
||||
/** Die Akte kommt gebunden herein, siehe `saveSectionAction.bind`. */
|
||||
export async function saveSectionAction(
|
||||
caseNumber: string,
|
||||
input: unknown,
|
||||
): Promise<SaveSectionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = schema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, conflict: false, error: de.case.errors.default! }
|
||||
if (!parsed.success) return { ok: false, conflict: false, error: de.actionErrors.default! }
|
||||
|
||||
try {
|
||||
const { version } = await saveSection(user.permissions, parsed.data)
|
||||
revalidatePath(`/faelle/${parsed.data.caseNumber}`)
|
||||
const { version } = await saveSection(user.permissions, { caseNumber, ...parsed.data })
|
||||
revalidatePath(`/faelle/${caseNumber}`)
|
||||
return { ok: true, version }
|
||||
} catch (error) {
|
||||
if (error instanceof ConflictError) {
|
||||
@@ -39,9 +37,13 @@ export async function saveSectionAction(input: unknown): Promise<SaveSectionResu
|
||||
}
|
||||
}
|
||||
if (error instanceof AccessError) {
|
||||
return { ok: false, conflict: false, error: de.case.errors[error.code] ?? de.case.errors.default! }
|
||||
return {
|
||||
ok: false,
|
||||
conflict: false,
|
||||
error: de.actionErrors[error.code] ?? de.actionErrors.default!,
|
||||
}
|
||||
}
|
||||
console.error('[abschnitt] unerwartet', error)
|
||||
return { ok: false, conflict: false, error: de.case.errors.default! }
|
||||
return { ok: false, conflict: false, error: de.actionErrors.default! }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,16 +6,19 @@ import { z } from 'zod'
|
||||
import { requireUser } from '@/lib/auth/current'
|
||||
import { AccessError, addEntry, changeStatus, createCase, reclassify } from '@/lib/cases/service'
|
||||
import { editEntry, restoreEntry, retractEntry } from '@/lib/cases/entryService'
|
||||
import { addParticipant, removeParticipant } from '@/lib/cases/participants'
|
||||
import { linkCases, unlinkCases } from '@/lib/cases/links'
|
||||
import { LINK_KINDS, PARTICIPANT_ROLES } from '@/lib/cases/terms'
|
||||
import { de } from '@/lib/i18n/de'
|
||||
|
||||
export type ActionResult = { ok: true } | { ok: false; error: string }
|
||||
|
||||
function toMessage(error: unknown): string {
|
||||
if (error instanceof AccessError) {
|
||||
return de.case.errors[error.code] ?? de.case.errors.default!
|
||||
return de.actionErrors[error.code] ?? de.actionErrors.default!
|
||||
}
|
||||
console.error('[faelle] unerwartet', error)
|
||||
return de.case.errors.default!
|
||||
return de.actionErrors.default!
|
||||
}
|
||||
|
||||
const createSchema = z.object({
|
||||
@@ -41,7 +44,7 @@ export async function createCaseAction(
|
||||
classification: formData.get('classification'),
|
||||
templateKey: formData.get('templateKey'),
|
||||
})
|
||||
if (!parsed.success) return { error: de.case.errors.default! }
|
||||
if (!parsed.success) return { error: de.actionErrors.default! }
|
||||
|
||||
let caseNumber: string
|
||||
try {
|
||||
@@ -66,7 +69,7 @@ const entrySchema = z.object({
|
||||
export async function addEntryAction(input: unknown): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = entrySchema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, error: de.case.errors.default! }
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors.default! }
|
||||
|
||||
try {
|
||||
await addEntry(user.permissions, parsed.data)
|
||||
@@ -88,7 +91,7 @@ const statusSchema = z.object({
|
||||
export async function changeStatusAction(input: unknown): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = statusSchema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, error: de.case.errors.default! }
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors.default! }
|
||||
|
||||
try {
|
||||
await changeStatus(user.permissions, parsed.data)
|
||||
@@ -110,7 +113,7 @@ const reclassifySchema = z.object({
|
||||
export async function reclassifyAction(input: unknown): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = reclassifySchema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, error: de.case.errors.default! }
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors.default! }
|
||||
|
||||
try {
|
||||
await reclassify(user.permissions, parsed.data)
|
||||
@@ -134,7 +137,7 @@ const editSchema = z.object({
|
||||
export async function editEntryAction(input: unknown): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = editSchema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, error: de.case.errors.default! }
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors.default! }
|
||||
|
||||
try {
|
||||
await editEntry(user.permissions, parsed.data)
|
||||
@@ -181,3 +184,81 @@ export async function restoreEntryAction(input: unknown): Promise<ActionResult>
|
||||
revalidatePath(`/faelle/${parsed.data.caseNumber}`)
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Beteiligte und Verknüpfungen
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const participantSchema = z.object({
|
||||
caseNumber: z.string().min(1),
|
||||
role: z.enum(PARTICIPANT_ROLES),
|
||||
userId: z.string().max(64).optional(),
|
||||
personnelFileId: z.string().max(64).optional(),
|
||||
})
|
||||
|
||||
export async function addParticipantAction(input: unknown): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = participantSchema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors['participant-target']! }
|
||||
|
||||
try {
|
||||
await addParticipant(user.permissions, parsed.data)
|
||||
revalidatePath(`/faelle/${parsed.data.caseNumber}`)
|
||||
return { ok: true }
|
||||
} catch (error) {
|
||||
return { ok: false, error: toMessage(error) }
|
||||
}
|
||||
}
|
||||
|
||||
const removeParticipantSchema = z.object({
|
||||
caseNumber: z.string().min(1),
|
||||
participantId: z.string().min(1),
|
||||
})
|
||||
|
||||
export async function removeParticipantAction(input: unknown): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = removeParticipantSchema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors.default! }
|
||||
|
||||
try {
|
||||
await removeParticipant(user.permissions, parsed.data)
|
||||
revalidatePath(`/faelle/${parsed.data.caseNumber}`)
|
||||
return { ok: true }
|
||||
} catch (error) {
|
||||
return { ok: false, error: toMessage(error) }
|
||||
}
|
||||
}
|
||||
|
||||
const linkSchema = z.object({
|
||||
fromCaseNumber: z.string().min(1),
|
||||
toCaseNumber: z.string().min(1),
|
||||
kind: z.enum(LINK_KINDS),
|
||||
})
|
||||
|
||||
export async function linkCasesAction(input: unknown): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = linkSchema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors.default! }
|
||||
|
||||
try {
|
||||
await linkCases(user.permissions, parsed.data)
|
||||
revalidatePath(`/faelle/${parsed.data.fromCaseNumber}`)
|
||||
return { ok: true }
|
||||
} catch (error) {
|
||||
return { ok: false, error: toMessage(error) }
|
||||
}
|
||||
}
|
||||
|
||||
export async function unlinkCasesAction(input: unknown): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = linkSchema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors.default! }
|
||||
|
||||
try {
|
||||
await unlinkCases(user.permissions, parsed.data)
|
||||
revalidatePath(`/faelle/${parsed.data.fromCaseNumber}`)
|
||||
return { ok: true }
|
||||
} catch (error) {
|
||||
return { ok: false, error: toMessage(error) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,9 @@ export default async function NewCasePage() {
|
||||
const user = await requirePermission('case.create')
|
||||
|
||||
const [templates, levels] = await Promise.all([
|
||||
db.caseTemplate.findMany({
|
||||
where: { isActive: true },
|
||||
db.documentTemplate.findMany({
|
||||
// Nur Fallarten. Eine Vorlage für Dokumente legt keine Akte an.
|
||||
where: { isActive: true, uses: { has: 'CASE' } },
|
||||
orderBy: [{ key: 'asc' }, { version: 'desc' }],
|
||||
distinct: ['key'],
|
||||
select: { key: true, name: true },
|
||||
|
||||
@@ -22,6 +22,9 @@ export default async function AppLayout({ children }: { children: React.ReactNod
|
||||
<nav className="flex gap-4 font-condensed text-xs">
|
||||
<Link href="/uebersicht">{de.nav.dashboard}</Link>
|
||||
<Link href="/faelle">{de.nav.cases}</Link>
|
||||
{user.permissions.isAdmin || user.permissions.permissions.has('personnel.read') ? (
|
||||
<Link href="/personalakten">{de.nav.personnel}</Link>
|
||||
) : null}
|
||||
{user.permissions.isAdmin || user.permissions.permissions.has('roles.manage') ? (
|
||||
<>
|
||||
<Link href="/admin/rollen">{de.nav.admin}</Link>
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
'use client'
|
||||
|
||||
import { useActionState, useState, useTransition } from 'react'
|
||||
import { de } from '@/lib/i18n/de'
|
||||
import {
|
||||
reclassifyPersonnelAction,
|
||||
updatePersonnelAction,
|
||||
type ActionResult,
|
||||
} from '../actions'
|
||||
|
||||
type File = {
|
||||
id: string
|
||||
displayName: string
|
||||
serviceNumber: string | null
|
||||
rank: string | null
|
||||
department: string | null
|
||||
status: string | null
|
||||
note: string | null
|
||||
classification: number
|
||||
userId: string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Kopfdaten einer Personalakte: lesen und ändern in derselben Ansicht.
|
||||
*
|
||||
* Die Klassifizierung steht bewusst getrennt. Sie ändert, wer die Akte
|
||||
* überhaupt sieht, und eine Herabstufung braucht eine Begründung — das gehört
|
||||
* nicht in dasselbe Formular wie eine Korrektur der Dienstnummer.
|
||||
*/
|
||||
export function PersonnelHead({
|
||||
file,
|
||||
canEdit,
|
||||
levels,
|
||||
}: {
|
||||
file: File
|
||||
canEdit: boolean
|
||||
levels: { level: number; name: string }[]
|
||||
}) {
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [state, action, pending] = useActionState<ActionResult | null, FormData>(
|
||||
updatePersonnelAction,
|
||||
null,
|
||||
)
|
||||
|
||||
if (!editing) {
|
||||
return (
|
||||
<div>
|
||||
<dl className="grid gap-x-8 gap-y-2 text-sm sm:grid-cols-2">
|
||||
<Zeile label={de.personnel.serviceNumber} value={file.serviceNumber} mono />
|
||||
<Zeile label={de.personnel.rank} value={file.rank} />
|
||||
<Zeile label={de.personnel.department} value={file.department} />
|
||||
<Zeile label={de.personnel.status} value={file.status} />
|
||||
<Zeile
|
||||
label={de.personnel.linkedAccount}
|
||||
value={file.userId ? file.userId : de.personnel.noAccount}
|
||||
mono={Boolean(file.userId)}
|
||||
/>
|
||||
</dl>
|
||||
|
||||
{file.note ? (
|
||||
<p className="mt-4 max-w-(--container-measure) border-l-(length:--spacing-edge) border-line pl-3 text-sm whitespace-pre-wrap">
|
||||
{file.note}
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{canEdit ? (
|
||||
<div className="mt-4 flex flex-wrap items-center gap-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setEditing(true)}
|
||||
className="border border-line bg-raised px-3 py-1 font-condensed text-2xs text-accent"
|
||||
>
|
||||
{de.personnel.edit}
|
||||
</button>
|
||||
<Reclassify id={file.id} current={file.classification} levels={levels} />
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<form
|
||||
action={action}
|
||||
onSubmit={() => setEditing(false)}
|
||||
className="max-w-(--container-measure) space-y-4"
|
||||
>
|
||||
<input type="hidden" name="id" value={file.id} />
|
||||
<Feld id="displayName" label={de.personnel.name} defaultValue={file.displayName} required />
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<Feld
|
||||
id="serviceNumber"
|
||||
label={de.personnel.serviceNumber}
|
||||
defaultValue={file.serviceNumber}
|
||||
/>
|
||||
<Feld id="rank" label={de.personnel.rank} defaultValue={file.rank} />
|
||||
<Feld id="department" label={de.personnel.department} defaultValue={file.department} />
|
||||
<Feld id="status" label={de.personnel.status} defaultValue={file.status} />
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="note" className="font-condensed text-2xs text-text-dim">
|
||||
{de.personnel.note}
|
||||
</label>
|
||||
<textarea
|
||||
id="note"
|
||||
name="note"
|
||||
rows={3}
|
||||
defaultValue={file.note ?? ''}
|
||||
className="mt-1 block w-full border border-line bg-raised px-3 py-2 text-sm"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{state && !state.ok ? (
|
||||
<p className="font-condensed text-2xs text-stamp-4">{state.error}</p>
|
||||
) : null}
|
||||
|
||||
<div className="flex gap-3">
|
||||
<button
|
||||
type="submit"
|
||||
disabled={pending}
|
||||
className="border border-line bg-raised px-3 py-1 font-condensed text-2xs text-accent disabled:text-text-dim"
|
||||
>
|
||||
{pending ? de.common.loading : de.common.save}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setEditing(false)}
|
||||
className="font-condensed text-2xs text-text-dim"
|
||||
>
|
||||
{de.common.cancel}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
function Reclassify({
|
||||
id,
|
||||
current,
|
||||
levels,
|
||||
}: {
|
||||
id: string
|
||||
current: number
|
||||
levels: { level: number; name: string }[]
|
||||
}) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [to, setTo] = useState(current)
|
||||
const [reason, setReason] = useState('')
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [pending, startTransition] = useTransition()
|
||||
|
||||
const lowering = to < current
|
||||
|
||||
if (!open) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(true)}
|
||||
className="font-condensed text-2xs text-text-dim"
|
||||
>
|
||||
{de.personnel.reclassify}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full border border-line p-3">
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<select
|
||||
value={to}
|
||||
onChange={(event) => setTo(Number(event.target.value))}
|
||||
aria-label={de.clearance.classification}
|
||||
className="border border-line bg-raised px-2 py-1 text-2xs"
|
||||
>
|
||||
{levels.map((level) => (
|
||||
<option key={level.level} value={level.level}>
|
||||
{level.level} · {level.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<button
|
||||
type="button"
|
||||
disabled={pending || to === current}
|
||||
onClick={() =>
|
||||
startTransition(async () => {
|
||||
const result = await reclassifyPersonnelAction({ id, to, reason })
|
||||
if (result.ok) setOpen(false)
|
||||
else setError(result.error)
|
||||
})
|
||||
}
|
||||
className="border border-line bg-raised px-3 py-1 font-condensed text-2xs text-accent disabled:text-text-dim"
|
||||
>
|
||||
{de.common.save}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen(false)}
|
||||
className="font-condensed text-2xs text-text-dim"
|
||||
>
|
||||
{de.common.cancel}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Nur die Herabstufung braucht eine Begründung: sie macht die Akte für
|
||||
Leute sichtbar, die sie vorher nicht sehen durften. */}
|
||||
{lowering ? (
|
||||
<textarea
|
||||
value={reason}
|
||||
onChange={(event) => setReason(event.target.value)}
|
||||
rows={2}
|
||||
placeholder={de.case.reclassifyReason}
|
||||
aria-label={de.case.reclassifyReason}
|
||||
className="mt-2 block w-full border border-line bg-raised px-3 py-2 text-2xs"
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{error ? <p className="mt-2 font-condensed text-2xs text-stamp-4">{error}</p> : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Zeile({
|
||||
label,
|
||||
value,
|
||||
mono,
|
||||
}: {
|
||||
label: string
|
||||
value: string | null
|
||||
mono?: boolean
|
||||
}) {
|
||||
return (
|
||||
<div className="flex gap-3">
|
||||
<dt className="font-condensed text-xs text-text-dim">{label}</dt>
|
||||
<dd className={mono ? 'font-mono text-xs' : ''}>{value || '—'}</dd>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Feld({
|
||||
id,
|
||||
label,
|
||||
defaultValue,
|
||||
required,
|
||||
}: {
|
||||
id: string
|
||||
label: string
|
||||
defaultValue?: string | null
|
||||
required?: boolean
|
||||
}) {
|
||||
return (
|
||||
<div>
|
||||
<label htmlFor={id} className="font-condensed text-2xs text-text-dim">
|
||||
{label}
|
||||
</label>
|
||||
<input
|
||||
id={id}
|
||||
name={id}
|
||||
required={required}
|
||||
minLength={required ? 2 : undefined}
|
||||
maxLength={120}
|
||||
defaultValue={defaultValue ?? ''}
|
||||
className="mt-1 block w-full border border-line bg-raised px-3 py-2 text-sm"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Skeleton, SkeletonLine } from '@/components/Skeleton'
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl px-6 py-10">
|
||||
<div className="pl-3">
|
||||
<Skeleton className="h-[0.9rem]" width="8rem" />
|
||||
<div className="mt-2">
|
||||
<Skeleton className="h-[1.6rem]" width="18rem" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-8 space-y-3">
|
||||
<Skeleton className="h-[1.1rem]" width="7rem" />
|
||||
<SkeletonLine width="60%" />
|
||||
<SkeletonLine width="45%" />
|
||||
</div>
|
||||
<div className="mt-10 space-y-3">
|
||||
<Skeleton className="h-[1.1rem]" width="9rem" />
|
||||
<SkeletonLine width="70%" />
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
import type { Metadata } from 'next'
|
||||
import { Suspense } from 'react'
|
||||
import Link from 'next/link'
|
||||
import { notFound } from 'next/navigation'
|
||||
import { db } from '@/lib/db'
|
||||
import { requirePermission } from '@/lib/auth/current'
|
||||
import { recordRead, READ_AUDIT_FROM_LEVEL } from '@/lib/audit'
|
||||
import { loadBacklinks, loadVisiblePersonnelFile } from '@/lib/personnel/service'
|
||||
import { listDocuments, listTemplatesFor } from '@/lib/documents/service'
|
||||
import { canWritePersonnel } from '@/lib/access/documentWrite'
|
||||
import { de } from '@/lib/i18n/de'
|
||||
import { StampMark, classificationEdgeStyle } from '@/components/StampMark'
|
||||
import { SkeletonLine } from '@/components/Skeleton'
|
||||
import { DocumentList } from '@/components/documents/DocumentList'
|
||||
import { NewDocument } from '@/components/documents/NewDocument'
|
||||
import { PersonnelHead } from './PersonnelHead'
|
||||
import type { EffectivePermissions } from '@/lib/auth/permissions'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>
|
||||
}): Promise<Metadata> {
|
||||
const user = await requirePermission('personnel.read')
|
||||
const { id } = await params
|
||||
const akte = await loadVisiblePersonnelFile(user.permissions, id)
|
||||
return { title: akte?.displayName ?? de.personnel.one }
|
||||
}
|
||||
|
||||
/**
|
||||
* Rückverweise: die Fälle, in denen diese Person vorkommt.
|
||||
*
|
||||
* Streamt in einer eigenen Suspense-Grenze nach, weil die Abfrage über die
|
||||
* Sichtbarkeitsprüfung der Fallakten läuft und damit die teuerste auf dieser
|
||||
* Seite ist. Die Kopfdaten stehen währenddessen schon.
|
||||
*/
|
||||
async function Backlinks({
|
||||
file,
|
||||
permissions,
|
||||
}: {
|
||||
file: { id: string; userId: string | null }
|
||||
permissions: EffectivePermissions
|
||||
}) {
|
||||
const { total, byRole } = await loadBacklinks(permissions, file)
|
||||
|
||||
if (total === 0) {
|
||||
return <p className="text-text-dim">{de.personnel.backlinksEmpty}</p>
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{byRole.map(({ role, eintraege }) => (
|
||||
<div key={role}>
|
||||
<h3 className="font-condensed text-xs text-text-dim">
|
||||
{de.participant.roles[role] ?? role}
|
||||
</h3>
|
||||
<ul className="mt-2 border-t border-line">
|
||||
{eintraege.map(({ case: akte }) => (
|
||||
<li key={`${role}:${akte.id}`} className="border-b border-line">
|
||||
<Link
|
||||
href={`/faelle/${akte.caseNumber}`}
|
||||
prefetch
|
||||
className="flex flex-wrap items-baseline gap-x-4 gap-y-1 py-2 pl-3 text-text no-underline"
|
||||
style={classificationEdgeStyle(akte.classification)}
|
||||
>
|
||||
<span className="font-mono text-xs text-text-dim">{akte.caseNumber}</span>
|
||||
<span className="grow">{akte.title}</span>
|
||||
<span className="font-condensed text-2xs text-text-dim">
|
||||
{de.case.statusNames[akte.status]}
|
||||
</span>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
async function Documents({
|
||||
file,
|
||||
permissions,
|
||||
canEdit,
|
||||
}: {
|
||||
file: { id: string; classification: number }
|
||||
permissions: EffectivePermissions
|
||||
canEdit: boolean
|
||||
}) {
|
||||
const [documents, templates, levels] = await Promise.all([
|
||||
listDocuments(permissions, { personnelFileId: file.id }),
|
||||
canEdit ? listTemplatesFor('PERSON_DOCUMENT') : Promise.resolve([]),
|
||||
db.clearanceLevelConfig.findMany({ orderBy: { level: 'asc' } }),
|
||||
])
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<DocumentList
|
||||
documents={documents}
|
||||
levelName={new Map(levels.map((l) => [l.level, l.name]))}
|
||||
/>
|
||||
{canEdit ? (
|
||||
<NewDocument
|
||||
templates={templates}
|
||||
levels={levels.filter((l) => l.level <= permissions.clearanceLevel)}
|
||||
defaultLevel={Math.min(file.classification, permissions.clearanceLevel)}
|
||||
personnelFileId={file.id}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default async function PersonnelPage({ params }: { params: Promise<{ id: string }> }) {
|
||||
const user = await requirePermission('personnel.read')
|
||||
const { id } = await params
|
||||
|
||||
const akte = await loadVisiblePersonnelFile(user.permissions, id)
|
||||
// Kein Zugriff heisst 404, nicht 403: die Existenz ist selbst eine Information.
|
||||
if (!akte) notFound()
|
||||
|
||||
// Harte Regel 3: jeder Lesezugriff ab Stufe 3 wird protokolliert.
|
||||
if (akte.classification >= READ_AUDIT_FROM_LEVEL) {
|
||||
recordRead({
|
||||
actorId: user.id,
|
||||
action: 'personnel.read',
|
||||
targetType: 'PersonnelFile',
|
||||
targetId: akte.id,
|
||||
clearanceAtTime: user.permissions.clearanceLevel,
|
||||
meta: { displayName: akte.displayName, classification: akte.classification },
|
||||
})
|
||||
}
|
||||
|
||||
const levels = await db.clearanceLevelConfig.findMany({ orderBy: { level: 'asc' } })
|
||||
const level = levels.find((l) => l.level === akte.classification)
|
||||
const canEdit = canWritePersonnel(user.permissions, akte.classification).ok
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl px-6 py-10">
|
||||
<header className="pl-3" style={classificationEdgeStyle(akte.classification)}>
|
||||
<div className="flex flex-wrap items-baseline gap-x-4 gap-y-2">
|
||||
<span className="font-condensed text-xs text-text-dim">{de.personnel.one}</span>
|
||||
<StampMark level={akte.classification} name={level?.name ?? de.common.unknown} />
|
||||
</div>
|
||||
<h1 className="mt-2 font-condensed">{akte.displayName}</h1>
|
||||
</header>
|
||||
|
||||
<section className="mt-8">
|
||||
<h2 className="font-condensed">{de.personnel.headData}</h2>
|
||||
<div className="mt-4">
|
||||
<PersonnelHead
|
||||
file={akte}
|
||||
canEdit={canEdit}
|
||||
levels={levels.filter((l) => l.level <= user.permissions.clearanceLevel)}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="mt-10">
|
||||
<h2 className="font-condensed">{de.document.heading}</h2>
|
||||
<div className="mt-4">
|
||||
<Suspense fallback={<SkeletonLine width="60%" />}>
|
||||
<Documents file={akte} permissions={user.permissions} canEdit={canEdit} />
|
||||
</Suspense>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="mt-10">
|
||||
<h2 className="font-condensed">{de.personnel.backlinks}</h2>
|
||||
<div className="mt-4">
|
||||
<Suspense
|
||||
fallback={
|
||||
<div className="space-y-3">
|
||||
<SkeletonLine width="8rem" />
|
||||
<SkeletonLine width="70%" />
|
||||
<SkeletonLine width="55%" />
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Backlinks file={akte} permissions={user.permissions} />
|
||||
</Suspense>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
'use server'
|
||||
|
||||
import { revalidatePath } from 'next/cache'
|
||||
import { redirect } from 'next/navigation'
|
||||
import { z } from 'zod'
|
||||
import { requireUser } from '@/lib/auth/current'
|
||||
import { AccessError } from '@/lib/errors'
|
||||
import {
|
||||
createPersonnelFile,
|
||||
reclassifyPersonnelFile,
|
||||
updatePersonnelFile,
|
||||
} from '@/lib/personnel/service'
|
||||
import { de } from '@/lib/i18n/de'
|
||||
|
||||
export type ActionResult = { ok: true } | { ok: false; error: string }
|
||||
|
||||
function toMessage(error: unknown): string {
|
||||
if (error instanceof AccessError) {
|
||||
return de.actionErrors[error.code] ?? de.actionErrors.default!
|
||||
}
|
||||
console.error('[personalakten] unerwartet', error)
|
||||
return de.actionErrors.default!
|
||||
}
|
||||
|
||||
const kopfdaten = {
|
||||
displayName: z.string().min(2).max(120),
|
||||
serviceNumber: z.string().max(60).optional(),
|
||||
rank: z.string().max(60).optional(),
|
||||
department: z.string().max(60).optional(),
|
||||
status: z.string().max(60).optional(),
|
||||
note: z.string().max(2000).optional(),
|
||||
}
|
||||
|
||||
const createSchema = z.object({
|
||||
...kopfdaten,
|
||||
userId: z.string().max(64).optional(),
|
||||
classification: z.coerce.number().int().min(0).max(5),
|
||||
})
|
||||
|
||||
export async function createPersonnelAction(
|
||||
_prev: ActionResult | null,
|
||||
formData: FormData,
|
||||
): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = createSchema.safeParse(Object.fromEntries(formData))
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors['name-required']! }
|
||||
|
||||
let id: string
|
||||
try {
|
||||
const created = await createPersonnelFile(user.permissions, parsed.data)
|
||||
id = created.id
|
||||
} catch (error) {
|
||||
return { ok: false, error: toMessage(error) }
|
||||
}
|
||||
|
||||
// Nach dem Anlegen direkt in die Akte, nicht zurück in die Liste.
|
||||
redirect(`/personalakten/${id}`)
|
||||
}
|
||||
|
||||
const updateSchema = z.object({ id: z.string().min(1), ...kopfdaten })
|
||||
|
||||
export async function updatePersonnelAction(
|
||||
_prev: ActionResult | null,
|
||||
formData: FormData,
|
||||
): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = updateSchema.safeParse(Object.fromEntries(formData))
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors['name-required']! }
|
||||
|
||||
try {
|
||||
const { id, ...rest } = parsed.data
|
||||
await updatePersonnelFile(user.permissions, id, rest)
|
||||
revalidatePath(`/personalakten/${id}`)
|
||||
return { ok: true }
|
||||
} catch (error) {
|
||||
return { ok: false, error: toMessage(error) }
|
||||
}
|
||||
}
|
||||
|
||||
const reclassifySchema = z.object({
|
||||
id: z.string().min(1),
|
||||
to: z.coerce.number().int().min(0).max(5),
|
||||
reason: z.string().max(2000).optional(),
|
||||
})
|
||||
|
||||
export async function reclassifyPersonnelAction(input: unknown): Promise<ActionResult> {
|
||||
const user = await requireUser()
|
||||
const parsed = reclassifySchema.safeParse(input)
|
||||
if (!parsed.success) return { ok: false, error: de.actionErrors.default! }
|
||||
|
||||
try {
|
||||
await reclassifyPersonnelFile(
|
||||
user.permissions,
|
||||
parsed.data.id,
|
||||
parsed.data.to,
|
||||
parsed.data.reason,
|
||||
)
|
||||
revalidatePath(`/personalakten/${parsed.data.id}`)
|
||||
return { ok: true }
|
||||
} catch (error) {
|
||||
return { ok: false, error: toMessage(error) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { Skeleton, SkeletonLine } from '@/components/Skeleton'
|
||||
|
||||
export default function Loading() {
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl px-6 py-10">
|
||||
<Skeleton className="h-[1.5rem]" width="12rem" />
|
||||
<div className="mt-4">
|
||||
<Skeleton className="h-[2.4rem]" width="24rem" />
|
||||
</div>
|
||||
<div className="mt-6 border-t border-line">
|
||||
{Array.from({ length: 8 }, (_, index) => (
|
||||
<div key={index} className="border-b border-line py-3 pl-3">
|
||||
<SkeletonLine width={`${45 + ((index * 11) % 40)}%`} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
'use client'
|
||||
|
||||
import { useActionState } from 'react'
|
||||
import { de } from '@/lib/i18n/de'
|
||||
import { createPersonnelAction, type ActionResult } from '../actions'
|
||||
|
||||
/**
|
||||
* Neue Personalakte.
|
||||
*
|
||||
* Das Discord-Konto ist **optional**. Personen ohne Konto — Zeugen, ehemalige
|
||||
* Mitarbeiter, Externe — brauchen genauso eine Akte, und ihr Name ist dann das
|
||||
* einzige, was sie identifiziert.
|
||||
*/
|
||||
export function NewPersonnelForm({
|
||||
members,
|
||||
levels,
|
||||
defaultLevel,
|
||||
}: {
|
||||
members: { id: string; displayName: string }[]
|
||||
levels: { level: number; name: string }[]
|
||||
defaultLevel: number
|
||||
}) {
|
||||
const [state, action, pending] = useActionState<ActionResult | null, FormData>(
|
||||
createPersonnelAction,
|
||||
null,
|
||||
)
|
||||
|
||||
return (
|
||||
<form action={action} className="mt-6 space-y-5">
|
||||
<Feld id="displayName" label={de.personnel.name} required minLength={2} />
|
||||
|
||||
<div>
|
||||
<label htmlFor="userId" className="font-condensed text-xs text-text-dim">
|
||||
{de.personnel.linkedAccount}
|
||||
</label>
|
||||
<select
|
||||
id="userId"
|
||||
name="userId"
|
||||
defaultValue=""
|
||||
className="mt-1.5 block w-full border border-line bg-raised px-3 py-2 text-sm"
|
||||
>
|
||||
<option value="">{de.personnel.noAccount}</option>
|
||||
{members.map((member) => (
|
||||
<option key={member.id} value={member.id}>
|
||||
{member.displayName}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-5 sm:grid-cols-2">
|
||||
<Feld id="serviceNumber" label={de.personnel.serviceNumber} />
|
||||
<Feld id="rank" label={de.personnel.rank} />
|
||||
<Feld id="department" label={de.personnel.department} />
|
||||
<Feld id="status" label={de.personnel.status} />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="note" className="font-condensed text-xs text-text-dim">
|
||||
{de.personnel.note}
|
||||
</label>
|
||||
<textarea
|
||||
id="note"
|
||||
name="note"
|
||||
rows={3}
|
||||
className="mt-1.5 block w-full border border-line bg-raised px-3 py-2 text-sm"
|
||||
/>
|
||||
<p className="mt-1 text-2xs text-text-dim">{de.personnel.noteHelp}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="classification" className="font-condensed text-xs text-text-dim">
|
||||
{de.clearance.classification}
|
||||
</label>
|
||||
{/* Die Auswahl zeigt nur, was erlaubt ist. Geprüft wird trotzdem serverseitig. */}
|
||||
<select
|
||||
id="classification"
|
||||
name="classification"
|
||||
defaultValue={defaultLevel}
|
||||
className="mt-1.5 block border border-line bg-raised px-3 py-2 text-sm"
|
||||
>
|
||||
{levels.map((level) => (
|
||||
<option key={level.level} value={level.level}>
|
||||
{level.level} · {level.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{state && !state.ok ? (
|
||||
<p className="font-condensed text-2xs text-stamp-4">{state.error}</p>
|
||||
) : null}
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={pending}
|
||||
className="border border-line bg-raised px-4 py-2 font-condensed text-sm text-accent disabled:text-text-dim"
|
||||
>
|
||||
{pending ? de.common.loading : de.personnel.create}
|
||||
</button>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
function Feld({
|
||||
id,
|
||||
label,
|
||||
required,
|
||||
minLength,
|
||||
}: {
|
||||
id: string
|
||||
label: string
|
||||
required?: boolean
|
||||
minLength?: number
|
||||
}) {
|
||||
return (
|
||||
<div>
|
||||
<label htmlFor={id} className="font-condensed text-xs text-text-dim">
|
||||
{label}
|
||||
</label>
|
||||
<input
|
||||
id={id}
|
||||
name={id}
|
||||
required={required}
|
||||
minLength={minLength}
|
||||
maxLength={120}
|
||||
className="mt-1.5 block w-full border border-line bg-raised px-3 py-2 text-sm"
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import type { Metadata } from 'next'
|
||||
import { db } from '@/lib/db'
|
||||
import { requirePermission } from '@/lib/auth/current'
|
||||
import { de } from '@/lib/i18n/de'
|
||||
import { NewPersonnelForm } from './NewPersonnelForm'
|
||||
|
||||
export const metadata: Metadata = { title: de.personnel.createTitle }
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
export default async function NewPersonnelPage() {
|
||||
const user = await requirePermission('personnel.edit')
|
||||
|
||||
const [levels, members] = await Promise.all([
|
||||
db.clearanceLevelConfig.findMany({ orderBy: { level: 'asc' } }),
|
||||
// Nur Konten, für die es noch keine Akte gibt: zwei Akten zu einer Person
|
||||
// wären zwei Wahrheiten.
|
||||
db.user.findMany({
|
||||
where: { personnelFiles: { none: {} } },
|
||||
orderBy: { displayName: 'asc' },
|
||||
take: 200,
|
||||
select: { id: true, displayName: true },
|
||||
}),
|
||||
])
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-(--container-measure) px-6 py-10">
|
||||
<h1 className="font-condensed">{de.personnel.createTitle}</h1>
|
||||
<p className="mt-2 max-w-(--container-measure) text-sm text-text-dim">
|
||||
{de.personnel.createHint}
|
||||
</p>
|
||||
<NewPersonnelForm
|
||||
members={members}
|
||||
levels={levels.filter((level) => level.level <= user.permissions.clearanceLevel)}
|
||||
defaultLevel={Math.min(1, user.permissions.clearanceLevel)}
|
||||
/>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import type { Metadata } from 'next'
|
||||
import Link from 'next/link'
|
||||
import { db } from '@/lib/db'
|
||||
import { requirePermission } from '@/lib/auth/current'
|
||||
import { listPersonnelFiles } from '@/lib/personnel/service'
|
||||
import { de } from '@/lib/i18n/de'
|
||||
import { StampMark, classificationEdgeStyle } from '@/components/StampMark'
|
||||
|
||||
export const metadata: Metadata = { title: de.personnel.listHeading }
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
/**
|
||||
* Liste der Personalakten.
|
||||
*
|
||||
* Wie bei den Fallakten: Suche, Sichtbarkeit und Zählung laufen über dieselbe
|
||||
* Abfrage. Eine Akte über der Stufe des Lesers taucht weder auf noch in der
|
||||
* Zahl daneben.
|
||||
*/
|
||||
export default async function PersonnelListPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: Promise<{ q?: string }>
|
||||
}) {
|
||||
// Ohne das Recht gibt es die Seite nicht — 404, nicht 403.
|
||||
const user = await requirePermission('personnel.read')
|
||||
const { q } = await searchParams
|
||||
|
||||
const [{ files, total }, levels] = await Promise.all([
|
||||
listPersonnelFiles(user.permissions, { query: q }),
|
||||
db.clearanceLevelConfig.findMany({ orderBy: { level: 'asc' } }),
|
||||
])
|
||||
const levelName = new Map(levels.map((l) => [l.level, l.name]))
|
||||
const darfAnlegen =
|
||||
user.permissions.isAdmin || user.permissions.permissions.has('personnel.edit')
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl px-6 py-10">
|
||||
<div className="flex flex-wrap items-baseline justify-between gap-4">
|
||||
<h1 className="font-condensed">{de.personnel.listHeading}</h1>
|
||||
<span className="font-mono text-xs text-text-dim">{de.personnel.countLabel(total)}</span>
|
||||
</div>
|
||||
|
||||
<form method="get" className="mt-4 flex flex-wrap items-center gap-3">
|
||||
<input
|
||||
type="search"
|
||||
name="q"
|
||||
defaultValue={q ?? ''}
|
||||
placeholder={de.personnel.search}
|
||||
aria-label={de.personnel.search}
|
||||
className="w-full max-w-sm border border-line bg-raised px-3 py-2 text-sm"
|
||||
/>
|
||||
{darfAnlegen ? (
|
||||
<Link href="/personalakten/neu" className="ml-auto font-condensed text-xs">
|
||||
{de.personnel.create}
|
||||
</Link>
|
||||
) : null}
|
||||
</form>
|
||||
|
||||
{files.length === 0 ? (
|
||||
<p className="mt-10 text-text-dim">
|
||||
{q ? de.personnel.emptySearch : de.personnel.empty}
|
||||
</p>
|
||||
) : (
|
||||
<ul className="mt-6 border-t border-line">
|
||||
{files.map((akte) => (
|
||||
<li key={akte.id} className="border-b border-line">
|
||||
<Link
|
||||
href={`/personalakten/${akte.id}`}
|
||||
prefetch
|
||||
className="flex flex-wrap items-baseline gap-x-4 gap-y-1 py-3 pl-3 text-text no-underline"
|
||||
style={classificationEdgeStyle(akte.classification)}
|
||||
>
|
||||
<span className="grow">{akte.displayName}</span>
|
||||
{akte.serviceNumber ? (
|
||||
<span className="font-mono text-xs text-text-dim">{akte.serviceNumber}</span>
|
||||
) : null}
|
||||
{akte.rank ? (
|
||||
<span className="font-condensed text-2xs text-text-dim">{akte.rank}</span>
|
||||
) : null}
|
||||
<StampMark
|
||||
level={akte.classification}
|
||||
name={levelName.get(akte.classification) ?? de.common.unknown}
|
||||
/>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</main>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user