feat: accept invitation

This commit is contained in:
Reto Aebersold 2023-12-12 14:59:18 +01:00
parent f7883b1bee
commit ed1493bc00
5 changed files with 73 additions and 4 deletions

View File

@ -0,0 +1,55 @@
<script setup lang="ts">
import { useCSRFFetch } from "@/fetchHelpers";
import { getCockpitUrl } from "@/utils/utils";
const props = defineProps<{
courseId: string;
invitationId: string;
}>();
const { data, error } = useCSRFFetch(`/api/mentor/${props.courseId}/invitations/accept`)
.post({
invitation_id: props.invitationId,
})
.json();
</script>
<template>
<div class="flex-grow bg-gray-200">
<div class="container-large">
<header class="mb-8 mt-12">
<h1 class="mb-8">{{ $t("a.Einladung") }}</h1>
</header>
<main>
<div class="bg-white p-6">
<template v-if="error">
{{
$t(
"a.Die Einladung konnte nicht akzeptiert werden. Bitte melde dich beim Support."
)
}}
<div>
<a class="underline" href="mailto:help@vbv.ch">help@vbv.ch</a>
</div>
</template>
<template v-else>
<i18next
:translation="
$t('a.Du hast die Einladung von {name} erfolgreich akzeptiert.')
"
>
<template #name>
<b>{{ data.user.first_name }} {{ data.user.last_name }}</b>
</template>
</i18next>
<div class="mt-4">
<a class="underline" :href="getCockpitUrl(data.course_slug)">
{{ $t("a.Cockpit anschauen") }}
</a>
</div>
</template>
</div>
</main>
</div>
</div>
</template>

View File

@ -134,12 +134,12 @@ const inviteMentor = async () => {
<template #body>
<div class="flex flex-col">
<label for="mentor-email">{{ $t("a.E-Mail Adresse") }}</label>
<input v-model="inviteeEmail" id="mentor-email" type="email" />
<input id="mentor-email" v-model="inviteeEmail" type="email" />
<button
:disabled="!validEmail"
@click="inviteMentor()"
class="btn-primary mt-8"
@click="inviteMentor()"
>
{{ $t("a.Einladung abschicken") }}
</button>

View File

@ -126,6 +126,11 @@ const router = createRouter({
component: () => import("@/pages/learningMentor/MentorManagementPage.vue"),
props: true,
},
{
path: "/lernbegleitung/:courseId/invitation/:invitationId",
component: () => import("@/pages/learningMentor/InvitationAcceptPage.vue"),
props: true,
},
{
path: "/course/:courseSlug/cockpit",
children: [

View File

@ -232,4 +232,8 @@ class LearningMentorInvitationTest(APITestCase):
mentor=invitee, course=self.course, participants=participant_cs_user
).exists()
)
self.assertEqual(response.data["id"], str(self.participant.id))
user = response.data["user"]
self.assertEqual(user["id"], str(self.participant.id))
self.assertEqual(response.data["course_slug"], str(self.course.slug))

View File

@ -186,4 +186,9 @@ def accept_invitation(request, course_session_id: int):
mentor.participants.add(invitation.participant)
invitation.delete()
return Response(UserSerializer(invitation.participant.user).data)
return Response(
{
"course_slug": course_session.course.slug,
"user": UserSerializer(invitation.participant.user).data,
}
)