// Copyright: © 2026 TWWIM UG. All rights reserved. (www.twwim.com) /** * "Captured this session" block — renders inside VisitorContextPanel when * the visitor has submitted the contact-capture form for the current * conversation. Polls /captured-contact every 5 s via useCapturedContact. * * When `captured === null` (or pending) the component returns null so the * surrounding panel stays compact. No empty-state copy. */ import { useTranslation } from '@/i18n/TranslationProvider'; import { useCapturedContact } from '../hooks/useCapturedContact'; interface CapturedContactBlockProps { conversationId: string; } function relativeWhen(date: string, locale: string): string { const target = new Date(date); const diffMs = Date.now() - target.getTime(); const minutes = Math.floor(diffMs / 60_000); if (minutes < 1) return locale === 'de' ? 'gerade eben' : 'just now'; if (minutes < 60) return locale === 'de' ? `vor ${minutes} Min.` : `${minutes} min ago`; const hours = Math.floor(minutes / 60); if (hours < 24) return locale === 'de' ? `vor ${hours} Std.` : `${hours} h ago`; const days = Math.floor(hours / 24); return locale === 'de' ? `vor ${days} Tagen` : `${days} d ago`; } export function CapturedContactBlock({ conversationId }: CapturedContactBlockProps) { const { t, locale } = useTranslation(); const { data } = useCapturedContact(conversationId); if (!data || !data.captured) return null; const { values, capturedAt } = data.captured; const entries = Object.entries(values); return (

{t('conversations.captured.title')}

{entries.map(([key, value]) => (
{key} {value}
))}
{t('conversations.captured.capturedAt', { when: relativeWhen(capturedAt, locale) })}
); }