Fix: selectedInstance object handling in messages page
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 51s
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:
@@ -95,7 +95,7 @@ definePageMeta({
|
||||
|
||||
const { instances, fetchInstances } = useInstances()
|
||||
|
||||
const selectedInstance = ref<string | null>(null)
|
||||
const selectedInstance = ref<{ label: string; value: string } | null>(null)
|
||||
const searchQuery = ref('')
|
||||
const selectedChat = ref<any>(null)
|
||||
const chats = ref<any[]>([])
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user