All files / src/components AdminAppealsPanel.vue

97.43% Statements 38/39
87.87% Branches 29/33
90% Functions 9/10
97.14% Lines 34/35

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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174  14x 2x   2x 28x         3x                               2x                       8x           2x 2x                 2x             2x       2x   2x 2x               2x 2x           1x                                 2x                             1x                                             9x 9x 9x 9x   9x     9x 11x 9x     3x 2x 2x         1x 1x 1x     9x                    
<template>
  <div class="admin-appeals-panel">
    <p class="text-muted">{{ t('appeal.admin.description') }}</p>
 
    <ul class="nav nav-pills mb-3">
      <li v-for="option in VIEWS" :key="option" class="nav-item">
        <button
          type="button"
          class="nav-link py-1"
          :class="[{ active: view === option }, `appeals-view-${option}`]"
          @click="switchView(option)"
        >
          {{ t(`report.admin.views.${option}`) }}
        </button>
      </li>
    </ul>
 
    <ErrorAlert v-if="list.error" :title="t('common.error')" :message="list.error" />
    <LoadingSpinner v-if="list.loading" />
 
    <template v-else-if="!list.error">
      <p v-if="list.items.length === 0" class="text-muted">
        {{ t(view === 'open' ? 'appeal.admin.empty' : 'appeal.admin.emptyClosed') }}
      </p>
 
      <div v-else class="table-responsive">
        <table class="table align-middle">
          <thead>
            <tr>
              <th>{{ t('appeal.admin.colDate') }}</th>
              <th>{{ t('report.admin.colContent') }}</th>
              <th>{{ t('appeal.admin.colContested') }}</th>
              <th>{{ t('appeal.admin.colAppellant') }}</th>
              <th>{{ t('appeal.admin.colMessage') }}</th>
              <th>{{ t('report.admin.colDecision') }}</th>
            </tr>
          </thead>
          <tbody>
            <tr
              v-for="appeal in list.items"
              :key="appeal.id"
              class="appeal-row"
              :data-appeal-id="appeal.id"
            >
              <td class="text-nowrap align-top">{{ formatDateTime(appeal.createdAt) }}</td>
              <td class="align-top">
                <AdminReportContent :item="appeal" :people="[appeal.reportedUser]" />
                <span
                  class="badge mt-1 report-reason"
                  :class="appeal.reason === 'illegal' ? 'bg-danger' : 'bg-light text-dark border'"
                >
                  {{ t(`report.reasons.${appeal.reason}`) }}
                </span>
              </td>
              <td class="align-top">
                <span
                  class="badge appeal-contested"
                  :class="appeal.decision.outcome === 'actioned' ? 'bg-danger' : 'bg-success'"
                >
                  {{ t(`report.decision.outcomes.${appeal.decision.outcome}`) }}
                </span>
                <div class="small mt-1">{{ decisionSummary(appeal.decision) }}</div>
                <div v-if="appeal.decision.note" class="small text-muted">
                  {{ appeal.decision.note }}
                </div>
                <div class="small text-muted">{{ formatDateTime(appeal.decision.decidedAt) }}</div>
              </td>
              <td class="align-top">
                <span class="badge bg-secondary mb-1 appeal-role">
                  {{ t(`appeal.admin.roles.${appeal.role}`) }}
                </span>
                <AdminReportUserCell
                  :user="appeal.appellant"
                  :standing="appeal.role === 'author' ? appeal.reportedUserStanding : null"
                />
              </td>
              <td class="align-top appeal-message">{{ appeal.message }}</td>
              <td class="align-top">
                <button
                  v-if="appeal.status === 'open'"
                  type="button"
                  class="btn btn-sm btn-outline-primary text-nowrap appeal-decide"
                  :disabled="!appeal.appellant"
                  @click="deciding = appeal"
                >
                  <font-awesome-icon icon="fa-solid fa-scale-balanced" class="me-1" />
                  {{ t('report.admin.decide') }}
                </button>
                <template v-else-if="appeal.appealDecision">
                  <span
                    class="badge appeal-outcome"
                    :class="
                      appeal.status === 'overturned' ? 'bg-warning text-dark' : 'bg-secondary'
                    "
                  >
                    {{ t(`appeal.admin.outcomes.${appeal.appealDecision.outcome}`) }}
                  </span>
                  <div v-if="appeal.appealDecision.note" class="small text-muted appeal-note">
                    {{ appeal.appealDecision.note }}
                  </div>
                  <div class="small text-muted">
                    {{ formatDateTime(appeal.appealDecision.decidedAt) }}
                  </div>
                </template>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
 
      <button
        v-if="list.nextCursor"
        type="button"
        class="btn btn-outline-secondary"
        :disabled="list.loadingMore"
        @click="list.loadMore()"
      >
        {{ t('admin.loadMore') }}
      </button>
    </template>
 
    <AppealDecisionModal :appeal="deciding" @close="deciding = null" @decided="onDecided" />
  </div>
</template>
 
<script setup lang="ts">
// @implements UC-REPORT-010.1
import { computed, onMounted, ref } from 'vue'
import { useAdminStore, type AdminAppeal } from '@/stores/admin'
import { useUILanguage } from '@/composables/useUILanguage'
import { useDateFormat } from '@/composables/useDateFormat'
import { useReportDecisionSummary } from '@/composables/useReportDecisionSummary'
import LoadingSpinner from '@/components/LoadingSpinner.vue'
import ErrorAlert from '@/components/ErrorAlert.vue'
import AdminReportContent from '@/components/AdminReportContent.vue'
import AdminReportUserCell from '@/components/AdminReportUserCell.vue'
import AppealDecisionModal from '@/components/AppealDecisionModal.vue'
 
const adminStore = useAdminStore()
const { t } = useUILanguage()
const { formatDateTime } = useDateFormat()
const { decisionSummary } = useReportDecisionSummary()
 
const VIEWS = ['open', 'closed'] as const
type View = (typeof VIEWS)[number]
 
const view = ref<View>('open')
const list = computed(() => (view.value === 'open' ? adminStore.appeals : adminStore.closedAppeals))
const deciding = ref<AdminAppeal | null>(null)
 
function switchView(next: View) {
  if (view.value === next) return
  view.value = next
  list.value.load()
}
 
// The appeal moved to the decided ones; an overturned dismissal reopened reports
function onDecided() {
  deciding.value = null
  adminStore.appeals.load()
  adminStore.closedAppeals.load()
}
 
onMounted(() => list.value.load())
</script>
 
<style scoped>
.appeal-message {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  min-width: 14rem;
}
</style>