TicketSharedDraftConflictDialog.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { NotificationTypes } from '#shared/components/CommonNotifications/types.ts'
  4. import { useNotifications } from '#shared/components/CommonNotifications/useNotifications.ts'
  5. import type { FormRef } from '#shared/components/Form/types.ts'
  6. import { useTicketSharedDraftZoomUpdateMutation } from '#shared/entities/ticket-shared-draft-zoom/graphql/mutations/ticketSharedDraftZoomUpdate.api.ts'
  7. import type { TicketSharedDraftZoomInput } from '#shared/graphql/types.ts'
  8. import { MutationHandler } from '#shared/server/apollo/handler/index.ts'
  9. import CommonButton from '#desktop/components/CommonButton/CommonButton.vue'
  10. import CommonDialog from '#desktop/components/CommonDialog/CommonDialog.vue'
  11. import { closeDialog } from '#desktop/components/CommonDialog/useDialog.ts'
  12. import { useTicketSharedDraft } from '#desktop/pages/ticket/composables/useTicketSharedDraft.ts'
  13. const props = defineProps<{
  14. sharedDraftId: string
  15. sharedDraftParams: TicketSharedDraftZoomInput
  16. form?: FormRef
  17. }>()
  18. const { notify } = useNotifications()
  19. const { openSharedDraftFlyout } = useTicketSharedDraft()
  20. const close = () => {
  21. closeDialog('shared-draft-conflict')
  22. }
  23. const draftUpdateMutation = new MutationHandler(
  24. useTicketSharedDraftZoomUpdateMutation(),
  25. {
  26. errorNotificationMessage: __('Draft could not be updated.'),
  27. },
  28. )
  29. const updateDraft = () => {
  30. draftUpdateMutation
  31. .send({
  32. sharedDraftId: props.sharedDraftId,
  33. input: props.sharedDraftParams,
  34. })
  35. .then(() => {
  36. close()
  37. notify({
  38. id: 'shared-draft-detail-view-updated',
  39. type: NotificationTypes.Success,
  40. message: __('Shared draft has been updated successfully.'),
  41. })
  42. })
  43. }
  44. const showDraft = () => {
  45. close()
  46. openSharedDraftFlyout('detail-view', props.sharedDraftId)
  47. }
  48. </script>
  49. <template>
  50. <CommonDialog
  51. name="shared-draft-conflict"
  52. header-title="Save Draft"
  53. content="There is an existing draft. Do you want to overwrite it?"
  54. >
  55. <template #footer>
  56. <div
  57. class="flex items-center gap-2 ltr:justify-end rtl:flex-row-reverse rtl:justify-start"
  58. >
  59. <CommonButton size="large" variant="secondary" @click="close()">
  60. {{ $t('Cancel & Go Back') }}
  61. </CommonButton>
  62. <CommonButton
  63. size="large"
  64. prefix-icon="file-text"
  65. variant="tertiary"
  66. @click="showDraft()"
  67. >
  68. {{ $t('Show Draft') }}
  69. </CommonButton>
  70. <CommonButton size="large" variant="danger" @click="updateDraft()">
  71. {{ $t('Overwrite Draft') }}
  72. </CommonButton>
  73. </div>
  74. </template>
  75. </CommonDialog>
  76. </template>