2023-04-30 15:28:10 +02:00
|
|
|
<template>
|
2023-05-06 13:14:01 +02:00
|
|
|
<p class="my-10 text-center text-gray-300">
|
2023-04-30 15:28:10 +02:00
|
|
|
Je zit momenteel niet in een team. Maak een team aan of wacht tot dat je geinvite wordt
|
|
|
|
</p>
|
2023-05-06 13:14:01 +02:00
|
|
|
<div class="mb-5 flex w-full justify-center gap-10">
|
2023-05-06 13:09:46 +02:00
|
|
|
<span
|
2023-05-09 13:57:01 +02:00
|
|
|
class="font-bold text-primary hover:cursor-pointer" :class="{ 'underline underline-offset-4': !createTeam.show }"
|
|
|
|
@click="createTeam.show = false"
|
2023-05-06 13:09:46 +02:00
|
|
|
>
|
|
|
|
Team Invites
|
|
|
|
</span>
|
2023-05-06 13:14:01 +02:00
|
|
|
<span
|
2023-05-09 13:57:01 +02:00
|
|
|
class="font-bold text-primary hover:cursor-pointer" :class="{ 'underline underline-offset-4': createTeam.show }"
|
|
|
|
@click="createTeam.show = true"
|
2023-05-06 13:09:46 +02:00
|
|
|
>
|
|
|
|
Create Team
|
|
|
|
</span>
|
2023-04-30 15:28:10 +02:00
|
|
|
</div>
|
2023-05-09 13:57:01 +02:00
|
|
|
<div v-if="!createTeam.show" class="text-center text-gray-300">
|
|
|
|
<h2 v-if="!user.teamInvites.length">You don't have any team invites</h2>
|
|
|
|
<div v-else class="mx-auto flex max-w-lg flex-col">
|
|
|
|
<div v-for="team in filteredTeams" :key="team._id" class="flex items-center rounded bg-neutral-800 px-3 py-1 text-left" @click="acceptInvite(team)">
|
|
|
|
<span>
|
|
|
|
{{ team.name }}
|
|
|
|
</span>
|
|
|
|
<Button class="ml-auto">Accept</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-04-30 15:28:10 +02:00
|
|
|
</div>
|
2023-05-06 13:14:01 +02:00
|
|
|
<div v-else class="flex w-full flex-col items-center gap-5">
|
2023-05-09 13:57:01 +02:00
|
|
|
<Input v-model:value="createTeam.name" class="w-full max-w-sm">Naam / Prefix</Input>
|
|
|
|
<Colorpicker v-model:value="createTeam.color" class="w-full max-w-sm" />
|
|
|
|
<Button @click="handleCreateTeam">Create Team</Button>
|
2023-04-30 15:28:10 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
2023-05-09 13:57:01 +02:00
|
|
|
const user = useState('user')
|
|
|
|
|
|
|
|
const teams = await $fetch('/api/team/all')
|
|
|
|
|
|
|
|
const filteredTeams = computed(() => {
|
|
|
|
return teams.filter(a => user.value.teamInvites.includes(a._id));
|
|
|
|
})
|
|
|
|
|
|
|
|
const createTeam = ref({
|
|
|
|
show: false,
|
|
|
|
name: '',
|
|
|
|
color: '',
|
|
|
|
})
|
|
|
|
|
|
|
|
const acceptInvite = async (team) => {
|
|
|
|
try {
|
|
|
|
const response = await $fetch('/api/team/acceptinvite', {
|
|
|
|
method: 'POST',
|
|
|
|
body: { teamId: team._id }
|
|
|
|
})
|
|
|
|
|
|
|
|
user.value.team = { id: response._id, admin: false }
|
|
|
|
|
2023-05-09 16:01:19 +02:00
|
|
|
useToast().success('Succesvol lid geworden van het team')
|
2023-05-09 13:57:01 +02:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
useToast().error(e.statusMessage)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleCreateTeam = async () => {
|
|
|
|
try {
|
|
|
|
const response = await $fetch('/api/team/create', {
|
|
|
|
method: 'POST',
|
|
|
|
body: { teamName: createTeam.value.name, teamColor: createTeam.value.color }
|
|
|
|
})
|
|
|
|
|
|
|
|
user.value.team = { id: response.insertedId.toString(), admin: true }
|
|
|
|
|
2023-05-09 16:01:19 +02:00
|
|
|
useToast().success('Succesvol team gemaakt')
|
2023-05-09 13:57:01 +02:00
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
useToast().error(e.statusMessage)
|
|
|
|
}
|
|
|
|
}
|
2023-04-30 15:28:10 +02:00
|
|
|
</script>
|