'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('INVESTIGATOR') const [target, setTarget] = useState('') const [error, setError] = useState(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 (
{participants.length === 0 ? (

{de.participant.empty}

) : (
    {participants.map((person) => (
  • {de.participant.roles[person.role] ?? person.role} {person.personnelFileId ? ( {person.displayName ?? de.common.unknown} ) : ( (person.displayName ?? de.common.unknown) )} {canEdit ? ( ) : null}
  • ))}
)} {error ?

{error}

: null} {canEdit ? ( open ? (

{de.participant.hint}

) : ( ) ) : null}
) }