diff --git a/src/composables/useNotifications.js b/src/composables/useNotifications.js index 40028eb..da6233d 100644 --- a/src/composables/useNotifications.js +++ b/src/composables/useNotifications.js @@ -56,7 +56,8 @@ export function useNotifications() { group: 'system-alerts', data: { deeplink: payload.deeplink, - actionLabel: payload.actionLabel || defaultActionLabel(payload.deeplink) + actionLabel: payload.actionLabel || defaultActionLabel(payload.deeplink), + thread_key: payload.thread_key || null } }); } diff --git a/src/layout/AppLayout.vue b/src/layout/AppLayout.vue index 8f20cb4..bac9bc8 100644 --- a/src/layout/AppLayout.vue +++ b/src/layout/AppLayout.vue @@ -19,6 +19,9 @@ import { useLayout } from '@/layout/composables/layout'; import { computed, onMounted, onBeforeUnmount, provide, watch } from 'vue'; import { useRoute, useRouter } from 'vue-router'; +import { supabase } from '@/lib/supabase/client'; +import { useConversationDrawerStore } from '@/stores/conversationDrawerStore'; + const router = useRouter(); // Aliases "semânticos" → resolvidos pra rota real com base no role atual. @@ -47,6 +50,32 @@ function goToDeeplink(link) { } } +// Abre o drawer global de conversa a partir do thread_key (do payload do alerta). +// Busca o row da view conversation_threads e delega pro store. +async function openConversationDrawer(threadKey) { + if (!threadKey) return; + try { + const tenantId = tenantStore.activeTenantId; + const { data, error } = await supabase + .from('conversation_threads') + .select('*') + .eq('tenant_id', tenantId) + .eq('thread_key', threadKey) + .maybeSingle(); + if (error) throw error; + if (!data) { + // Thread sumiu (foi arquivada ou paciente deletado) — fallback pra lista + goToDeeplink('/conversas'); + return; + } + const drawerStore = useConversationDrawerStore(); + await drawerStore.openForThread(data); + } catch (e) { + console.warn('[AppLayout] openConversationDrawer falhou:', e?.message); + goToDeeplink('/conversas'); + } +} + import AppFooter from './AppFooter.vue'; import AppSidebar from './AppSidebar.vue'; import AppTopbar from './AppTopbar.vue'; @@ -216,16 +245,28 @@ onBeforeUnmount(() => {
{{ slotProps.message.detail }}
-