Fix: selectedInstance object handling in messages page
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 51s

USelectMenu devuelve un objeto {label, value}, no solo el value string.
Actualizado el tipo y todas las referencias para usar instance.value
This commit is contained in:
2025-12-02 19:50:16 -06:00
parent 03c1bc8e4e
commit b516da39f3

View File

@@ -95,7 +95,7 @@ definePageMeta({
const { instances, fetchInstances } = useInstances() const { instances, fetchInstances } = useInstances()
const selectedInstance = ref<string | null>(null) const selectedInstance = ref<{ label: string; value: string } | null>(null)
const searchQuery = ref('') const searchQuery = ref('')
const selectedChat = ref<any>(null) const selectedChat = ref<any>(null)
const chats = ref<any[]>([]) const chats = ref<any[]>([])
@@ -113,20 +113,20 @@ const instanceOptions = computed(() =>
// Auto-select first connected instance // Auto-select first connected instance
watch(instanceOptions, (opts) => { watch(instanceOptions, (opts) => {
if (opts.length > 0 && !selectedInstance.value) { if (opts.length > 0 && !selectedInstance.value) {
selectedInstance.value = opts[0].value selectedInstance.value = opts[0]
} }
}, { immediate: true }) }, { immediate: true })
// Load chats when instance changes // Load chats when instance changes
watch(selectedInstance, async (instanceId) => { watch(selectedInstance, async (instance) => {
if (!instanceId) { if (!instance?.value) {
chats.value = [] chats.value = []
return return
} }
loadingChats.value = true loadingChats.value = true
try { try {
chats.value = await $fetch(`/api/messages/${instanceId}/chats`) chats.value = await $fetch(`/api/messages/${instance.value}/chats`)
} catch (e) { } catch (e) {
console.error('Error loading chats:', e) console.error('Error loading chats:', e)
chats.value = [] chats.value = []
@@ -137,14 +137,14 @@ watch(selectedInstance, async (instanceId) => {
// Load messages when chat changes // Load messages when chat changes
watch(selectedChat, async (chat) => { watch(selectedChat, async (chat) => {
if (!chat || !selectedInstance.value) { if (!chat || !selectedInstance.value?.value) {
messages.value = [] messages.value = []
return return
} }
loadingMessages.value = true loadingMessages.value = true
try { try {
messages.value = await $fetch(`/api/messages/${selectedInstance.value}/${chat.id}`) messages.value = await $fetch(`/api/messages/${selectedInstance.value.value}/${chat.id}`)
} catch (e) { } catch (e) {
console.error('Error loading messages:', e) console.error('Error loading messages:', e)
messages.value = [] messages.value = []
@@ -161,16 +161,16 @@ const filteredChats = computed(() => {
}) })
const handleSendMessage = async (content: string) => { const handleSendMessage = async (content: string) => {
if (!selectedInstance.value || !selectedChat.value) return if (!selectedInstance.value?.value || !selectedChat.value) return
try { try {
await $fetch(`/api/messages/${selectedInstance.value}/${selectedChat.value.id}/send`, { await $fetch(`/api/messages/${selectedInstance.value.value}/${selectedChat.value.id}/send`, {
method: 'POST', method: 'POST',
body: { content } body: { content }
}) })
// Reload messages // 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) { } catch (e) {
console.error('Error sending message:', e) console.error('Error sending message:', e)
} }