import { EntityAction, EntityListHeader, EntityRowActions, EntityTable, } from "@repo/rdx-ui/components/entity-list"; import { PhoneLink } from "@repo/rdx-ui/components/phone-link"; import { BriefcaseIcon, ChevronLeftIcon, MailIcon, PencilIcon, PhoneIcon, } from "@repo/rdx-ui/lib/icons"; import { createTextMatcher } from "@repo/rdx-ui/lib/text-search"; import { AvatarBadge } from "@repo/shadcn-ui/components/avatar"; import { Button } from "@repo/shadcn-ui/components/button"; import { Card, CardContent } from "@repo/shadcn-ui/components/card"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import type { CompanyDTO, PersonDTO } from "../../../../common"; import { AssignmentEditorDialog, AssignmentHistoryDialog } from "../../../assignments"; import { deleteAssignment } from "../../../assignments/shared/api"; import { useDetailTableContext } from "../../../shared/hooks/use-detail-table-context"; import { PersonAvatar } from "../../shared"; import { deletePerson } from "../../shared/api"; import { CurrentWorkstations } from "./current-workstations"; export function PersonDetails({ company, person, onBack, onEdit, }: { company: CompanyDTO; person: PersonDTO; onBack: () => void; onEdit: () => void; }) { const { t, i18n } = useTranslation("companies"); const [editor, setEditor] = useState(); const [historyId, setHistoryId] = useState(); const [deleting, setDeleting] = useState(false); const [deletingAssignment, setDeletingAssignment] = useState(); const assignments = company.assignments.filter((item) => item.personId === person.id); const tableContext = useDetailTableContext( `/companies/${company.id}/people/${person.id}`, "assignments", true ); const selected = assignments.find((item) => item.id === editor); const history = assignments.find((item) => item.id === historyId); const departmentName = (id: string) => company.departments.find((item) => item.id === id)?.name ?? "—"; const matches = createTextMatcher(tableContext.search); const visible = assignments.filter((item) => [ departmentName(item.departmentId), item.position, item.startDate, item.endDate, item.isPrimary, ].some(matches) ); return (
{t(person.active ? "activePerson" : "inactivePerson")}

{person.name}

{person.phone ? : "—"}
{!person.active && assignments.some((item) => item.endDate === null) && (

{t("inactiveMembershipWarning")}

)} setEditor("new")}> { if (!open) { setEditor(undefined); } }} onSaved={() => setEditor(undefined)} personId={person.id} selected={selected} /> { if (!open) { setHistoryId(undefined); } }} />
); }