Files
libredesk/frontend/src/stores/inbox.js
Abhinav Raut 35ad00ec51 Add loading spinner to ConversationPlaceholder
Add missing i18n translation
2025-09-01 02:41:47 +05:30

32 lines
923 B
JavaScript

import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import { handleHTTPError } from '@/utils/http'
import { useEmitter } from '@/composables/useEmitter'
import { EMITTER_EVENTS } from '@/constants/emitterEvents'
import api from '@/api'
export const useInboxStore = defineStore('inbox', () => {
const inboxes = ref([])
const emitter = useEmitter()
const options = computed(() => inboxes.value.map(inb => ({
label: inb.name,
value: String(inb.id)
})))
const fetchInboxes = async (force = false) => {
if (!force && inboxes.value.length) return
try {
const response = await api.getInboxes()
inboxes.value = response?.data?.data || []
} catch (error) {
emitter.emit(EMITTER_EVENTS.SHOW_TOAST, {
variant: 'destructive',
description: handleHTTPError(error).message
})
}
}
return {
inboxes,
options,
fetchInboxes,
}
})