From 5f51bc068eb1d1907f7387bce74b2b4b57eee16e Mon Sep 17 00:00:00 2001 From: Leonardo Date: Thu, 23 Apr 2026 11:22:07 -0300 Subject: [PATCH] =?UTF-8?q?Fix=20deeplink=20/crm/conversas=20n=C3=A3o=20ex?= =?UTF-8?q?iste;=20alias=20din=C3=A2mico=20por=20role?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: toast do SLA tinha deeplink /crm/conversas que caía em NotFound. As rotas reais são /therapist/conversas (terapeuta) e /admin/conversas (clinic_admin), contextuais por role. Fix: novo sistema de aliases em AppLayout.resolveDeeplink. DEEPLINK_ALIASES traduz links semânticos (ex: /conversas, /crm/conversas) pra rota real baseado em tenantStore.activeRole. Edge do SLA agora emite /conversas (alias) em vez de path hardcoded; frontend resolve. Padrão aplicável pras próximas features — basta registrar novo alias aqui quando a rota depender de contexto. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/layout/AppLayout.vue | 23 ++++++++++++++++--- .../functions/conversation-sla-check/index.ts | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/layout/AppLayout.vue b/src/layout/AppLayout.vue index fecf9d3..8f20cb4 100644 --- a/src/layout/AppLayout.vue +++ b/src/layout/AppLayout.vue @@ -21,12 +21,29 @@ import { useRoute, useRouter } from 'vue-router'; const router = useRouter(); +// Aliases "semânticos" → resolvidos pra rota real com base no role atual. +// Evita que deeplinks gravados no backend quebrem se o caminho da rota mudar +// ou se o usuário logado pertencer a outro contexto (therapist vs clinic_admin). +const DEEPLINK_ALIASES = { + '/crm/conversas': { therapist: '/therapist/conversas', clinic_admin: '/admin/conversas' }, + '/conversas': { therapist: '/therapist/conversas', clinic_admin: '/admin/conversas' } +}; + +function resolveDeeplink(link) { + if (!link || typeof link !== 'string') return link; + const alias = DEEPLINK_ALIASES[link]; + if (!alias) return link; + const role = tenantStore?.activeRole || 'therapist'; + return alias[role] || alias.therapist; +} + function goToDeeplink(link) { if (!link) return; - if (typeof link === 'string' && link.startsWith('/')) { - router.push(link); + const resolved = resolveDeeplink(link); + if (typeof resolved === 'string' && resolved.startsWith('/')) { + router.push(resolved); } else { - window.location.href = link; + window.location.href = resolved; } } diff --git a/supabase/functions/conversation-sla-check/index.ts b/supabase/functions/conversation-sla-check/index.ts index 3c96381..803eedd 100644 --- a/supabase/functions/conversation-sla-check/index.ts +++ b/supabase/functions/conversation-sla-check/index.ts @@ -279,7 +279,7 @@ async function notifyBreach(supa: SupabaseClient, params: { title, detail, severity: 'error', - deeplink: '/crm/conversas', + deeplink: '/conversas', actionLabel: 'Abrir CRM', thread_key: params.thread_key }