'use client' import { useState, useTransition } from 'react' import Link from 'next/link' import { commonText } from '@/lib/i18n/common' import { participantText } from '@/lib/i18n/cases' import { PARTICIPANT_ROLES } from '@/lib/cases/terms' import { AddPanel, PanelSelect } from '@/components/AddPanel' 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 [role, setRole] = useState('INVESTIGATOR') const [target, setTarget] = useState('') const [fehler, setFehler] = useState(null) const [pending, startTransition] = useTransition() return (
{participants.length === 0 ? (

{participantText.empty}

) : (
    {participants.map((person) => (
  • {participantText.roles[person.role] ?? person.role} {person.personnelFileId ? ( {person.displayName ?? commonText.unknown} ) : ( (person.displayName ?? commonText.unknown) )} {canEdit ? ( ) : null}
  • ))}
)} {fehler ?

{fehler}

: null} {canEdit ? ( { const [art, id] = target.split(':') const ergebnis = await addParticipantAction({ caseNumber, role, ...(art === 'user' ? { userId: id } : { personnelFileId: id }), }) if (ergebnis.ok) setTarget('') return ergebnis }} > {PARTICIPANT_ROLES.map((value) => ( ))} {members.map((member) => ( ))} {files.map((file) => ( ))} ) : null}
) }