ArticleWhatsappMediaBadge.vue 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed, ref, toRef } from 'vue'
  4. import { useTicketArticleRetryMediaDownload } from '#shared/entities/ticket-article/composables/useTicketArticleRetryMediaDownload.ts'
  5. import CommonSectionPopup from '#mobile/components/CommonSectionPopup/CommonSectionPopup.vue'
  6. export interface Props {
  7. articleId: string
  8. mediaError: boolean
  9. }
  10. const props = defineProps<Props>()
  11. const showPopup = ref(false)
  12. const { loading, tryAgain } = useTicketArticleRetryMediaDownload(
  13. toRef(props, 'articleId'),
  14. )
  15. const popupItems = computed(() =>
  16. props.mediaError && !loading.value
  17. ? [
  18. {
  19. type: 'button' as const,
  20. label: __('Try again'),
  21. onAction: async () => {
  22. try {
  23. await tryAgain()
  24. showPopup.value = false
  25. } catch {
  26. // no-op
  27. }
  28. },
  29. noHideOnSelect: true,
  30. },
  31. ]
  32. : [],
  33. )
  34. </script>
  35. <template>
  36. <button
  37. v-if="props.mediaError"
  38. type="button"
  39. class="bg-yellow inline-flex h-7 grow items-center gap-1 rounded-lg px-2 py-1 text-xs font-bold text-black"
  40. @click.prevent="showPopup = !showPopup"
  41. @keydown.space.prevent="showPopup = !showPopup"
  42. >
  43. <CommonIcon name="update" decorative size="xs" />
  44. {{ $t('Media Download Error') }}
  45. </button>
  46. <CommonSectionPopup v-model:state="showPopup" :messages="popupItems">
  47. <template #header>
  48. <div
  49. class="flex flex-col items-center gap-2 border-b border-b-white/10 p-4"
  50. >
  51. <div
  52. v-if="props.mediaError"
  53. class="text-yellow flex w-full items-center justify-center gap-1"
  54. >
  55. <CommonIcon name="update" size="tiny" />
  56. {{ $t('Media Download Error') }}
  57. </div>
  58. <div
  59. v-if="loading"
  60. class="flex w-full items-center justify-center gap-1"
  61. >
  62. <CommonIcon name="loading" animation="spin" />
  63. </div>
  64. </div>
  65. </template>
  66. </CommonSectionPopup>
  67. </template>