feat: manage invitation

This commit is contained in:
Reto Aebersold 2023-12-13 11:25:17 +01:00
parent ae91f442f6
commit 4866602c26
3 changed files with 14 additions and 10 deletions

View File

@ -10,11 +10,11 @@ const showInvitationModal = ref(false);
const inviteeEmail = ref(""); const inviteeEmail = ref("");
const { execute: refreshMentors, data: mentors } = useCSRFFetch( const { execute: refreshMentors, data: mentors } = useCSRFFetch(
`/api/mentor/${courseSession.value.course.id}/mentors` `/api/mentor/${courseSession.value.id}/mentors`
).json(); ).json();
const { execute: refreshInvitations, data: invitations } = useCSRFFetch( const { execute: refreshInvitations, data: invitations } = useCSRFFetch(
`/api/mentor/${courseSession.value.course.id}/invitations` `/api/mentor/${courseSession.value.id}/invitations`
).json(); ).json();
const hasMentors = computed(() => { const hasMentors = computed(() => {
@ -31,22 +31,20 @@ const validEmail = computed(() => {
const removeInvitation = async (invitationId: string) => { const removeInvitation = async (invitationId: string) => {
await useCSRFFetch( await useCSRFFetch(
`/api/mentor/${courseSession.value.course.id}/invitations/${invitationId}/delete` `/api/mentor/${courseSession.value.id}/invitations/${invitationId}/delete`
).delete(); ).delete();
await refreshInvitations(); await refreshInvitations();
}; };
const removeMentor = async (mentorId: string) => { const removeMentor = async (mentorId: string) => {
await useCSRFFetch( await useCSRFFetch(
`/api/mentor/${courseSession.value.course.id}/mentors/${mentorId}/leave` `/api/mentor/${courseSession.value.id}/mentors/${mentorId}/leave`
).delete(); ).delete();
await refreshMentors(); await refreshMentors();
}; };
const inviteMentor = async () => { const inviteMentor = async () => {
await useCSRFFetch( await useCSRFFetch(`/api/mentor/${courseSession.value.id}/invitations/create`).post({
`/api/mentor/${courseSession.value.course.id}/invitations/create`
).post({
email: inviteeEmail.value, email: inviteeEmail.value,
}); });
await refreshInvitations(); await refreshInvitations();

View File

@ -8,7 +8,7 @@ import {
useCourseSessionDetailQuery, useCourseSessionDetailQuery,
useCurrentCourseSession, useCurrentCourseSession,
} from "@/composables"; } from "@/composables";
import { bustItGetCache } from "@/fetchHelpers"; import { bustItGetCache, useCSRFFetch } from "@/fetchHelpers";
import { UPSERT_ASSIGNMENT_COMPLETION_MUTATION } from "@/graphql/mutations"; import { UPSERT_ASSIGNMENT_COMPLETION_MUTATION } from "@/graphql/mutations";
import AssignmentSubmissionResponses from "@/pages/learningPath/learningContentPage/assignment/AssignmentSubmissionResponses.vue"; import AssignmentSubmissionResponses from "@/pages/learningPath/learningContentPage/assignment/AssignmentSubmissionResponses.vue";
import { useUserStore } from "@/stores/user"; import { useUserStore } from "@/stores/user";
@ -61,6 +61,10 @@ const circleExpert = computed(() => {
return circleExperts.value[0]; return circleExperts.value[0];
}); });
const { data: learningMentors } = useCSRFFetch(
`/api/mentor/${courseSession.value.id}/mentors`
).json();
const circleExpertName = computed(() => { const circleExpertName = computed(() => {
return `${circleExpert.value?.first_name} ${circleExpert.value?.last_name}`; return `${circleExpert.value?.first_name} ${circleExpert.value?.last_name}`;
}); });
@ -156,7 +160,6 @@ const onSubmit = async () => {
></ItCheckbox> ></ItCheckbox>
<div v-if="mayBeEvaluated" class="w-full border-b border-gray-400"> <div v-if="mayBeEvaluated" class="w-full border-b border-gray-400">
<ItCheckbox <ItCheckbox
v-if="mayBeEvaluated"
class="py-6" class="py-6"
:checkbox-item="{ :checkbox-item="{
label: isPraxisAssignment label: isPraxisAssignment
@ -178,6 +181,9 @@ const onSubmit = async () => {
{{ circleExpertName }} {{ circleExpertName }}
</p> </p>
</div> </div>
<div>
{{ learningMentors }}
</div>
<!-- TODO: find way to find user that will do the corrections --> <!-- TODO: find way to find user that will do the corrections -->
</div> </div>
<div v-if="isCasework" class="flex flex-col space-x-2 pt-6 text-base sm:flex-row"> <div v-if="isCasework" class="flex flex-col space-x-2 pt-6 text-base sm:flex-row">

View File

@ -31,7 +31,7 @@ class InvitationSerializer(serializers.ModelSerializer):
def create(self, validated_data): def create(self, validated_data):
participant = self.context["course_session_user"] participant = self.context["course_session_user"]
invitation, _ = MentorInvitation.objects.get_or_create( invitation, _ = MentorInvitation.objects.get_or_create(
email=validated_data["email"], defaults={"participant": participant} email=validated_data["email"], participant=participant
) )
return invitation return invitation