|
| 1 | +<template> |
| 2 | + <v-badge |
| 3 | + :model-value="pendingInvitationsCount > 0" |
| 4 | + :content="pendingInvitationsCount" |
| 5 | + offset-y="-4" |
| 6 | + offset-x="-4" |
| 7 | + location="top right" |
| 8 | + color="success" |
| 9 | + size="x-small" |
| 10 | + data-test="invitations-menu-badge" |
| 11 | + :class="{ 'mr-1': pendingInvitationsCount > 0 }" |
| 12 | + > |
| 13 | + <v-icon |
| 14 | + color="primary" |
| 15 | + aria-label="Open pending invitations menu" |
| 16 | + icon="mdi-email" |
| 17 | + data-test="invitations-menu-icon" |
| 18 | + @click="toggleDrawer" |
| 19 | + /> |
| 20 | + </v-badge> |
| 21 | + |
| 22 | + <Teleport to="body"> |
| 23 | + <v-navigation-drawer |
| 24 | + v-model="isDrawerOpen" |
| 25 | + location="right" |
| 26 | + temporary |
| 27 | + :width="thresholds.sm" |
| 28 | + class="bg-v-theme-surface" |
| 29 | + data-test="invitations-drawer" |
| 30 | + > |
| 31 | + <v-card |
| 32 | + class="bg-v-theme-surface h-100" |
| 33 | + flat |
| 34 | + data-test="invitations-card" |
| 35 | + > |
| 36 | + <v-card-title class="text-h6 py-3">Pending Invitations</v-card-title> |
| 37 | + |
| 38 | + <v-card-text class="pa-4 pt-0"> |
| 39 | + <div |
| 40 | + v-if="isLoading" |
| 41 | + class="d-flex justify-center align-center" |
| 42 | + style="min-height: 200px" |
| 43 | + data-test="loading-state" |
| 44 | + > |
| 45 | + <v-progress-circular indeterminate /> |
| 46 | + </div> |
| 47 | + |
| 48 | + <v-list |
| 49 | + v-else-if="pendingInvitationsList.length > 0" |
| 50 | + density="compact" |
| 51 | + class="bg-v-theme-surface pa-0" |
| 52 | + data-test="invitations-list" |
| 53 | + > |
| 54 | + <InvitationsMenuItem |
| 55 | + v-for="(invitation, index) in pendingInvitationsList" |
| 56 | + :key="index" |
| 57 | + :invitation="invitation" |
| 58 | + @update="fetchInvitations" |
| 59 | + /> |
| 60 | + </v-list> |
| 61 | + |
| 62 | + <div |
| 63 | + v-else |
| 64 | + class="d-flex flex-column justify-center align-center text-center" |
| 65 | + style="min-height: 200px" |
| 66 | + data-test="empty-state" |
| 67 | + > |
| 68 | + <v-icon |
| 69 | + size="64" |
| 70 | + color="medium-emphasis" |
| 71 | + class="mb-4" |
| 72 | + icon="mdi-email-check-outline" |
| 73 | + /> |
| 74 | + <div class="text-body-2 text-medium-emphasis">No pending invitations</div> |
| 75 | + </div> |
| 76 | + </v-card-text> |
| 77 | + </v-card> |
| 78 | + </v-navigation-drawer> |
| 79 | + </Teleport> |
| 80 | +</template> |
| 81 | + |
| 82 | +<script setup lang="ts"> |
| 83 | +import { ref, computed, onBeforeMount, watch } from "vue"; |
| 84 | +import { useDisplay } from "vuetify"; |
| 85 | +import useSnackbar from "@/helpers/snackbar"; |
| 86 | +import handleError from "@/utils/handleError"; |
| 87 | +import InvitationsMenuItem from "./InvitationsMenuItem.vue"; |
| 88 | +import useInvitationsStore from "@/store/modules/invitations"; |
| 89 | +
|
| 90 | +const { thresholds } = useDisplay(); |
| 91 | +const invitationsStore = useInvitationsStore(); |
| 92 | +const snackbar = useSnackbar(); |
| 93 | +
|
| 94 | +const isDrawerOpen = defineModel<boolean>({ required: true }); |
| 95 | +const isLoading = ref(false); |
| 96 | +const pendingInvitationsList = computed(() => invitationsStore.pendingInvitations); |
| 97 | +const pendingInvitationsCount = computed(() => pendingInvitationsList.value.length); |
| 98 | +
|
| 99 | +const toggleDrawer = () => { isDrawerOpen.value = !isDrawerOpen.value; }; |
| 100 | +
|
| 101 | +const fetchInvitations = async () => { |
| 102 | + try { |
| 103 | + isLoading.value = true; |
| 104 | + await invitationsStore.fetchUserPendingInvitationList(); |
| 105 | + } catch (error: unknown) { |
| 106 | + snackbar.showError("Failed to fetch pending invitations"); |
| 107 | + handleError(error); |
| 108 | + } finally { |
| 109 | + isLoading.value = false; |
| 110 | + } |
| 111 | +}; |
| 112 | +
|
| 113 | +onBeforeMount(async () => { |
| 114 | + await fetchInvitations(); |
| 115 | +}); |
| 116 | +
|
| 117 | +watch(isDrawerOpen, async (newValue) => { |
| 118 | + if (newValue) { |
| 119 | + await fetchInvitations(); |
| 120 | + } |
| 121 | +}); |
| 122 | +
|
| 123 | +defineExpose({ |
| 124 | + isDrawerOpen, |
| 125 | + pendingInvitationsList, |
| 126 | + isLoading, |
| 127 | + toggleDrawer, |
| 128 | + fetchInvitations, |
| 129 | +}); |
| 130 | +</script> |
0 commit comments