FieldCustomerWrapper.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <!-- Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { markRaw, defineAsyncComponent } from 'vue'
  4. import type { ObjectLike } from '@shared/types/utils'
  5. import { AutocompleteSearchUserDocument } from '@shared/components/Form/fields/FieldCustomer/graphql/queries/autocompleteSearch/user.api'
  6. import { useUserCreate } from '@mobile/entities/user/composables/useUserCreate'
  7. import FieldCustomerOptionIcon from './FieldCustomerOptionIcon.vue'
  8. import type { AutoCompleteProps } from '../FieldAutoComplete/types'
  9. import type { FormFieldContext } from '../../types/field'
  10. import type { SelectValue } from '../FieldSelect'
  11. import type { AutoCompleteCustomerOption } from './types'
  12. const FieldAutoCompleteInput = defineAsyncComponent(
  13. () =>
  14. import(
  15. '@shared/components/Form/fields/FieldAutoComplete/FieldAutoCompleteInput.vue'
  16. ),
  17. )
  18. interface Props {
  19. context: FormFieldContext<
  20. AutoCompleteProps & {
  21. options?: AutoCompleteCustomerOption[]
  22. }
  23. >
  24. }
  25. const props = defineProps<Props>()
  26. const { openCreateUserDialog } = useUserCreate()
  27. Object.assign(props.context, {
  28. optionIconComponent: markRaw(FieldCustomerOptionIcon),
  29. initialOptionBuilder: (
  30. initialEntityObject: ObjectLike,
  31. value: SelectValue,
  32. context: Props['context'],
  33. ) => {
  34. if (!context.belongsToObjectField || !initialEntityObject) return null
  35. const belongsToObject = initialEntityObject[context.belongsToObjectField]
  36. if (!belongsToObject) return null
  37. return {
  38. value,
  39. label: belongsToObject.fullname,
  40. // disabled: !object.active, // TODO: we can not use disabled for the active/inactive flag, because it will be no longer possible to select the option
  41. user: belongsToObject,
  42. }
  43. },
  44. actionIcon: 'mobile-new-customer',
  45. gqlQuery: AutocompleteSearchUserDocument,
  46. onActionClick: openCreateUserDialog,
  47. })
  48. </script>
  49. <template>
  50. <FieldAutoCompleteInput :context="context" v-bind="$attrs" />
  51. </template>