TicketCreate.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed, useTemplateRef, watch } from 'vue'
  4. import { useTicketCreateArticleType } from '#shared/entities/ticket/composables/useTicketCreateArticleType.ts'
  5. import { useTicketCreateView } from '#shared/entities/ticket/composables/useTicketCreateView.ts'
  6. import type { TicketCreateArticleType } from '#shared/entities/ticket/types.ts'
  7. import { type UserTaskbarItemEntityTicketCreate } from '#shared/graphql/types.ts'
  8. import { i18n } from '#shared/i18n.ts'
  9. import type { UserTaskbarTabEntityProps } from '../types.ts'
  10. const props =
  11. defineProps<UserTaskbarTabEntityProps<UserTaskbarItemEntityTicketCreate>>()
  12. const { ticketCreateArticleType, defaultTicketCreateArticleType } =
  13. useTicketCreateArticleType()
  14. const { isTicketCustomer } = useTicketCreateView()
  15. const ticketCreateLinkInstance = useTemplateRef('link')
  16. watch(
  17. () => ticketCreateLinkInstance.value?.isExactActive,
  18. (isExactActive) => {
  19. if (!isExactActive) return
  20. // Scroll the tab into view when it becomes active.
  21. ticketCreateLinkInstance.value?.$el?.scrollIntoView?.()
  22. },
  23. )
  24. const currentViewTitle = computed(() => {
  25. // Customer users should get a generic title prefix, since they cannot control the type of the first article.
  26. if (isTicketCustomer.value) {
  27. if (!props.context?.formValues?.title && !props.taskbarTab.entity?.title)
  28. return i18n.t('New Ticket')
  29. return i18n.t(
  30. 'New Ticket: %s',
  31. (props.context?.formValues?.title as string) ||
  32. props.taskbarTab.entity?.title,
  33. )
  34. }
  35. if (
  36. !props.context?.formValues?.articleSenderType &&
  37. !props.taskbarTab.entity?.createArticleTypeKey
  38. )
  39. return i18n.t(
  40. ticketCreateArticleType[defaultTicketCreateArticleType]?.label,
  41. )
  42. const createArticleTypeKey = (props.context?.formValues?.articleSenderType ||
  43. props.taskbarTab.entity?.createArticleTypeKey) as TicketCreateArticleType
  44. if (!props.context?.formValues?.title && !props.taskbarTab.entity?.title)
  45. return i18n.t(ticketCreateArticleType[createArticleTypeKey]?.label)
  46. return i18n.t(
  47. ticketCreateArticleType[createArticleTypeKey]?.title,
  48. (props.context?.formValues?.title as string) ||
  49. props.taskbarTab.entity?.title,
  50. )
  51. })
  52. </script>
  53. <template>
  54. <CommonLink
  55. v-if="taskbarTabLink"
  56. ref="link"
  57. v-tooltip="currentViewTitle"
  58. class="flex grow gap-2 rounded-md px-2 py-3 hover:no-underline focus-visible:rounded-md focus-visible:outline-none group-hover/tab:bg-blue-600 group-hover/tab:dark:bg-blue-900"
  59. :link="taskbarTabLink"
  60. exact-active-class="!bg-blue-800 text-white"
  61. internal
  62. >
  63. <CommonIcon
  64. class="-:text-stone-200 -:dark:text-neutral-500 shrink-0 group-focus-visible/link:text-white"
  65. name="pencil"
  66. size="small"
  67. decorative
  68. />
  69. <CommonLabel
  70. class="-:text-gray-300 -:dark:text-neutral-400 block truncate group-hover/tab:text-white group-focus-visible/link:text-white"
  71. >
  72. {{ currentViewTitle }}
  73. </CommonLabel>
  74. </CommonLink>
  75. </template>
  76. <style scoped>
  77. .router-link-active {
  78. @apply text-white;
  79. .icon,
  80. span {
  81. @apply text-white;
  82. }
  83. }
  84. </style>