All files / components/composite AttendanceList.vue

100% Statements 107/107
100% Branches 19/19
100% Functions 0/0
100% Lines 107/107

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  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   19x 1x 1x 1x 1x 1x 1x   1x 1x   1x 1x 1x 1x 1x   16x 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   19x 1x 1x 1x   1x 1x 1x 1x                             1x                 1x         1x 1x 23x 23x 23x 23x 23x         23x 1x 23x 23x 23x 23x 23x         23x 1x 23x 23x         23x 1x 1x 1x    
<template>
  <div data-testid="attendance-list" class="space-y-4">
    <!-- Summary Stats -->
    <div class="flex gap-4 text-sm">
      <div class="flex items-center gap-1.5">
        <BaseBadge variant="yes" size="sm">{{ attendanceCount.yes }}</BaseBadge>
        <span class="text-secondary-600">{{ $t('rsvp.yes') }}</span>
      </div>
      <div class="flex items-center gap-1.5">
        <BaseBadge variant="no" size="sm">{{ attendanceCount.no }}</BaseBadge>
        <span class="text-secondary-600">{{ $t('rsvp.no') }}</span>
      </div>
      <div class="flex items-center gap-1.5">
        <BaseBadge variant="maybe" size="sm">{{ attendanceCount.maybe }}</BaseBadge>
        <span class="text-secondary-600">{{ $t('rsvp.maybe') }}</span>
      </div>
    </div>
 
    <!-- Grouped Lists -->
    <div class="space-y-4">
      <!-- Yes Responses -->
      <div v-if="groupedResponses.yes.length > 0">
        <h4 class="text-sm font-medium text-success-700 mb-2">
          {{ $t('rsvp.attending', { count: groupedResponses.yes.length }) }}
        </h4>
        <ul class="space-y-1">
          <li
            v-for="response in groupedResponses.yes"
            :key="response.userId"
            class="flex items-center gap-2 text-sm text-secondary-700"
          >
            <span class="w-2 h-2 rounded-full bg-success-500" />
            {{ getMemberName(response.userId) }}
          </li>
        </ul>
      </div>
 
      <!-- No Responses -->
      <div v-if="groupedResponses.no.length > 0">
        <h4 class="text-sm font-medium text-error-700 mb-2">
          {{ $t('rsvp.notAttending', { count: groupedResponses.no.length }) }}
        </h4>
        <ul class="space-y-1">
          <li
            v-for="response in groupedResponses.no"
            :key="response.userId"
            class="flex items-center gap-2 text-sm text-secondary-700"
          >
            <span class="w-2 h-2 rounded-full bg-error-500" />
            {{ getMemberName(response.userId) }}
          </li>
        </ul>
      </div>
 
      <!-- Maybe Responses -->
      <div v-if="groupedResponses.maybe.length > 0">
        <h4 class="text-sm font-medium text-warning-700 mb-2">
          {{ $t('rsvp.maybeAttending', { count: groupedResponses.maybe.length }) }}
        </h4>
        <ul class="space-y-1">
          <li
            v-for="response in groupedResponses.maybe"
            :key="response.userId"
            class="flex items-center gap-2 text-sm text-secondary-700"
          >
            <span class="w-2 h-2 rounded-full bg-warning-500" />
            {{ getMemberName(response.userId) }}
          </li>
        </ul>
      </div>
 
      <!-- No Responses Yet -->
      <div
        v-if="noResponses.length > 0"
        class="pt-2 border-t border-secondary-200"
      >
        <h4 class="text-sm font-medium text-secondary-500 mb-2">
          {{ $t('rsvp.noResponse', { count: noResponses.length }) }}
        </h4>
        <ul class="space-y-1">
          <li
            v-for="member in noResponses"
            :key="member.id"
            class="flex items-center gap-2 text-sm text-secondary-400"
          >
            <span class="w-2 h-2 rounded-full bg-secondary-300" />
            {{ member.name }}
          </li>
        </ul>
      </div>
 
      <!-- Empty State -->
      <p
        v-if="responses.length === 0 && members.length === 0"
        class="text-sm text-secondary-500 text-center py-4"
      >
        {{ $t('rsvp.noResponsesYet') }}
      </p>
    </div>
  </div>
</template>
 
<script setup lang="ts">
/**
 * AttendanceList
 * @description Composite component displaying grouped attendance responses
 * Shows team members grouped by their RSVP status
 */
 
import type { AttendanceResponse, TeamMember, AttendanceCount } from '~/types'
 
/**
 * i18n
 */
const { t } = useI18n()
 
interface Props {
  /** Array of attendance responses */
  responses: AttendanceResponse[]
  /** Array of team members for name lookup */
  members: TeamMember[]
}
 
const props = defineProps<Props>()
 
/**
 * Group responses by status
 */
const groupedResponses = computed(() => {
  return {
    yes: props.responses.filter(r => r.status === 'yes'),
    no: props.responses.filter(r => r.status === 'no'),
    maybe: props.responses.filter(r => r.status === 'maybe')
  }
})
 
/**
 * Attendance count summary
 */
const attendanceCount = computed((): AttendanceCount => {
  return {
    yes: groupedResponses.value.yes.length,
    no: groupedResponses.value.no.length,
    maybe: groupedResponses.value.maybe.length
  }
})
 
/**
 * Members who haven't responded
 */
const noResponses = computed((): TeamMember[] => {
  const respondedUserIds = new Set(props.responses.map(r => r.userId))
  return props.members.filter(m => !respondedUserIds.has(m.id))
})
 
/**
 * Get member name by userId
 */
const getMemberName = (userId: string): string => {
  const member = props.members.find(m => m.id === userId)
  return member?.name ?? 'Unknown'
}
</script>