import { useParams, Link } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { extractApiError } from '@/api/client'; import { useAuth } from '@/hooks/useAuth'; import { useEngagement } from '@/hooks/useEngagements'; import { useHashTab } from '@/hooks/useHashTab'; import { useEngagementSimulations } from '@/hooks/useSimulations'; import { LoadingState } from '@/components/LoadingState'; import { ErrorState } from '@/components/ErrorState'; import { StatusBadge } from '@/components/StatusBadge'; import { SimulationList } from '@/components/SimulationList'; import { ExportEngagementButton } from '@/components/ExportEngagementButton'; import { BackLink } from '@/components/BackLink'; import { Tabs } from '@/components/Tabs'; import { formatDate } from '@/lib/format'; type TabId = 'description' | 'simulations'; export function EngagementDetailPage(): JSX.Element { const { t } = useTranslation(); const { id } = useParams<{ id: string }>(); const numericId = id ? Number(id) : undefined; const { canEditEngagements } = useAuth(); const detail = useEngagement(numericId); const simsQuery = useEngagementSimulations(numericId); const [activeTabRaw, setActiveTab] = useHashTab('description'); const activeTab = activeTabRaw as TabId; if (detail.isLoading) return ; if (detail.isError) { return ( detail.refetch()} /> ); } if (!detail.data) return ; const eng = detail.data; const simCount = simsQuery.data?.length; const tabs = [ { id: 'description', label: t('engagement.detail.tabs.description') }, { id: 'simulations', label: t('engagement.detail.tabs.simulations'), count: simCount }, ]; return ( {t('engagement.detail.backTo')} {eng.name} {t('engagement.detail.createdBy')}{' '} {eng.created_by.username} {canEditEngagements ? ( ) : null} {activeTab === 'description' && ( {t('engagement.detail.schedule.startDate')} {formatDate(eng.start_date)} {t('engagement.detail.schedule.endDate')} {eng.end_date ? formatDate(eng.end_date) : '—'} {t('engagement.detail.schedule.status')} {t('engagement.detail.schedule.createdAt')} {formatDate(eng.created_at)} {canEditEngagements ? ( {t('engagement.detail.edit')} ) : null} {t('engagement.detail.tabs.description')} {eng.description?.trim() ? eng.description : t('engagement.detail.noDescription')} )} {activeTab === 'simulations' && ( )} ); }
{eng.description?.trim() ? eng.description : t('engagement.detail.noDescription')}