FieldRecipientWrapper.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed } from 'vue'
  4. import type { FormFieldContext } from '#shared/components/Form/types/field.ts'
  5. import FieldAutoCompleteInput from '../FieldAutoComplete/FieldAutoCompleteInput.vue'
  6. import {
  7. emailFilterValueValidator,
  8. phoneFilterValueValidator,
  9. useAddUnknownValueAction,
  10. } from '../FieldAutoComplete/useAddUnknownValueAction.ts'
  11. import type { AutoCompleteProps } from '../FieldAutoComplete/types.ts'
  12. interface Props {
  13. context: FormFieldContext<AutoCompleteProps>
  14. }
  15. const props = defineProps<Props>()
  16. const { contact } = props.context
  17. const actionLabel = computed(() =>
  18. contact === 'phone'
  19. ? __('add new phone number')
  20. : __('add new email address'),
  21. )
  22. const filterValueValidator = (filter: string) => {
  23. switch (contact) {
  24. case 'phone':
  25. return phoneFilterValueValidator(filter)
  26. case 'email':
  27. default:
  28. return emailFilterValueValidator(filter)
  29. }
  30. }
  31. const { actions, onSearchInteractionUpdate } = useAddUnknownValueAction(
  32. actionLabel,
  33. filterValueValidator,
  34. )
  35. Object.assign(props.context, {
  36. actions,
  37. emptyInitialLabelText:
  38. contact === 'phone'
  39. ? __('Start typing to search or enter an phone number…')
  40. : __('Start typing to search or enter an email address…'),
  41. })
  42. </script>
  43. <template>
  44. <FieldAutoCompleteInput
  45. :context="context"
  46. v-bind="$attrs"
  47. @search-interaction-update="onSearchInteractionUpdate"
  48. />
  49. </template>