useTicketCreateTitle.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { computed, type ComputedRef } from 'vue'
  3. import { useTicketCreateArticleType } from '#shared/entities/ticket/composables/useTicketCreateArticleType.ts'
  4. import { useTicketCreateView } from '#shared/entities/ticket/composables/useTicketCreateView.ts'
  5. import type { TicketCreateArticleType } from '#shared/entities/ticket/types.ts'
  6. import { i18n } from '#shared/i18n.ts'
  7. export const useTicketCreateTitle = (
  8. currentTitle: ComputedRef<string>,
  9. currentArticleType: ComputedRef<string>,
  10. ) => {
  11. const { isTicketCustomer } = useTicketCreateView()
  12. const { ticketCreateArticleType, defaultTicketCreateArticleType } =
  13. useTicketCreateArticleType()
  14. const currentViewTitle = computed(() => {
  15. // Customer users should get a generic title prefix, since they cannot control the type of the first article.
  16. if (isTicketCustomer.value) {
  17. if (!currentTitle.value) return i18n.t('New Ticket')
  18. return i18n.t('New Ticket: %s', currentTitle.value)
  19. }
  20. if (!currentArticleType.value) {
  21. return i18n.t(
  22. ticketCreateArticleType[defaultTicketCreateArticleType]?.label,
  23. )
  24. }
  25. const createArticleTypeKey =
  26. currentArticleType.value as TicketCreateArticleType
  27. if (!currentTitle.value)
  28. return i18n.t(ticketCreateArticleType[createArticleTypeKey]?.label)
  29. return i18n.t(
  30. ticketCreateArticleType[createArticleTypeKey]?.title,
  31. currentTitle.value,
  32. )
  33. })
  34. return {
  35. currentViewTitle,
  36. }
  37. }