/opt/mawid/apps/dashboard/app/(app)/conversations/[id]
NameSizeModeActions
page.tsx39110644editdlrm
Edit: /opt/mawid/apps/dashboard/app/(app)/conversations/[id]/page.tsx (3911B)
'use client'; import { useCallback, useEffect, useState } from 'react'; import { useParams, useRouter } from 'next/navigation'; import { api } from '@/lib/api'; import { useLang } from '@/lib/i18n'; import { Badge, Button, Card, Spinner } from '@/components/ui'; interface MessageRow { id: string; direction: 'inbound' | 'outbound'; type: string; body: string | null; createdAt: string; } interface ConversationRow { id: string; patient: { name: string | null; waPhone: string }; handedOff: boolean; } export default function ConversationDetailPage() { const { t, lang } = useLang(); const params = useParams<{ id: string }>(); const router = useRouter(); const [messages, setMessages] = useState(null); const [conversation, setConversation] = useState(null); const load = useCallback(async () => { const [list, msgs] = await Promise.all([ api('/conversations'), api(`/conversations/${params.id}/messages`), ]); const current = list.find((c) => c.id === params.id) ?? null; setConversation(current); setMessages(msgs); }, [params.id]); useEffect(() => { load().catch(() => router.push('/conversations')); }, [load, router]); async function toggleTakeover() { if (!conversation) return; await api(`/conversations/${params.id}/${conversation.handedOff ? 'resume' : 'takeover'}`, { method: 'POST', }); load(); } if (messages === null || conversation === null) return ; return (
{conversation.handedOff ? t('agentPaused') : t('agentActive')}
{conversation.patient.name ?? conversation.patient.waPhone}{' '} {conversation.patient.waPhone}
{messages.length === 0 &&

{t('noMessages')}

} {messages.map((message) => (
{message.body ?? `[${message.type}]`}
{new Date(message.createdAt).toLocaleString(lang === 'ar' ? 'ar' : lang, { day: 'numeric', month: 'short', hour: '2-digit', minute: '2-digit', })}
))}
); }