CommonConfirmation.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <!-- Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed } from 'vue'
  4. import CommonSectionPopup from '@mobile/components/CommonSectionPopup/CommonSectionPopup.vue'
  5. import useConfirmation from './composable'
  6. // TODO: Add a story for this component.
  7. const { confirmationDialog } = useConfirmation()
  8. const localState = computed({
  9. get: () => !!confirmationDialog.value,
  10. set: (value) => {
  11. if (!value) confirmationDialog.value = undefined
  12. },
  13. })
  14. const item = computed(() => {
  15. return {
  16. label: confirmationDialog.value?.buttonTitle || __('OK'),
  17. class: confirmationDialog.value?.buttonTextColorClass || 'text-white',
  18. onAction: confirmationDialog.value?.confirmCallback,
  19. }
  20. })
  21. const callCancelCallback = (isCancel: boolean) => {
  22. if (!isCancel) return
  23. if (confirmationDialog.value?.cancelCallback) {
  24. confirmationDialog.value.cancelCallback()
  25. }
  26. }
  27. </script>
  28. <template>
  29. <CommonSectionPopup
  30. v-model:state="localState"
  31. :items="[item]"
  32. :label="__('Confirm dialog')"
  33. @close="callCancelCallback"
  34. >
  35. <template #header>
  36. <div
  37. class="flex min-h-[3.5rem] items-center justify-center border-b border-gray-300 p-3 text-center text-white"
  38. >
  39. {{
  40. $t(
  41. confirmationDialog?.heading,
  42. ...(confirmationDialog?.headingPlaceholder || []),
  43. )
  44. }}
  45. </div>
  46. </template>
  47. </CommonSectionPopup>
  48. </template>