Started working on the assignments page
This commit is contained in:
@@ -20,6 +20,7 @@ import {uniqBy} from "lodash";
|
||||
import moment from "moment";
|
||||
import Head from "next/head";
|
||||
import Link from "next/link";
|
||||
import {useRouter} from "next/router";
|
||||
import {useMemo} from "react";
|
||||
import {
|
||||
BsClipboard2Data,
|
||||
@@ -78,6 +79,8 @@ export default function Dashboard({user, users, entities, assignments, stats, gr
|
||||
const students = useMemo(() => users.filter((u) => u.type === "student"), [users]);
|
||||
const teachers = useMemo(() => users.filter((u) => u.type === "teacher"), [users]);
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const averageLevelCalculator = (studentStats: Stat[]) => {
|
||||
const formattedStats = studentStats
|
||||
.map((s) => ({
|
||||
@@ -133,9 +136,27 @@ export default function Dashboard({user, users, entities, assignments, stats, gr
|
||||
</div>
|
||||
)}
|
||||
<section className="grid grid-cols-5 -md:grid-cols-2 place-items-center gap-4 text-center">
|
||||
<IconCard Icon={BsPersonFill} label="Students" value={students.length} color="purple" />
|
||||
<IconCard Icon={BsPencilSquare} label="Teachers" value={teachers.length} color="purple" />
|
||||
<IconCard Icon={BsPeople} label="Classrooms" value={groups.length} color="purple" />
|
||||
<IconCard
|
||||
onClick={() => router.push("/lists/users?type=student")}
|
||||
Icon={BsPersonFill}
|
||||
label="Students"
|
||||
value={students.length}
|
||||
color="purple"
|
||||
/>
|
||||
<IconCard
|
||||
onClick={() => router.push("/lists/users?type=teacher")}
|
||||
Icon={BsPencilSquare}
|
||||
label="Teachers"
|
||||
value={teachers.length}
|
||||
color="purple"
|
||||
/>
|
||||
<IconCard
|
||||
onClick={() => router.push("/classrooms")}
|
||||
Icon={BsPeople}
|
||||
label="Classrooms"
|
||||
value={groups.length}
|
||||
color="purple"
|
||||
/>
|
||||
<IconCard Icon={BsPeopleFill} label="Entities" value={entities.length} color="purple" />
|
||||
<IconCard Icon={BsClipboard2Data} label="Exams Performed" value={uniqBy(stats, "exam").length} color="purple" />
|
||||
<IconCard Icon={BsPaperclip} label="Average Level" value={averageLevelCalculator(stats).toFixed(1)} color="purple" />
|
||||
@@ -56,7 +56,7 @@ export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (!checkAccess(user, ["admin", "developer"]))
|
||||
if (!checkAccess(user, ["developer"]))
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/dashboard",
|
||||
@@ -20,6 +20,7 @@ import {uniqBy} from "lodash";
|
||||
import moment from "moment";
|
||||
import Head from "next/head";
|
||||
import Link from "next/link";
|
||||
import {useRouter} from "next/router";
|
||||
import {useMemo} from "react";
|
||||
import {
|
||||
BsBank,
|
||||
@@ -80,6 +81,8 @@ export default function Dashboard({user, users, entities, assignments, stats, gr
|
||||
const teachers = useMemo(() => users.filter((u) => u.type === "teacher"), [users]);
|
||||
const corporates = useMemo(() => users.filter((u) => u.type === "corporate"), [users]);
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const averageLevelCalculator = (studentStats: Stat[]) => {
|
||||
const formattedStats = studentStats
|
||||
.map((s) => ({
|
||||
@@ -132,7 +135,7 @@ export default function Dashboard({user, users, entities, assignments, stats, gr
|
||||
<IconCard Icon={BsPersonFill} label="Students" value={students.length} color="purple" />
|
||||
<IconCard Icon={BsPencilSquare} label="Teachers" value={teachers.length} color="purple" />
|
||||
<IconCard Icon={BsBank} label="Corporate Accounts" value={corporates.length} color="purple" />
|
||||
<IconCard Icon={BsPeople} label="Classrooms" value={groups.length} color="purple" />
|
||||
<IconCard onClick={() => router.push("/classrooms")} Icon={BsPeople} label="Classrooms" value={groups.length} color="purple" />
|
||||
<IconCard Icon={BsPeopleFill} label="Entities" value={entities.length} color="purple" />
|
||||
<IconCard Icon={BsClipboard2Data} label="Exams Performed" value={uniqBy(stats, "exam").length} color="purple" />
|
||||
<IconCard Icon={BsPaperclip} label="Average Level" value={averageLevelCalculator(stats).toFixed(1)} color="purple" />
|
||||
@@ -17,7 +17,7 @@ import useExamStore from "@/stores/examStore";
|
||||
import {mapBy, serialize} from "@/utils";
|
||||
import {activeAssignmentFilter} from "@/utils/assignments";
|
||||
import {getAssignmentsByAssignee} from "@/utils/assignments.be";
|
||||
import {getEntityWithRoles} from "@/utils/entities.be";
|
||||
import {getEntitiesWithRoles, getEntityWithRoles} from "@/utils/entities.be";
|
||||
import {getExamsByIds} from "@/utils/exams.be";
|
||||
import {getGradingSystemByEntity} from "@/utils/grading.be";
|
||||
import {convertInvitersToUsers, getInvitesByInvitee} from "@/utils/invites.be";
|
||||
@@ -59,7 +59,7 @@ export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
||||
};
|
||||
}
|
||||
|
||||
if (!checkAccess(user, ["admin", "developer", "mastercorporate"]))
|
||||
if (!checkAccess(user, ["admin", "developer", "student"]))
|
||||
return {
|
||||
redirect: {
|
||||
destination: "/dashboard",
|
||||
@@ -68,14 +68,13 @@ export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
||||
};
|
||||
|
||||
const entityIDS = mapBy(user.entities, "id") || [];
|
||||
const entityID = entityIDS.length > 0 ? entityIDS[0] : "";
|
||||
|
||||
const entities = await getEntityWithRoles(entityID);
|
||||
const entities = await getEntitiesWithRoles(entityIDS);
|
||||
const allAssignments = await getAssignmentsByAssignee(user.id, {archived: false});
|
||||
const stats = await getStatsByUser(user.id);
|
||||
const sessions = await getSessionsByUser(user.id, 10);
|
||||
const invites = await getInvitesByInvitee(user.id);
|
||||
const grading = await getGradingSystemByEntity(entityID);
|
||||
const grading = await getGradingSystemByEntity(entityIDS[0] || "");
|
||||
|
||||
const formattedInvites = await Promise.all(invites.map(convertInvitersToUsers));
|
||||
const assignments = allAssignments.filter(activeAssignmentFilter);
|
||||
@@ -17,21 +17,10 @@ import {getStatsByUsers} from "@/utils/stats.be";
|
||||
import {getEntitiesUsers} from "@/utils/users.be";
|
||||
import {withIronSessionSsr} from "iron-session/next";
|
||||
import {uniqBy} from "lodash";
|
||||
import moment from "moment";
|
||||
import Head from "next/head";
|
||||
import Link from "next/link";
|
||||
import {useRouter} from "next/router";
|
||||
import {useMemo} from "react";
|
||||
import {
|
||||
BsClipboard2Data,
|
||||
BsClock,
|
||||
BsEnvelopePaper,
|
||||
BsPaperclip,
|
||||
BsPencilSquare,
|
||||
BsPeople,
|
||||
BsPeopleFill,
|
||||
BsPersonFill,
|
||||
BsPersonFillGear,
|
||||
} from "react-icons/bs";
|
||||
import {BsClipboard2Data, BsEnvelopePaper, BsPaperclip, BsPeople, BsPersonFill} from "react-icons/bs";
|
||||
import {ToastContainer} from "react-toastify";
|
||||
|
||||
interface Props {
|
||||
@@ -76,6 +65,7 @@ export const getServerSideProps = withIronSessionSsr(async ({req, res}) => {
|
||||
|
||||
export default function Dashboard({user, users, entities, assignments, stats, groups}: Props) {
|
||||
const students = useMemo(() => users.filter((u) => u.type === "student"), [users]);
|
||||
const router = useRouter();
|
||||
|
||||
const averageLevelCalculator = (studentStats: Stat[]) => {
|
||||
const formattedStats = studentStats
|
||||
@@ -133,7 +123,13 @@ export default function Dashboard({user, users, entities, assignments, stats, gr
|
||||
)}
|
||||
<section className="grid grid-cols-5 -md:grid-cols-2 place-items-center gap-4 text-center">
|
||||
<IconCard Icon={BsPersonFill} label="Students" value={students.length} color="purple" />
|
||||
<IconCard Icon={BsPeople} label="Classrooms" value={groups.length} color="purple" />
|
||||
<IconCard
|
||||
onClick={() => router.push("/classrooms")}
|
||||
Icon={BsPeople}
|
||||
label="Classrooms"
|
||||
value={groups.length}
|
||||
color="purple"
|
||||
/>
|
||||
<IconCard Icon={BsClipboard2Data} label="Exams Performed" value={uniqBy(stats, "exam").length} color="purple" />
|
||||
<IconCard Icon={BsPaperclip} label="Average Level" value={averageLevelCalculator(stats).toFixed(1)} color="purple" />
|
||||
<IconCard Icon={BsEnvelopePaper} label="Assignments" value={assignments.filter((a) => !a.archived).length} color="purple" />
|
||||
Reference in New Issue
Block a user