TicketSidebarOrganization.vue 2.4 KB

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