ArticleWhatsappMediaBadge.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed, ref } from 'vue'
  4. import {
  5. NotificationTypes,
  6. useNotifications,
  7. } from '#shared/components/CommonNotifications/index.ts'
  8. import { useTicketArticleRetryMediaDownloadMutation } from '#shared/entities/ticket-article/graphql/mutations/ticketArticleRetryMediaDownload.api.ts'
  9. import { MutationHandler } from '#shared/server/apollo/handler/index.ts'
  10. import CommonSectionPopup from '#mobile/components/CommonSectionPopup/CommonSectionPopup.vue'
  11. export interface Props {
  12. articleId: string
  13. mediaError: boolean
  14. }
  15. const props = defineProps<Props>()
  16. const showPopup = ref(false)
  17. const retryMutation = new MutationHandler(
  18. useTicketArticleRetryMediaDownloadMutation(() => ({
  19. variables: {
  20. articleId: props.articleId,
  21. },
  22. })),
  23. )
  24. const { notify } = useNotifications()
  25. const loading = ref(false)
  26. const tryAgain = async () => {
  27. loading.value = true
  28. const result = await retryMutation.send()
  29. if (result?.ticketArticleRetryMediaDownload?.success) {
  30. notify({
  31. id: 'media-download-success',
  32. type: NotificationTypes.Success,
  33. message: __('Media download was successful.'),
  34. })
  35. showPopup.value = false
  36. } else {
  37. notify({
  38. id: 'media-download-failed',
  39. type: NotificationTypes.Error,
  40. message: __('Media download failed. Please try again later.'),
  41. })
  42. }
  43. loading.value = false
  44. }
  45. const popupItems = computed(() =>
  46. props.mediaError && !loading.value
  47. ? [
  48. {
  49. type: 'button' as const,
  50. label: __('Try again'),
  51. onAction: tryAgain,
  52. noHideOnSelect: true,
  53. },
  54. ]
  55. : [],
  56. )
  57. </script>
  58. <template>
  59. <button
  60. v-if="props.mediaError"
  61. type="button"
  62. class="bg-yellow inline-flex h-7 grow items-center gap-1 rounded-lg px-2 py-1 text-xs font-bold text-black"
  63. @click.prevent="showPopup = !showPopup"
  64. @keydown.space.prevent="showPopup = !showPopup"
  65. >
  66. <CommonIcon name="update" decorative size="xs" />
  67. {{ $t('Media Download Error') }}
  68. </button>
  69. <CommonSectionPopup v-model:state="showPopup" :messages="popupItems">
  70. <template #header>
  71. <div
  72. class="flex flex-col items-center gap-2 border-b border-b-white/10 p-4"
  73. >
  74. <div
  75. v-if="props.mediaError"
  76. class="text-yellow flex w-full items-center justify-center gap-1"
  77. >
  78. <CommonIcon name="update" size="tiny" />
  79. {{ $t('Media Download Error') }}
  80. </div>
  81. <div
  82. v-if="loading"
  83. class="flex w-full items-center justify-center gap-1"
  84. >
  85. <CommonIcon name="loading" animation="spin" />
  86. </div>
  87. </div>
  88. </template>
  89. </CommonSectionPopup>
  90. </template>