TicketSidebarCustomer.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { watch, computed } from 'vue'
  4. import { useUserDetail } from '#shared/entities/user/composables/useUserDetail.ts'
  5. import { useApplicationStore } from '#shared/stores/application.ts'
  6. import {
  7. type TicketSidebarProps,
  8. type TicketSidebarEmits,
  9. TicketSidebarButtonBadgeType,
  10. TicketSidebarScreenType,
  11. type TicketSidebarButtonBadgeDetails,
  12. } from '#desktop/pages/ticket/types/sidebar.ts'
  13. import TicketSidebarWrapper from '../TicketSidebarWrapper.vue'
  14. import TicketSidebarCustomerContent from './TicketSidebarCustomerContent.vue'
  15. const props = defineProps<TicketSidebarProps>()
  16. const emit = defineEmits<TicketSidebarEmits>()
  17. const application = useApplicationStore()
  18. // TODO: only for now, implement correct situtation for create/detail view.
  19. const customerId = computed(() => Number(props.context.formValues.customer_id))
  20. const {
  21. user: customer,
  22. secondaryOrganizations,
  23. objectAttributes,
  24. loadAllSecondaryOrganizations,
  25. } = useUserDetail(customerId)
  26. const calculateBadgeType = (value: number) => {
  27. if (!application.config.ui_sidebar_open_ticket_indicator_colored)
  28. return TicketSidebarButtonBadgeType.Info
  29. if (props.context.screenType === TicketSidebarScreenType.TicketDetailView)
  30. value -= 1
  31. switch (value) {
  32. case 0:
  33. return TicketSidebarButtonBadgeType.Info
  34. case 1:
  35. return TicketSidebarButtonBadgeType.Warning
  36. case 2:
  37. default:
  38. return TicketSidebarButtonBadgeType.Danger
  39. }
  40. }
  41. const badge = computed<TicketSidebarButtonBadgeDetails | undefined>(() => {
  42. const label = __('Open tickets')
  43. const value = customer.value?.ticketsCount?.open
  44. if (!value) return
  45. const type = calculateBadgeType(Number(value))
  46. return { label, value, type }
  47. })
  48. // When customerId is present, show the sidebar (for unknown customers the check is
  49. // already inside the available sidebar plugin).
  50. watch(customerId, (newValue) => {
  51. if (!newValue) {
  52. emit('hide')
  53. return
  54. }
  55. emit('show')
  56. })
  57. // On initial setup we show the sidebar if customerId is present.
  58. if (customerId.value) {
  59. emit('show')
  60. }
  61. </script>
  62. <template>
  63. <TicketSidebarWrapper
  64. :key="sidebar"
  65. :sidebar="sidebar"
  66. :sidebar-plugin="sidebarPlugin"
  67. :selected="selected"
  68. :badge="badge"
  69. >
  70. <TicketSidebarCustomerContent
  71. v-if="customer"
  72. :context="context"
  73. :sidebar-plugin="sidebarPlugin"
  74. :customer="customer"
  75. :secondary-organizations="secondaryOrganizations"
  76. :object-attributes="objectAttributes"
  77. @load-more-secondary-organizations="loadAllSecondaryOrganizations"
  78. />
  79. </TicketSidebarWrapper>
  80. </template>