From 71d2f597506dbb35bb699eb8c1c485b89f5e3a71 Mon Sep 17 00:00:00 2001 From: Primakov Alexandr Alexandrovich Date: Sun, 15 Dec 2024 20:35:39 +0300 Subject: [PATCH] teachers in Attendance --- src/__data__/model.ts | 7 +++++++ src/pages/attendance/attendance.tsx | 28 +++++++++++++++++++++++++++ stubs/mocks/lessons/list/success.json | 7 +++++++ 3 files changed, 42 insertions(+) diff --git a/src/__data__/model.ts b/src/__data__/model.ts index e554a01..f6af58c 100644 --- a/src/__data__/model.ts +++ b/src/__data__/model.ts @@ -53,10 +53,17 @@ export interface Lesson { id: string; name: string; students: User[]; + teachers: Teacher[]; date: string; created: string; } +interface Teacher { + sub: string; + email_verified: boolean; + preferred_username: string; +} + export interface AccessCode { expires: string; lesson: Lesson; diff --git a/src/pages/attendance/attendance.tsx b/src/pages/attendance/attendance.tsx index ee0d854..482419e 100644 --- a/src/pages/attendance/attendance.tsx +++ b/src/pages/attendance/attendance.tsx @@ -21,8 +21,15 @@ export const Attendance = () => { if (!attendance) return null const studentsMap = new Map() + const teachersMap = new Map() attendance.forEach((lesson) => { + lesson.teachers?.map((teacher: any) => { + teachersMap.set(teacher.sub, { id: teacher.sub, ...teacher, value: teacher.value || (teacher.family_name && teacher.given_name + ? `${teacher.family_name} ${teacher.given_name}` + : teacher.name || teacher.email || teacher.preferred_username || teacher.family_name || teacher.given_name), }) + }) + lesson.students.forEach((student) => { const current = studentsMap.get(student.sub) || {} @@ -39,11 +46,13 @@ export const Attendance = () => { const compare = Intl.Collator('ru').compare const students = [...studentsMap.values()] + const taechers = [...teachersMap.values()] students.sort(({ family_name: name }, { family_name: nname }) => compare(name, nname), ) return { students, + taechers, } }, [attendance]) @@ -60,6 +69,9 @@ export const Attendance = () => { + {data.taechers.map(teacher => ( + + ))} {data.students.map((student) => ( @@ -70,6 +82,22 @@ export const Attendance = () => { {attendance.map((lesson, index) => ( + {data?.taechers?.map((teacher) => { + + const wasThere = Boolean(lesson.teachers) && + lesson?.teachers?.findIndex((u) => u.sub === teacher.sub) !== -1 + return ( + + ) + })} diff --git a/stubs/mocks/lessons/list/success.json b/stubs/mocks/lessons/list/success.json index 19cad60..7430e2a 100644 --- a/stubs/mocks/lessons/list/success.json +++ b/stubs/mocks/lessons/list/success.json @@ -4,6 +4,13 @@ { "_id": "65e2e5fbec37fec650f28489", "name": "ВВЕДЕНИЕ В ВЕБ-РАЗРАБОТКУ. ИНСТРУМЕНТАРИЙ, ОБЗОР ВЕБ-ТЕХНОЛОГИЙ", + "teachers": [ + { + "sub": "f62905b1-e223-40ca-910f-c8d84c6137c1", + "email_verified": true, + "preferred_username": "primakov" + } + ], "students": [ { "sub": "fcde3f22-d9ba-412a-a572-c59e515a290f",
{teacher.value}Дата Название занятия
+ {wasThere ? '+' : '-'} + {dayjs(lesson.date).format('DD.MM.YYYY')} {}