FieldRecipientWrapper.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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, onKeydownFilterInput } =
  32. useAddUnknownValueAction(actionLabel, filterValueValidator)
  33. Object.assign(props.context, {
  34. actions,
  35. emptyInitialLabelText:
  36. contact === 'phone'
  37. ? __('Start typing to search or enter a phone number…')
  38. : __('Start typing to search or enter an email address…'),
  39. })
  40. </script>
  41. <template>
  42. <FieldAutoCompleteInput
  43. :context="context"
  44. v-bind="$attrs"
  45. @search-interaction-update="onSearchInteractionUpdate"
  46. @keydown-filter-input="onKeydownFilterInput"
  47. />
  48. </template>