useDialogObjectForm.ts 934 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { FormFieldValue } from '#shared/components/Form/types.ts'
  3. import type { EnumObjectManagerObjects } from '#shared/graphql/types.ts'
  4. import { useDialog } from '#mobile/composables/useDialog.ts'
  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. }