confirmation.ts 877 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { ref } from 'vue'
  3. import type { ButtonVariant } from '#shared/components/Form/fields/FieldButton/types.ts'
  4. export interface ConfirmationOptions {
  5. heading: string
  6. headingPlaceholder?: string[]
  7. buttonTitle?: string
  8. buttonVariant?: ButtonVariant
  9. confirmCallback: () => void
  10. cancelCallback?: () => void
  11. }
  12. export const confirmationOptions = ref<ConfirmationOptions>()
  13. export const waitForConfirmation = (
  14. heading: string,
  15. options: Pick<
  16. ConfirmationOptions,
  17. 'buttonTitle' | 'buttonVariant' | 'headingPlaceholder'
  18. > = {},
  19. ) => {
  20. return new Promise<boolean>((resolve) => {
  21. confirmationOptions.value = {
  22. ...options,
  23. heading,
  24. confirmCallback() {
  25. resolve(true)
  26. },
  27. cancelCallback() {
  28. resolve(false)
  29. },
  30. }
  31. })
  32. }