From b516da39f309121144d0acec0a49d84f931b4bc1 Mon Sep 17 00:00:00 2001 From: josedario87 Date: Tue, 2 Dec 2025 19:50:16 -0600 Subject: [PATCH] Fix: selectedInstance object handling in messages page USelectMenu devuelve un objeto {label, value}, no solo el value string. Actualizado el tipo y todas las referencias para usar instance.value --- app/pages/messages/index.vue | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/pages/messages/index.vue b/app/pages/messages/index.vue index 06dcafb..8a277ed 100644 --- a/app/pages/messages/index.vue +++ b/app/pages/messages/index.vue @@ -95,7 +95,7 @@ definePageMeta({ const { instances, fetchInstances } = useInstances() -const selectedInstance = ref(null) +const selectedInstance = ref<{ label: string; value: string } | null>(null) const searchQuery = ref('') const selectedChat = ref(null) const chats = ref([]) @@ -113,20 +113,20 @@ const instanceOptions = computed(() => // Auto-select first connected instance watch(instanceOptions, (opts) => { if (opts.length > 0 && !selectedInstance.value) { - selectedInstance.value = opts[0].value + selectedInstance.value = opts[0] } }, { immediate: true }) // Load chats when instance changes -watch(selectedInstance, async (instanceId) => { - if (!instanceId) { +watch(selectedInstance, async (instance) => { + if (!instance?.value) { chats.value = [] return } loadingChats.value = true try { - chats.value = await $fetch(`/api/messages/${instanceId}/chats`) + chats.value = await $fetch(`/api/messages/${instance.value}/chats`) } catch (e) { console.error('Error loading chats:', e) chats.value = [] @@ -137,14 +137,14 @@ watch(selectedInstance, async (instanceId) => { // Load messages when chat changes watch(selectedChat, async (chat) => { - if (!chat || !selectedInstance.value) { + if (!chat || !selectedInstance.value?.value) { messages.value = [] return } loadingMessages.value = true try { - messages.value = await $fetch(`/api/messages/${selectedInstance.value}/${chat.id}`) + messages.value = await $fetch(`/api/messages/${selectedInstance.value.value}/${chat.id}`) } catch (e) { console.error('Error loading messages:', e) messages.value = [] @@ -161,16 +161,16 @@ const filteredChats = computed(() => { }) const handleSendMessage = async (content: string) => { - if (!selectedInstance.value || !selectedChat.value) return + if (!selectedInstance.value?.value || !selectedChat.value) return try { - await $fetch(`/api/messages/${selectedInstance.value}/${selectedChat.value.id}/send`, { + await $fetch(`/api/messages/${selectedInstance.value.value}/${selectedChat.value.id}/send`, { method: 'POST', body: { content } }) // Reload messages - messages.value = await $fetch(`/api/messages/${selectedInstance.value}/${selectedChat.value.id}`) + messages.value = await $fetch(`/api/messages/${selectedInstance.value.value}/${selectedChat.value.id}`) } catch (e) { console.error('Error sending message:', e) }