chore: render mentor / expert cockpit based on role
This commit is contained in:
parent
ed1493bc00
commit
c3a16a7bec
|
|
@ -1,20 +1,26 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import log from "loglevel";
|
import { useCockpitStore } from "@/stores/cockpit";
|
||||||
|
import { useCurrentCourseSession } from "@/composables";
|
||||||
|
import { onMounted } from "vue";
|
||||||
|
import CockpitExpertPage from "./CockpitExpertPage.vue";
|
||||||
|
import CockpitMentorPage from "./CockpitMentorPage.vue";
|
||||||
|
|
||||||
const props = defineProps<{
|
const courseSession = useCurrentCourseSession();
|
||||||
courseSlug: string;
|
const cockpitStore = useCockpitStore();
|
||||||
}>();
|
|
||||||
|
|
||||||
// FIXME: Decide which page to show
|
onMounted(async () => {
|
||||||
// -> CockpitExpertPage.vue
|
await cockpitStore.fetchCockpitType(courseSession.value.course.id);
|
||||||
// -> CockpitMentorPage.vue
|
});
|
||||||
|
|
||||||
log.debug("Cockpit page created", props.courseSlug);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="bg-gray-200">
|
<div class="bg-gray-200">
|
||||||
<h1>TODO</h1>
|
<template v-if="cockpitStore.cockpitType == 'expert'">
|
||||||
|
<CockpitExpertPage :course-slug="courseSession.course.slug" />
|
||||||
|
</template>
|
||||||
|
<template v-else-if="cockpitStore.cockpitType == 'mentor'">
|
||||||
|
<CockpitMentorPage :course-slug="courseSession.course.slug" />
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,7 @@ const router = createRouter({
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: "",
|
path: "",
|
||||||
component: () => import("@/pages/cockpit/cockpitPage/CockpitExpertPage.vue"),
|
component: () => import("@/pages/cockpit/cockpitPage/CockpitPage.vue"),
|
||||||
props: true,
|
props: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { itGetCached } from "@/fetchHelpers";
|
||||||
|
import { defineStore } from "pinia";
|
||||||
|
import type { Ref } from "vue";
|
||||||
|
import { ref } from "vue";
|
||||||
|
|
||||||
|
type CockpitType = "mentor" | "expert" | null;
|
||||||
|
|
||||||
|
export const useCockpitStore = defineStore("cockpit", () => {
|
||||||
|
const cockpitType: Ref<CockpitType> = ref(null);
|
||||||
|
const cockpitTypeIsLoading = ref(false);
|
||||||
|
|
||||||
|
async function fetchCockpitType(courseId: string) {
|
||||||
|
cockpitTypeIsLoading.value = true;
|
||||||
|
const url = `/api/course/${courseId}/cockpit/`;
|
||||||
|
const response = await itGetCached(url);
|
||||||
|
cockpitType.value = response.type;
|
||||||
|
cockpitTypeIsLoading.value = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { cockpitType, cockpitTypeIsLoading, fetchCockpitType };
|
||||||
|
});
|
||||||
|
|
@ -125,7 +125,7 @@ urlpatterns = [
|
||||||
path(r"api/course/completion/<signed_int:course_session_id>/<uuid:user_id>/",
|
path(r"api/course/completion/<signed_int:course_session_id>/<uuid:user_id>/",
|
||||||
request_course_completion_for_user,
|
request_course_completion_for_user,
|
||||||
name="request_course_completion_for_user"),
|
name="request_course_completion_for_user"),
|
||||||
path(r"api/course/<int:course_id>/cockpit/",
|
path(r"api/course/<signed_int:course_id>/cockpit/",
|
||||||
get_cockpit_type,
|
get_cockpit_type,
|
||||||
name="get_cockpit_type"),
|
name="get_cockpit_type"),
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,4 +56,4 @@ class MeUserViewTest(APITestCase):
|
||||||
|
|
||||||
# THEN
|
# THEN
|
||||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
self.assertEquals(response.data["type"], "trainer")
|
self.assertEquals(response.data["type"], "expert")
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,6 @@ def get_cockpit_type(request, course_id: int):
|
||||||
course_session__course=course,
|
course_session__course=course,
|
||||||
role=CourseSessionUser.Role.EXPERT,
|
role=CourseSessionUser.Role.EXPERT,
|
||||||
).exists():
|
).exists():
|
||||||
cockpit_type = "trainer"
|
cockpit_type = "expert"
|
||||||
|
|
||||||
return Response({"type": cockpit_type})
|
return Response({"type": cockpit_type})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue