useOrganizationEdit.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { reactive } from 'vue'
  3. import type { FormSchemaField } from '#shared/components/Form/types.ts'
  4. import { defineFormSchema } from '#shared/form/defineFormSchema.ts'
  5. import type { OrganizationQuery } from '#shared/graphql/types.ts'
  6. import {
  7. EnumFormUpdaterId,
  8. EnumObjectManagerObjects,
  9. } from '#shared/graphql/types.ts'
  10. import type { ConfidentTake } from '#shared/types/utils.ts'
  11. import { useDialogObjectForm } from '#mobile/components/CommonDialogObjectForm/useDialogObjectForm.ts'
  12. import { useOrganizationUpdateMutation } from '../graphql/mutations/update.api.ts'
  13. export const useOrganizationEdit = () => {
  14. const dialog = useDialogObjectForm(
  15. 'organization-edit',
  16. EnumObjectManagerObjects.Organization,
  17. )
  18. const schema = defineFormSchema(
  19. [
  20. {
  21. name: 'name',
  22. required: true,
  23. screen: 'edit',
  24. object: EnumObjectManagerObjects.Organization,
  25. },
  26. {
  27. screen: 'edit',
  28. object: EnumObjectManagerObjects.Organization,
  29. },
  30. {
  31. name: 'active',
  32. required: true,
  33. screen: 'edit',
  34. object: EnumObjectManagerObjects.Organization,
  35. },
  36. ],
  37. { showDirtyMark: true },
  38. )
  39. const openEditOrganizationDialog = async (
  40. organization: ConfidentTake<OrganizationQuery, 'organization'>,
  41. ) => {
  42. const formChangeFields = reactive<Record<string, Partial<FormSchemaField>>>(
  43. {
  44. domain: {
  45. required: !!organization.domainAssignment,
  46. },
  47. note: {
  48. props: {
  49. meta: {
  50. mentionText: {
  51. disabled: true,
  52. },
  53. mentionKnowledgeBase: {
  54. disabled: true,
  55. },
  56. mentionUser: {
  57. disabled: true,
  58. },
  59. },
  60. },
  61. },
  62. },
  63. )
  64. dialog.openDialog({
  65. object: organization,
  66. schema,
  67. mutation: useOrganizationUpdateMutation,
  68. formChangeFields,
  69. onChangedField: (fieldName, newValue) => {
  70. if (fieldName === 'domain_assignment') {
  71. // TODO: Can be changed when we have the new toggle field (currently the value can also be a string).
  72. formChangeFields.domain.required =
  73. (typeof newValue === 'boolean' && newValue) || newValue === 'true'
  74. }
  75. },
  76. formUpdaterId: EnumFormUpdaterId.FormUpdaterUpdaterOrganizationEdit,
  77. errorNotificationMessage: __('Organization could not be updated.'),
  78. })
  79. }
  80. return { openEditOrganizationDialog }
  81. }