ArticleMetaAddress.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
  2. <script setup lang="ts">
  3. import { computed } from 'vue'
  4. import type { TicketArticle } from '#shared/entities/ticket/types.ts'
  5. interface Props {
  6. context: {
  7. article: TicketArticle
  8. }
  9. type?: 'from' | 'to' | 'cc'
  10. }
  11. const props = withDefaults(defineProps<Props>(), {
  12. type: 'from',
  13. })
  14. const getEmailAddress = (article: TicketArticle) => {
  15. if (props.type === 'from') return article.from?.parsed?.at(0)?.emailAddress
  16. if (props.type === 'cc') return article.cc?.parsed?.at(0)?.emailAddress
  17. return article.to?.parsed?.at(0)?.emailAddress
  18. }
  19. const getName = (article: TicketArticle) => {
  20. if (props.type === 'from')
  21. return article.from?.parsed?.at(0)?.name || article.from?.raw
  22. if (props.type === 'cc')
  23. return article.cc?.parsed?.at(0)?.name || article.cc?.raw
  24. return article.to?.parsed?.at(0)?.name || article.to?.raw
  25. }
  26. const name = computed(() => getName(props.context.article))
  27. const email = computed(() => getEmailAddress(props.context.article))
  28. </script>
  29. <template>
  30. <div class="flex gap-2">
  31. <CommonLabel v-if="name" class="text-black dark:text-white">{{
  32. $t(name)
  33. }}</CommonLabel>
  34. <CommonLabel v-if="email && email !== '-' && email !== name">{{
  35. `<${email}>`
  36. }}</CommonLabel>
  37. </div>
  38. </template>