From e49a4971ae1b0e44c00e9ade6cda100ab5f1341a Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Wed, 3 Apr 2024 15:15:07 +0200 Subject: [PATCH] Add simple DashboardPersonsPage which loads data --- client/src/composables.ts | 27 +++++++++++++++-- client/src/fetchHelpers.ts | 20 ++++++++----- .../pages/dashboard/DashboardPersonsPage.vue | 22 ++++++++++++++ client/src/router/index.ts | 4 +++ client/src/services/dashboard.ts | 30 +++++++++++++++++++ 5 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 client/src/pages/dashboard/DashboardPersonsPage.vue diff --git a/client/src/composables.ts b/client/src/composables.ts index a4989aa0..cbf6dc97 100644 --- a/client/src/composables.ts +++ b/client/src/composables.ts @@ -5,8 +5,10 @@ import { COURSE_QUERY, COURSE_SESSION_DETAIL_QUERY } from "@/graphql/queries"; import { circleFlatChildren, circleFlatLearningContents, - circleFlatLearningUnits, + circleFlatLearningUnits } from "@/services/circle"; +import type { DashboardPersonType } from "@/services/dashboard"; +import { fetchDashboardPersons } from "@/services/dashboard"; import { presignUpload, uploadFile } from "@/services/files"; import { useCompletionStore } from "@/stores/completion"; import { useCourseSessionsStore } from "@/stores/courseSessions"; @@ -23,7 +25,7 @@ import type { LearningMentor, LearningPathType, LearningUnitPerformanceCriteria, - PerformanceCriteria, + PerformanceCriteria } from "@/types"; import { useQuery } from "@urql/vue"; import orderBy from "lodash/orderBy"; @@ -487,3 +489,24 @@ export function useMyLearningMentors() { loading, }; } + +export function useDashboardPersons() { + const dashboardPersons = ref([]); + const loading = ref(false); + + const fetchData = async () => { + loading.value = true; + try { + dashboardPersons.value = await fetchDashboardPersons(); + } finally { + loading.value = false; + } + }; + + onMounted(fetchData); + + return { + dashboardPersons, + loading, + }; +} diff --git a/client/src/fetchHelpers.ts b/client/src/fetchHelpers.ts index f4ca9ec1..bbdd50db 100644 --- a/client/src/fetchHelpers.ts +++ b/client/src/fetchHelpers.ts @@ -20,7 +20,11 @@ export const itFetch = (url: RequestInfo, options: RequestInit) => { }); }; -export const itPost = (url: RequestInfo, data: unknown, options: RequestInit = {}) => { +export const itPost = ( + url: RequestInfo, + data: unknown, + options: RequestInit = {} +) => { options = Object.assign({}, options); const headers = Object.assign( @@ -56,11 +60,11 @@ export const itPost = (url: RequestInfo, data: unknown, options: RequestInit = { return response.json().catch(() => { return Promise.resolve(null); }); - }); + }) as Promise; }; -export const itGet = (url: RequestInfo) => { - return itPost(url, {}, { method: "GET" }); +export const itGet = (url: RequestInfo) => { + return itPost(url, {}, { method: "GET" }); }; export const itDelete = (url: RequestInfo) => { @@ -81,17 +85,17 @@ export function bustItGetCache(key?: string) { } } -export const itGetCached = ( +export const itGetCached = ( url: RequestInfo, options = { reload: false, } -): Promise => { +): Promise => { if (!itGetPromiseCache.has(url.toString()) || options.reload) { - itGetPromiseCache.set(url.toString(), itGet(url)); + itGetPromiseCache.set(url.toString(), itGet(url)); } - return itGetPromiseCache.get(url.toString()) as Promise; + return itGetPromiseCache.get(url.toString()) as Promise; }; export const useCSRFFetch = createFetch({ diff --git a/client/src/pages/dashboard/DashboardPersonsPage.vue b/client/src/pages/dashboard/DashboardPersonsPage.vue new file mode 100644 index 00000000..9cf37ccb --- /dev/null +++ b/client/src/pages/dashboard/DashboardPersonsPage.vue @@ -0,0 +1,22 @@ + + + diff --git a/client/src/router/index.ts b/client/src/router/index.ts index 52a39878..78704b5e 100644 --- a/client/src/router/index.ts +++ b/client/src/router/index.ts @@ -60,6 +60,10 @@ const router = createRouter({ name: "home", component: DashboardPage, }, + { + path: "/dashboard/persons", + component: () => import("@/pages/dashboard/DashboardPersonsPage.vue"), + }, { path: "/course/:courseSlug/media", props: true, diff --git a/client/src/services/dashboard.ts b/client/src/services/dashboard.ts index a320774f..e628b7fe 100644 --- a/client/src/services/dashboard.ts +++ b/client/src/services/dashboard.ts @@ -5,12 +5,37 @@ import { DASHBOARD_COURSE_STATISTICS, } from "@/graphql/queries"; +import { itGetCached } from "@/fetchHelpers"; import type { CourseProgressType, CourseStatisticsType, DashboardConfigType, } from "@/gql/graphql"; +export type DashboardPersonRoleType = + | "SUPERVISOR" + | "EXPERT" + | "MEMBER" + | "LEARNING_MENTOR" + | "LEARNING_MENTEE"; + +export type DashboardPersonCourseSessionType = { + id: number; + session_title: string; + course_id: number; + course_title: string; + user_role: DashboardPersonRoleType; + my_role: DashboardPersonRoleType; +}; + +export type DashboardPersonType = { + user_id: string; + first_name: string; + last_name: string; + email: string; + course_sessions: DashboardPersonCourseSessionType[]; +}; + export const fetchStatisticData = async ( courseId: string ): Promise => { @@ -47,6 +72,7 @@ export const fetchProgressData = async ( return null; } }; + export const fetchDashboardConfig = async (): Promise => { try { const res = await graphqlClient.query(DASHBOARD_CONFIG, {}); @@ -61,3 +87,7 @@ export const fetchDashboardConfig = async (): Promise("/api/dashboard/persons/"); +}