TicketSharedDraftConflictDialog.vue 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 dialogName = 'shared-draft-conflict'
  20. const { openSharedDraftFlyout } = useTicketSharedDraft()
  21. const close = () => {
  22. closeDialog(dialogName)
  23. }
  24. const draftUpdateMutation = new MutationHandler(
  25. useTicketSharedDraftZoomUpdateMutation(),
  26. {
  27. errorNotificationMessage: __('Draft could not be updated.'),
  28. },
  29. )
  30. const updateDraft = () => {
  31. draftUpdateMutation
  32. .send({
  33. sharedDraftId: props.sharedDraftId,
  34. input: props.sharedDraftParams,
  35. })
  36. .then(() => {
  37. close()
  38. notify({
  39. id: 'shared-draft-detail-view-updated',
  40. type: NotificationTypes.Success,
  41. message: __('Shared draft has been updated successfully.'),
  42. })
  43. })
  44. }
  45. const showDraft = () => {
  46. close()
  47. openSharedDraftFlyout('detail-view', props.sharedDraftId)
  48. }
  49. </script>
  50. <template>
  51. <CommonDialog
  52. :name="dialogName"
  53. header-title="Save Draft"
  54. content="There is an existing draft. Do you want to overwrite it?"
  55. >
  56. <template #footer>
  57. <div
  58. class="flex items-center gap-2 ltr:justify-end rtl:flex-row-reverse rtl:justify-start"
  59. >
  60. <CommonButton size="large" variant="secondary" @click="close()">
  61. {{ $t('Cancel & Go Back') }}
  62. </CommonButton>
  63. <CommonButton
  64. size="large"
  65. prefix-icon="file-text"
  66. variant="tertiary"
  67. @click="showDraft()"
  68. >
  69. {{ $t('Show Draft') }}
  70. </CommonButton>
  71. <CommonButton size="large" variant="danger" @click="updateDraft()">
  72. {{ $t('Overwrite Draft') }}
  73. </CommonButton>
  74. </div>
  75. </template>
  76. </CommonDialog>
  77. </template>