TicketSidebarOrganization.vue 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { watch, computed } from 'vue'
  4. import { useOrganizationDetail } from '#shared/entities/organization/composables/useOrganizationDetail.ts'
  5. import { useUserQuery } from '#shared/entities/user/graphql/queries/user.api.ts'
  6. import QueryHandler from '#shared/server/apollo/handler/QueryHandler.ts'
  7. import type {
  8. TicketSidebarProps,
  9. TicketSidebarEmits,
  10. } from '#desktop/pages/ticket/types/sidebar.ts'
  11. import TicketSidebarWrapper from '../TicketSidebarWrapper.vue'
  12. import TicketSidebarOrganizationContent from './TicketSidebarOrganizationContent.vue'
  13. const props = defineProps<TicketSidebarProps>()
  14. const emit = defineEmits<TicketSidebarEmits>()
  15. const customerId = computed(() => Number(props.context.formValues.customer_id))
  16. // Query is using cache first so it should normally not trigger any additional request, because the customer sidebar
  17. // is alreaddy doing the same query.
  18. const userQuery = new QueryHandler(
  19. useUserQuery(
  20. () => ({
  21. userInternalId: customerId.value,
  22. secondaryOrganizationsCount: 3,
  23. }),
  24. () => ({ enabled: Boolean(customerId.value), fetchPolicy: 'cache-first' }),
  25. ),
  26. )
  27. const userResult = userQuery.result()
  28. const customer = computed(() => userResult.value?.user)
  29. watch(customer, (newValue) => {
  30. if (!newValue?.organization) {
  31. emit('hide')
  32. return
  33. }
  34. emit('show')
  35. })
  36. const organizationInternalId = computed(() => {
  37. if (props.context.formValues?.organization_id)
  38. return Number(props.context.formValues?.organization_id)
  39. return customer.value?.organization?.internalId
  40. })
  41. const { organization, organizationMembers, objectAttributes, loadAllMembers } =
  42. useOrganizationDetail(organizationInternalId)
  43. </script>
  44. <template>
  45. <TicketSidebarWrapper
  46. :key="sidebar"
  47. :sidebar="sidebar"
  48. :sidebar-plugin="sidebarPlugin"
  49. :selected="selected"
  50. >
  51. <TicketSidebarOrganizationContent
  52. v-if="organization"
  53. :context="context"
  54. :sidebar-plugin="sidebarPlugin"
  55. :organization="organization"
  56. :organization-members="organizationMembers"
  57. :object-attributes="objectAttributes"
  58. @load-more-members="loadAllMembers"
  59. />
  60. </TicketSidebarWrapper>
  61. </template>