fix(newwhats): resolve conversa por 9º dígito e nome do paciente no slot da agenda

- WhatsChatDrawer: busca o chat pelos últimos 8 dígitos (o WhatsApp grava o jid BR
  sem o 9º dígito, ex. 556799591687), evitando falso "sem conversa"
- AgendaView: slot usa pacienteNome || pacientenome (backend retorna minúsculo),
  corrigindo o card que não exibia o nome do paciente

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
VPS 4 Builder
2026-07-03 00:29:02 +02:00
parent 21bebd3256
commit c2a1f8f701
2 changed files with 8 additions and 4 deletions
+5 -2
View File
@@ -161,8 +161,11 @@ const DrawerInner: React.FC<Omit<WhatsChatDrawerProps, 'isOpen'>> = ({ onClose,
store.setActiveChat(null);
try {
const send = normalizeSendPhone(phoneDigits);
// O GET /inbox?search=<dígitos> casa por `jid contains` no backend.
await store.loadChats(activeInstanceId, { search: send });
// Busca pelos ÚLTIMOS 8 dígitos (estáveis): o WhatsApp grava o jid do BR sem o
// 9º dígito (ex.: 556799591687), então buscar o número completo (13 dígitos)
// não casaria no `jid contains` do backend. O samePhone (últimos 8) filtra.
const tail8 = send.replace(/\D/g, '').slice(-8);
await store.loadChats(activeInstanceId, { search: tail8 });
const chats = useChatStore.getState().chats;
const hit = chats.find((c) =>
samePhone(c.contactPhone || c.jid.split('@')[0], send)) ?? null;