useDialogObjectForm.ts 923 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. import type { FormFieldValue } from '@shared/components/Form/types'
  3. import { useDialog } from '@shared/composables/useDialog'
  4. import type { EnumObjectManagerObjects } from '@shared/graphql/types'
  5. import type { Props } from './CommonDialogObjectForm.vue'
  6. interface ObjectDescription extends Omit<Props, 'name' | 'type'> {
  7. onSuccess?(data: unknown): void
  8. onError?(): void
  9. onChangedField?(
  10. fieldName: string,
  11. newValue: FormFieldValue,
  12. oldValue: FormFieldValue,
  13. ): void
  14. }
  15. export const useDialogObjectForm = (
  16. name: string,
  17. type: EnumObjectManagerObjects,
  18. ) => {
  19. const dialog = useDialog({
  20. name,
  21. component: () => import('./CommonDialogObjectForm.vue'),
  22. })
  23. const openDialog = async (props: ObjectDescription) => {
  24. dialog.open({
  25. name,
  26. type,
  27. ...props,
  28. })
  29. }
  30. return { openDialog }
  31. }