Files
pichunt/app/pages/hunt/[huntSlug]/teams.vue
T

76 lines
1.8 KiB
Vue

<script setup lang="ts">
import { parseError, sluggy } from '#imports';
import Team from '~/components/admin/Team.vue';
import { useHuntStore } from '~/stores/hunt';
import { useTitleStore } from '~/stores/title';
definePageMeta({
middleware: ['auth']
});
const app = useNuxtApp();
const { loggedIn } = useUserSession();
const localePath = useLocalePath();
const { t } = useI18n();
const { tKey, hasKey } = useI18nKey();
const router = useRouter();
const { name, id } = app.$slugData.huntSlug!;
const titleStore = useTitleStore();
const huntStore = useHuntStore();
const { data, refresh, error } = await useFetch(`/api/admin/hunt/${id}/teams`);
huntStore.setMembership(id, !error.value);
useHead({
title: t('layouts.title', {
title: hasKey(data.value, 'name') ? tKey(data.value!, 'name').value : name
})
});
watch(loggedIn, (isLoggedIn) => {
if (!isLoggedIn) {
router.push(localePath('/login'));
}
});
titleStore.title = data.value ? tKey(data.value, 'name').value : undefined;
type Data = NonNullable<(typeof data)['value']>;
export type Team = Data['teams'][number];
</script>
<template>
<div>
<div v-if="error">
<VaAlert color="danger" class="my-4">
{{ t(parseError(error)) }}
</VaAlert>
<VaButton
icon="arrow_back"
:to="localePath(`/hunt/${sluggy(app.$slugData.huntSlug!)}`)"
>{{ t('page.common.back_to_hunt') }}</VaButton
>
</div>
<template v-else>
<h1 class="mb-4 text-3xl">
Teams
<VaButton color="success" icon="replay" @click="refresh"
>Refresh</VaButton
>
</h1>
<VaAccordion v-if="data" stateful inset>
<Team
v-for="team in data.teams"
:key="team.id"
:team="team"
:hunt-id="id"
@refresh="refresh"
/>
</VaAccordion>
</template>
</div>
</template>