All files / src/components AppealDecisionModal.vue

97.36% Statements 37/38
96.15% Branches 25/26
100% Functions 9/9
100% Lines 37/37

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    34x             1x   3x   3x                   1x     3x 3x 3x 46x     6x                                     1x             3x         1x                                                               15x 3x     15x   15x   15x 15x 15x   15x 15x 15x     15x 18x   3x 3x         5x 5x 5x 5x 5x 5x           4x 4x   1x   5x        
<template>
  <div
    v-if="appeal"
    class="modal fade show d-block appeal-decision-modal"
    role="dialog"
    aria-modal="true"
    aria-labelledby="appeal-decision-title"
    tabindex="-1"
    style="background-color: rgba(0, 0, 0, 0.5)"
    @click.self="!submitting && emit('close')"
  >
    <div class="modal-dialog modal-dialog-centered">
      <form class="modal-content" @submit.prevent="submit">
        <div class="modal-header">
          <h5 id="appeal-decision-title" class="modal-title">
            <font-awesome-icon icon="fa-solid fa-scale-balanced" class="me-2" />
            {{ t('appeal.admin.decideTitle') }}
          </h5>
          <button
            type="button"
            class="btn-close"
            :aria-label="t('common.close')"
            :disabled="submitting"
            @click="emit('close')"
          ></button>
        </div>
        <div class="modal-body">
          <fieldset class="mb-3">
            <legend class="form-label fs-6">{{ t('report.decision.outcomeLabel') }}</legend>
            <div v-for="option in OUTCOMES" :key="option" class="form-check">
              <input
                :id="`appeal-outcome-${option}`"
                v-model="outcome"
                class="form-check-input"
                type="radio"
                name="appeal-outcome"
                :value="option"
                :disabled="submitting"
              />
              <label class="form-check-label" :for="`appeal-outcome-${option}`">
                {{ t(`appeal.admin.outcomes.${option}`) }}
              </label>
            </div>
          </fieldset>
          <!-- What overturning does, which depends on who appealed -->
          <p v-if="outcome === 'overturned'" class="small text-muted appeal-effect">
            {{ t(`appeal.admin.effect.${appeal.role}`) }}
          </p>
          <label for="appeal-note" class="form-label">{{ t('appeal.admin.noteLabel') }}</label>
          <textarea
            id="appeal-note"
            v-model="note"
            class="form-control"
            rows="3"
            :maxlength="MAX_NOTE_LENGTH"
            :disabled="submitting"
          />
        </div>
        <div class="modal-footer">
          <button
            type="button"
            class="btn btn-secondary"
            :disabled="submitting"
            @click="emit('close')"
          >
            <font-awesome-icon icon="fa-solid fa-xmark" class="me-2" />
            {{ t('common.cancel') }}
          </button>
          <button
            type="submit"
            class="btn btn-primary appeal-submit"
            :disabled="!outcome || submitting"
          >
            <span
              v-if="submitting"
              class="spinner-border spinner-border-sm me-2"
              role="status"
              aria-hidden="true"
            />
            {{ t('report.decision.submit') }}
          </button>
        </div>
      </form>
    </div>
  </div>
</template>
 
<script setup lang="ts">
// @implements UC-REPORT-010.1
import { ref, watch } from 'vue'
import { useUILanguage } from '@/composables/useUILanguage'
import { useToastStore } from '@/stores/toast'
import { useAdminStore, type AdminAppeal, type AppealOutcome } from '@/stores/admin'
import { getErrorMessage } from '@/utils/errors'
 
const OUTCOMES: AppealOutcome[] = ['upheld', 'overturned']
const MAX_NOTE_LENGTH = 1000
 
// Open while an appeal is set
const props = defineProps<{ appeal: AdminAppeal | null }>()
 
const emit = defineEmits<{ close: []; decided: [] }>()
 
const { t } = useUILanguage()
const toastStore = useToastStore()
const adminStore = useAdminStore()
 
const outcome = ref<AppealOutcome | null>(null)
const note = ref('')
const submitting = ref(false)
 
// Every decision starts blank
watch(
  () => props.appeal?.id,
  () => {
    outcome.value = null
    note.value = ''
  }
)
 
async function submit() {
  const appeal = props.appeal
  Iif (!appeal?.appellant || !outcome.value || submitting.value) return
  submitting.value = true
  try {
    const trimmed = note.value.trim()
    await adminStore.decideAppeal({
      decisionId: appeal.decisionId,
      appellantId: appeal.appellant.id,
      outcome: outcome.value,
      ...(trimmed && { note: trimmed })
    })
    toastStore.success(t('report.decision.success'))
    emit('decided')
  } catch (err) {
    toastStore.error(getErrorMessage(err, t('report.decision.error'), t))
  } finally {
    submitting.value = false
  }
}
</script>