useTicketDataHandler.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { computed, type Ref } from 'vue'
  3. import { useTicketQuery } from '#shared/entities/ticket/graphql/queries/ticket.api.ts'
  4. import { useErrorHandler } from '#shared/errors/useErrorHandler.ts'
  5. import { QueryHandler } from '#shared/server/apollo/handler/index.ts'
  6. export const useTicketDataHandler = (ticketId: Ref<string>) => {
  7. const { createQueryErrorHandler } = useErrorHandler()
  8. const ticketQuery = new QueryHandler(
  9. useTicketQuery(
  10. () => ({
  11. ticketId: ticketId.value,
  12. }),
  13. { fetchPolicy: 'cache-first' },
  14. ),
  15. {
  16. errorCallback: createQueryErrorHandler({
  17. notFound: __(
  18. 'Ticket with specified ID was not found. Try checking the URL for errors.',
  19. ),
  20. forbidden: __('You have insufficient rights to view this ticket.'),
  21. }),
  22. },
  23. )
  24. const ticketResult = ticketQuery.result()
  25. const isLoadingTicket = computed(() => {
  26. return ticketQuery.loading().value && !ticketResult.value
  27. })
  28. const isRefetchingTicket = computed(
  29. () => ticketQuery.loading().value && !!ticketResult.value,
  30. )
  31. return { ticketQuery, ticketResult, isRefetchingTicket, isLoadingTicket }
  32. }