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 | 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 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 | <template>
<div data-testid="admin-club-notifications">
<div class="flex justify-between items-center gap-3 flex-wrap mb-6">
<h2 class="text-xl font-bold text-fg">Live Match Notifications</h2>
<div
v-if="isAdmin"
class="flex gap-1 text-sm"
role="tablist"
data-testid="admin-notifications-scope"
>
<button
v-for="tab in scopeTabs"
:key="tab.id"
role="tab"
:aria-selected="scope === tab.id"
:class="[
'px-3 py-1.5 rounded-md border',
scope === tab.id
? 'bg-brand-600 text-white border-brand-600'
: 'bg-card text-fg border-line',
]"
:data-testid="`scope-${tab.id}`"
@click="scope = tab.id"
>
{{ tab.label }}
</button>
</div>
</div>
<ChannelManager
v-if="isAdmin && scope === 'global'"
scope-type="global"
heading="Every match"
/>
<template v-else>
<!-- Admins pick a club; club_managers are auto-scoped to their own -->
<div v-if="isAdmin" class="flex items-center gap-3 mb-4">
<label class="text-sm text-fg-muted" for="club-picker">Club:</label>
<select
id="club-picker"
v-model.number="selectedClubId"
data-testid="admin-notifications-club-picker"
class="px-3 py-2 bg-card text-fg border border-line rounded-md text-sm focus:outline-none focus:ring-2 focus:ring-brand-500"
>
<option :value="null" disabled>Select a club…</option>
<option v-for="c in clubs" :key="c.id" :value="c.id">
{{ c.name }}
</option>
</select>
</div>
<div v-if="loadingClubs" class="text-sm text-fg-muted">
Loading clubs…
</div>
<div
v-else-if="!isAdmin && !selectedClubId"
class="bg-yellow-50 border border-yellow-200 rounded-md p-4 text-sm text-yellow-800 dark:bg-yellow-500/10 dark:border-yellow-500/30 dark:text-yellow-200"
data-testid="no-club-assigned"
>
No club is assigned to your account. Contact an administrator to have
one assigned before configuring notifications.
</div>
<div v-else-if="selectedClubId">
<ChannelManager scope-type="club" :club-id="selectedClubId" />
<p class="text-sm text-fg-muted mt-4">
Squad channels (one age group) are set up from that team's page.
</p>
</div>
<div v-else class="text-sm text-fg-muted" data-testid="no-club-selected">
Select a club to configure its notification channels.
</div>
</template>
</div>
</template>
<script setup>
import { computed, onMounted, ref } from 'vue';
import { useAuthStore } from '@/stores/auth';
import { getApiBaseUrl } from '@/config/api';
import ChannelManager from '@/components/notifications/ChannelManager.vue';
const authStore = useAuthStore();
const isAdmin = computed(() => authStore.isAdmin.value);
const ownClubId = computed(() => authStore.state.profile?.club_id ?? null);
const clubs = ref([]);
const loadingClubs = ref(false);
const selectedClubId = ref(null);
const scopeTabs = [
{ id: 'club', label: 'One club' },
{ id: 'global', label: 'Every match' },
];
const scope = ref('club');
const fetchClubs = async () => {
loadingClubs.value = true;
try {
const resp = await fetch(`${getApiBaseUrl()}/api/clubs`, {
headers: authStore.getAuthHeaders(),
});
if (resp.ok) {
clubs.value = await resp.json();
}
} finally {
loadingClubs.value = false;
}
};
onMounted(async () => {
if (isAdmin.value) {
await fetchClubs();
} else {
selectedClubId.value = ownClubId.value;
}
});
</script>
|