TicketSidebarCustomer.vue 2.8 KB

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