CommonConfirmation.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 CommonSectionPopup from '../CommonSectionPopup/CommonSectionPopup.vue'
  7. import type { PopupItemDescriptor } from '../CommonSectionPopup/types.ts'
  8. const { confirmationOptions, showConfirmation } = useConfirmation()
  9. const localState = computed({
  10. get: () => showConfirmation.value,
  11. set: (value) => {
  12. if (!value) confirmationOptions.value = undefined
  13. },
  14. })
  15. const item = computed(() => {
  16. return {
  17. type: 'button' as const,
  18. label: confirmationOptions.value?.buttonLabel || __('OK'),
  19. buttonVariant: confirmationOptions.value
  20. ?.buttonVariant as PopupItemDescriptor['buttonVariant'],
  21. onAction: confirmationOptions.value?.confirmCallback,
  22. }
  23. })
  24. const callCancelCallback = (isCancel: boolean) => {
  25. if (!isCancel) return
  26. if (confirmationOptions.value?.cancelCallback) {
  27. confirmationOptions.value.cancelCallback()
  28. }
  29. }
  30. const heading = computed(() => {
  31. return i18n.t(
  32. confirmationOptions.value?.headerTitle || __('Confirm dialog'),
  33. ...(confirmationOptions.value?.headerTitlePlaceholder || []),
  34. )
  35. })
  36. </script>
  37. <template>
  38. <CommonSectionPopup
  39. v-model:state="localState"
  40. :messages="[item]"
  41. :heading="heading"
  42. :cancel-label="confirmationOptions?.cancelLabel"
  43. @close="callCancelCallback"
  44. >
  45. <template #header>
  46. <div
  47. class="flex min-h-[3.5rem] items-center justify-center border-b border-gray-300 p-3 text-center text-white"
  48. >
  49. {{
  50. $t(
  51. confirmationOptions?.text,
  52. ...(confirmationOptions?.textPlaceholder || []),
  53. )
  54. }}
  55. </div>
  56. </template>
  57. </CommonSectionPopup>
  58. </template>