diff --git a/frontend/src/views/classes/SingleClass.vue b/frontend/src/views/classes/SingleClass.vue index c99a27ea..1ece11d5 100644 --- a/frontend/src/views/classes/SingleClass.vue +++ b/frontend/src/views/classes/SingleClass.vue @@ -10,6 +10,8 @@ import { useTeacherJoinRequestsQuery, useUpdateJoinRequestMutation } from "@/queries/teachers"; import type { ClassJoinRequestDTO } from "@dwengo-1/common/interfaces/class-join-request"; import { useClassDeleteStudentMutation, useClassQuery, useClassStudentsQuery } from "@/queries/classes"; +import { useCreateTeacherInvitationMutation } from "@/queries/teacher-invitations"; +import type { TeacherInvitationData } from "@dwengo-1/common/interfaces/teacher-invitation"; const { t } = useI18n(); @@ -19,6 +21,7 @@ const isLoading = ref(false); const isError = ref(false); const errorMessage = ref(""); + const usernameTeacher = ref(undefined); // Queries used to access the backend and catch loading or errors @@ -32,6 +35,8 @@ const { mutate } = useUpdateJoinRequestMutation(); // Handle deletion of a student from the class const { mutate: deleteStudentMutation } = useClassDeleteStudentMutation(); + // Handle creation of teacher invites + const { mutate: sentInviteMutation } = useCreateTeacherInvitationMutation(); // Load current user before rendering the page onMounted(async () => { @@ -104,6 +109,22 @@ ); } + function sentInvite(): void{ + if (!usernameTeacher.value) { + showSnackbar(t("please enter a valid username"), "error"); + return; + } + const data : TeacherInvitationData = {sender: username.value!, receiver: usernameTeacher.value, class: classId}; + sentInviteMutation(data, { + onSuccess: () => { + usernameTeacher.value = ""; + }, + onError: (e) => { + showSnackbar(t("failed: " + e.message), "error"); + } + }); + } + // Default of snackbar values const snackbar = ref({ visible: false, @@ -228,6 +249,34 @@ +
+
+

{{ t("inviteTeacher") }}

+

{{ t("enter the username of the teacher you would like to invite") }}

+ + + + + {{ t("invite") }} + + +
+