mirror of
				https://github.com/abhinavxd/libredesk.git
				synced 2025-11-04 05:53:30 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			32 lines
		
	
	
		
			923 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			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,
 | 
						|
  }
 | 
						|
}) |