composable.ts 963 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. import type { Ref } from 'vue'
  3. import { ref } from 'vue'
  4. import type { ConfirmationOptions } from './types'
  5. const confirmationDialog: Ref<ConfirmationOptions | undefined> = ref()
  6. const useConfirmation = () => {
  7. const showConfirmation = (confirmationOptions: ConfirmationOptions) => {
  8. confirmationDialog.value = confirmationOptions
  9. }
  10. const waitForConfirmation = (
  11. heading: string,
  12. options: Pick<
  13. ConfirmationOptions,
  14. 'buttonTextColorClass' | 'buttonTitle'
  15. > = {},
  16. ) => {
  17. return new Promise<boolean>((resolve) => {
  18. showConfirmation({
  19. ...options,
  20. heading,
  21. confirmCallback() {
  22. resolve(true)
  23. },
  24. cancelCallback() {
  25. resolve(false)
  26. },
  27. })
  28. })
  29. }
  30. return {
  31. confirmationDialog,
  32. showConfirmation,
  33. waitForConfirmation,
  34. }
  35. }
  36. export default useConfirmation