All files / src/components/admin AdminSupportInbox.vue

86.51% Statements 77/89
77.77% Branches 7/9
33.33% Functions 2/6
86.51% Lines 77/89

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 1081x 1x 1x 1x 1x 2x 2x 2x 2x   2x 2x 1x   1x 7x 7x 7x   7x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x       1x           1x 1x 1x   1x 1x 1x 1x     1x   1x       1x       1x 9x 9x 1x   1x 1x 1x    
<template>
  <div data-testid="admin-support-inbox">
    <div class="flex items-start justify-between mb-4 sm:mb-6">
      <h2 class="text-xl sm:text-2xl font-bold">Support Inbox</h2>
      <span
        v-if="unreadCount > 0"
        class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-semibold bg-red-100 text-red-800"
        :aria-label="`${unreadCount} unread message${unreadCount === 1 ? '' : 's'}`"
        data-testid="support-inbox-unread-badge"
      >
        {{ unreadCount }} unread
      </span>
    </div>
 
    <div
      v-if="error"
      class="bg-red-50 border border-red-200 text-red-700 px-4 py-3 rounded mb-4"
      role="alert"
    >
      {{ error }}
    </div>
 
    <SupportThreadView
      v-if="activeThread"
      :thread="activeThread"
      :sending="sending"
      @back="closeThread"
      @reply="onReply"
      @set-status="onSetStatus"
      @mark-all-read="onMarkAllRead"
    />
    <SupportInboxList
      v-else
      :threads="threads"
      :loading="loading"
      :current-status="currentStatus"
      @select="openThread"
      @filter="onFilter"
      @load-more="onLoadMore"
      @search="onSearch"
    />
  </div>
</template>
 
<script setup>
import { onMounted, onBeforeUnmount } from 'vue';
import { useSupportInbox } from '@/composables/useSupportInbox';
import SupportInboxList from './SupportInboxList.vue';
import SupportThreadView from './SupportThreadView.vue';
 
const {
  threads,
  activeThread,
  unreadCount,
  loading,
  sending,
  error,
  currentStatus,
  loadThreads,
  openThread,
  closeThread,
  sendReply,
  setStatus,
  markAllRead,
  startPolling,
  stopPolling,
} = useSupportInbox();
 
const onFilter = status => {
  loadThreads({ status });
};
 
const onLoadMore = () => {
  if (threads.value.nextCursor) {
    loadThreads({ cursor: threads.value.nextCursor });
  }
};
 
const onSearch = mtN => {
  openThread(mtN);
};
 
const onReply = async body => {
  try {
    await sendReply(body);
  } catch (_e) {
    // Error already set on composable; nothing to do here.
  }
};
 
const onSetStatus = status => {
  setStatus(status);
};
 
const onMarkAllRead = () => {
  markAllRead();
};
 
onMounted(() => {
  loadThreads();
  startPolling();
});
 
onBeforeUnmount(() => {
  stopPolling();
});
</script>