CommonConfirmation.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. @close="callCancelCallback"
  43. >
  44. <template #header>
  45. <div
  46. class="flex min-h-[3.5rem] items-center justify-center border-b border-gray-300 p-3 text-center text-white"
  47. >
  48. {{
  49. $t(
  50. confirmationOptions?.text,
  51. ...(confirmationOptions?.textPlaceholder || []),
  52. )
  53. }}
  54. </div>
  55. </template>
  56. </CommonSectionPopup>
  57. </template>