Fix student performance freeze and search users in create entities
TODO: pagination in student performance freeze
This commit is contained in:
@@ -4,7 +4,7 @@ import { useRouter } from "next/router";
|
||||
import { BsChevronLeft } from "react-icons/bs";
|
||||
import { mapBy, serialize } from "@/utils";
|
||||
import { withIronSessionSsr } from "iron-session/next";
|
||||
import { getEntitiesUsers, getUsers } from "@/utils/users.be";
|
||||
import { getUsersWithStats } from "@/utils/users.be";
|
||||
import { sessionOptions } from "@/lib/session";
|
||||
import { checkAccess, findAllowedEntities } from "@/utils/permissions";
|
||||
import { getEntitiesWithRoles } from "@/utils/entities.be";
|
||||
@@ -33,8 +33,32 @@ export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
|
||||
if (allowedEntities.length === 0) return redirect("/");
|
||||
|
||||
const students = await (checkAccess(user, ["admin", "developer"])
|
||||
? getUsers({ type: "student" })
|
||||
: getEntitiesUsers(mapBy(allowedEntities, "id"), { type: "student" }));
|
||||
? getUsersWithStats(
|
||||
{ type: "student" },
|
||||
{
|
||||
id: 1,
|
||||
entities: 1,
|
||||
focus: 1,
|
||||
email: 1,
|
||||
name: 1,
|
||||
levels: 1,
|
||||
userStats: 1,
|
||||
studentID: 1,
|
||||
}
|
||||
)
|
||||
: getUsersWithStats(
|
||||
{ type: "student", "entities.id": { in: mapBy(entities, "id") } },
|
||||
{
|
||||
id: 1,
|
||||
entities: 1,
|
||||
focus: 1,
|
||||
email: 1,
|
||||
name: 1,
|
||||
levels: 1,
|
||||
userStats: 1,
|
||||
studentID: 1,
|
||||
}
|
||||
));
|
||||
const groups = await getParticipantsGroups(mapBy(students, "id"));
|
||||
|
||||
return {
|
||||
@@ -44,14 +68,12 @@ export const getServerSideProps = withIronSessionSsr(async ({ req, res }) => {
|
||||
|
||||
interface Props {
|
||||
user: User;
|
||||
students: StudentUser[];
|
||||
students: (StudentUser & { userStats: Stat[] })[];
|
||||
entities: Entity[];
|
||||
groups: Group[];
|
||||
}
|
||||
|
||||
const StudentPerformance = ({ user, students, entities, groups }: Props) => {
|
||||
const { data: stats } = useFilterRecordsByUser<Stat[]>();
|
||||
|
||||
const StudentPerformance = ({ students, entities, groups }: Props) => {
|
||||
const router = useRouter();
|
||||
|
||||
const performanceStudents = students.map((u) => ({
|
||||
@@ -76,7 +98,6 @@ const StudentPerformance = ({ user, students, entities, groups }: Props) => {
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
<ToastContainer />
|
||||
|
||||
<>
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
@@ -91,7 +112,7 @@ const StudentPerformance = ({ user, students, entities, groups }: Props) => {
|
||||
Student Performance ({students.length})
|
||||
</h2>
|
||||
</div>
|
||||
<StudentPerformanceList items={performanceStudents} stats={stats} />
|
||||
<StudentPerformanceList items={performanceStudents} />
|
||||
</>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user