import { memo } from 'react' import { Pencil, Trash2 } from 'lucide-react' import type { Organisation } from '../../../../entities/employee/model/types' function getOrganisationInitials(name: string) { const words = name.trim().split(/\s+/).filter(Boolean) if (words.length === 0) return 'ОР' return words .slice(0, 2) .map((word) => word[0]) .join('') .toUpperCase() } function formatCreationDate(timestamp?: number) { if (!timestamp) return 'Дата создания не указана' return `Создана ${new Intl.DateTimeFormat('ru-RU', { day: '2-digit', month: '2-digit', year: 'numeric', }).format(new Date(timestamp))}` } type OrganisationsTableProps = { organisations: Organisation[] onOpen: (organisation: Organisation) => void onEdit: (organisation: Organisation) => void onDelete: (organisation: Organisation) => void } type OrganisationTableRowProps = { organisation: Organisation onOpen: (organisation: Organisation) => void onEdit: (organisation: Organisation) => void onDelete: (organisation: Organisation) => void } const OrganisationTableRow = memo(function OrganisationTableRow({ organisation, onOpen, onEdit, onDelete, }: OrganisationTableRowProps) { return ( onOpen(organisation)} onKeyDown={(event) => { if (event.key === 'Enter') { onOpen(organisation) } }} > {organisation.id}
{organisation.logoUrl ? ( {organisation.name} ) : ( {getOrganisationInitials(organisation.name)} )}
{organisation.name} {formatCreationDate(organisation.creationDate)}
) }) export const OrganisationsTable = memo(function OrganisationsTable({ organisations, onOpen, onEdit, onDelete, }: OrganisationsTableProps) { return ( {organisations.map((organisation) => ( ))}
ID Название организации Управление
) })