CommonConfirmationDialog.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed } from 'vue'
  4. import { useConfirmation } from '#shared/composables/useConfirmation.ts'
  5. import { i18n } from '#shared/i18n.ts'
  6. import CommonDialog from '#desktop/components/CommonDialog/CommonDialog.vue'
  7. import type { ConfirmationVariantOptions } from './types.ts'
  8. const { confirmationOptions } = useConfirmation()
  9. const handleConfirmation = (isCancel: boolean) => {
  10. if (isCancel) {
  11. confirmationOptions.value?.cancelCallback()
  12. } else {
  13. confirmationOptions.value?.confirmCallback()
  14. }
  15. confirmationOptions.value = undefined
  16. }
  17. const confirmationVariant = computed<ConfirmationVariantOptions>(() => {
  18. switch (confirmationOptions.value?.confirmationVariant) {
  19. case 'delete':
  20. return {
  21. headerTitle: __('Delete Object'),
  22. headerIcon: 'trash3',
  23. content: __('Are you sure you want to delete this object?'),
  24. footerActionOptions: {
  25. actionLabel:
  26. confirmationOptions.value?.buttonLabel || __('Delete Object'),
  27. actionButton: {
  28. variant: 'danger',
  29. },
  30. },
  31. }
  32. case 'unsaved':
  33. return {
  34. headerTitle: __('Unsaved Changes'),
  35. content: __(
  36. 'Are you sure? You have unsaved changes that will get lost.',
  37. ),
  38. footerActionOptions: {
  39. actionLabel: __('Discard Changes'),
  40. actionButton: {
  41. variant: 'danger',
  42. },
  43. },
  44. }
  45. default:
  46. return {
  47. headerTitle: __('Confirmation'),
  48. content: __('Do you want to continue?'),
  49. footerActionOptions: {
  50. actionLabel: confirmationOptions.value?.buttonLabel || __('Yes'),
  51. actionButton: {
  52. variant: confirmationOptions.value?.buttonVariant || 'primary',
  53. },
  54. },
  55. }
  56. }
  57. })
  58. const headerTitle = computed(() => {
  59. if (confirmationOptions.value?.headerTitle) {
  60. return i18n.t(
  61. confirmationOptions.value?.headerTitle,
  62. ...(confirmationOptions.value?.headerTitlePlaceholder || []),
  63. )
  64. }
  65. return confirmationVariant.value.headerTitle
  66. })
  67. </script>
  68. <template>
  69. <CommonDialog
  70. name="confirmation"
  71. :header-title="headerTitle"
  72. :header-icon="
  73. confirmationOptions?.headerIcon || confirmationVariant.headerIcon
  74. "
  75. :content="confirmationOptions?.text || confirmationVariant.content"
  76. :content-placeholder="confirmationOptions?.textPlaceholder"
  77. :footer-action-options="confirmationVariant.footerActionOptions"
  78. @close="handleConfirmation"
  79. ></CommonDialog>
  80. </template>