useFieldOrganizationInitialOptionBuilder.ts 967 B

12345678910111213141516171819202122232425
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { SelectValue } from '#shared/components/CommonSelect/types.ts'
  3. import type { AutocompleteOrganizationProps } from '#shared/components/Form/fields/FieldOrganization/types.ts'
  4. import { getAutoCompleteOption } from '#shared/entities/organization/utils/getAutoCompleteOption.ts'
  5. import type { Organization } from '#shared/graphql/types.ts'
  6. import type { ObjectLike } from '#shared/types/utils.ts'
  7. export const useFormFieldOrganizationInitialOptionBuilder = () => {
  8. return (
  9. initialEntityObject: ObjectLike,
  10. value: SelectValue,
  11. context: AutocompleteOrganizationProps['context'],
  12. ) => {
  13. if (!context.belongsToObjectField || !initialEntityObject) return null
  14. const belongsToObject = initialEntityObject[
  15. context.belongsToObjectField
  16. ] as Organization
  17. if (!belongsToObject) return null
  18. return getAutoCompleteOption(belongsToObject)
  19. }
  20. }