CommonConfirmation.vue 2.1 KB

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