Merged in ENCOA-200_StatisticalCorporate (pull request #97)
ENCOA-200: Added Master Statistical to Corporate Approved-by: Tiago Ribeiro
This commit is contained in:
@@ -26,6 +26,7 @@ import {
|
||||
BsArrowRepeat,
|
||||
BsPlus,
|
||||
BsEnvelopePaper,
|
||||
BsDatabase,
|
||||
} from "react-icons/bs";
|
||||
import UserCard from "@/components/UserCard";
|
||||
import useGroups from "@/hooks/useGroups";
|
||||
@@ -52,7 +53,7 @@ import {getUserCompanyName} from "@/resources/user";
|
||||
import {futureAssignmentFilter, pastAssignmentFilter, archivedAssignmentFilter, activeAssignmentFilter} from "@/utils/assignments";
|
||||
import useUserBalance from "@/hooks/useUserBalance";
|
||||
import AssignmentsPage from "./views/AssignmentsPage";
|
||||
|
||||
import MasterStatistical from "./MasterStatistical";
|
||||
interface Props {
|
||||
user: CorporateUser;
|
||||
linkedCorporate?: CorporateUser | MasterCorporateUser;
|
||||
@@ -278,6 +279,30 @@ export default function CorporateDashboard({user, linkedCorporate}: Props) {
|
||||
return calculateAverageLevel(levels);
|
||||
};
|
||||
|
||||
// this workaround will allow us toreuse the master statistical due to master corporate restraints
|
||||
// while still being able to use the corporate user
|
||||
const groupedByNameCorporateIds = useMemo(() => ({
|
||||
[user.corporateInformation?.companyInformation?.name || user.name]: [user.id],
|
||||
}), [user]);
|
||||
|
||||
const teachersAndStudents = useMemo(() => [...students, ...teachers], [students, teachers]);
|
||||
const MasterStatisticalPage = () => {
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col gap-4">
|
||||
<div
|
||||
onClick={() => router.push("/")}
|
||||
className="flex gap-2 items-center text-mti-purple-light cursor-pointer hover:text-mti-purple-dark transition ease-in-out duration-300">
|
||||
<BsArrowLeft className="text-xl" />
|
||||
<span>Back</span>
|
||||
</div>
|
||||
<h2 className="text-2xl font-semibold">Master Statistical</h2>
|
||||
</div>
|
||||
<MasterStatistical users={teachersAndStudents} corporateUsers={groupedByNameCorporateIds} displaySelection={false} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const DefaultDashboard = () => (
|
||||
<>
|
||||
{!!linkedCorporate && (
|
||||
@@ -336,6 +361,12 @@ export default function CorporateDashboard({user, linkedCorporate}: Props) {
|
||||
color="purple"
|
||||
onClick={() => router.push("/#studentsPerformance")}
|
||||
/>
|
||||
<IconCard
|
||||
Icon={BsDatabase}
|
||||
label="Master Statistical"
|
||||
color="purple"
|
||||
onClick={() => router.push("/#statistical")}
|
||||
/>
|
||||
<button
|
||||
disabled={isAssignmentsLoading}
|
||||
onClick={() => router.push("/#assignments")}
|
||||
@@ -504,6 +535,7 @@ export default function CorporateDashboard({user, linkedCorporate}: Props) {
|
||||
/>
|
||||
)}
|
||||
{router.asPath === "/#studentsPerformance" && <StudentPerformancePage />}
|
||||
{router.asPath === "/#statistical" && <MasterStatisticalPage />}
|
||||
{router.asPath === "/" && <DefaultDashboard />}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -500,7 +500,6 @@ export default function MasterCorporateDashboard({user}: Props) {
|
||||
<IconCard
|
||||
Icon={BsDatabase}
|
||||
label="Master Statistical"
|
||||
// value={masterCorporateUserGroups.length}
|
||||
color="purple"
|
||||
onClick={() => router.push("/#statistical")}
|
||||
/>
|
||||
|
||||
@@ -28,6 +28,7 @@ interface GroupedCorporateUsers {
|
||||
interface Props {
|
||||
corporateUsers: GroupedCorporateUsers;
|
||||
users: User[];
|
||||
displaySelection?: boolean;
|
||||
}
|
||||
|
||||
interface TableData {
|
||||
@@ -49,7 +50,7 @@ interface UserCount {
|
||||
const searchFilters = [["email"], ["user"], ["userId"]];
|
||||
|
||||
const MasterStatistical = (props: Props) => {
|
||||
const { users, corporateUsers } = props;
|
||||
const { users, corporateUsers, displaySelection = true } = props;
|
||||
|
||||
// const corporateRelevantUsers = React.useMemo(
|
||||
// () => corporateUsers.filter((x) => x.type !== "student") as CorporateUser[],
|
||||
@@ -173,6 +174,8 @@ const MasterStatistical = (props: Props) => {
|
||||
return <span>{info.getValue()}</span>;
|
||||
},
|
||||
}),
|
||||
...(displaySelection
|
||||
? [
|
||||
columnHelper.accessor("corporate", {
|
||||
header: "Corporate",
|
||||
id: "corporate",
|
||||
@@ -180,6 +183,8 @@ const MasterStatistical = (props: Props) => {
|
||||
return <span>{info.getValue()}</span>;
|
||||
},
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
columnHelper.accessor("assignment", {
|
||||
header: "Assignment",
|
||||
id: "assignment",
|
||||
@@ -261,6 +266,7 @@ const MasterStatistical = (props: Props) => {
|
||||
...(startDate ? { startDate: startDate.toISOString() } : {}),
|
||||
...(endDate ? { endDate: endDate.toISOString() } : {}),
|
||||
searchText,
|
||||
displaySelection,
|
||||
});
|
||||
toast.success("Report ready!");
|
||||
const link = document.createElement("a");
|
||||
@@ -282,6 +288,7 @@ const MasterStatistical = (props: Props) => {
|
||||
const consolidateResults = getStudentsConsolidateScore();
|
||||
return (
|
||||
<>
|
||||
{displaySelection && (
|
||||
<div className="flex flex-wrap gap-2 items-center text-center">
|
||||
<IconCard
|
||||
Icon={BsBank}
|
||||
@@ -304,7 +311,9 @@ const MasterStatistical = (props: Props) => {
|
||||
);
|
||||
|
||||
const valueHash = getCorporatesScoresHash(group);
|
||||
const value = getConsolidateScoreStr(getConsolidateScore(valueHash));
|
||||
const value = getConsolidateScoreStr(
|
||||
getConsolidateScore(valueHash)
|
||||
);
|
||||
return (
|
||||
<IconCard
|
||||
key={corporateName}
|
||||
@@ -328,6 +337,7 @@ const MasterStatistical = (props: Props) => {
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
<div className="flex gap-3 w-full">
|
||||
<div className="flex flex-col gap-3">
|
||||
<label className="font-normal text-base text-mti-gray-dim">
|
||||
|
||||
@@ -49,15 +49,22 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
// verify if it's a logged user that is trying to export
|
||||
if (req.session.user) {
|
||||
if (
|
||||
!checkAccess(req.session.user, ["mastercorporate", "developer", "admin"])
|
||||
!checkAccess(req.session.user, ["mastercorporate", "corporate", "developer", "admin"])
|
||||
) {
|
||||
return res.status(401).json({ error: "Unauthorized" });
|
||||
return res.status(403).json({ error: "Unauthorized" });
|
||||
}
|
||||
const { ids, startDate, endDate, searchText } = req.body as {
|
||||
const {
|
||||
ids,
|
||||
startDate,
|
||||
endDate,
|
||||
searchText,
|
||||
displaySelection = true,
|
||||
} = req.body as {
|
||||
ids: string[];
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
searchText: string;
|
||||
displaySelection?: boolean;
|
||||
};
|
||||
const startDateParsed = startDate ? new Date(startDate) : undefined;
|
||||
const endDateParsed = endDate ? new Date(endDate) : undefined;
|
||||
@@ -83,7 +90,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
);
|
||||
|
||||
const getGradingSystemHelper = (
|
||||
exams: {id: string; module: Module; assignee: string}[],
|
||||
exams: { id: string; module: Module; assignee: string }[],
|
||||
assigner: string,
|
||||
user: User,
|
||||
correct: number,
|
||||
@@ -100,15 +107,18 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
"level",
|
||||
user.focus
|
||||
);
|
||||
return { label: getGradingLabel(bandScore, gradingSystem?.steps || []), score: bandScore };
|
||||
return {
|
||||
label: getGradingLabel(bandScore, gradingSystem?.steps || []),
|
||||
score: bandScore,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return { score: -1, label: "N/A" };
|
||||
};
|
||||
|
||||
const tableResults = assignments.reduce(
|
||||
(accmA: TableData[], a: AssignmentWithCorporateId) => {
|
||||
const tableResults = assignments
|
||||
.reduce((accmA: TableData[], a: AssignmentWithCorporateId) => {
|
||||
const userResults = a.assignees.map((assignee) => {
|
||||
const userStats =
|
||||
a.results.find((r) => r.user === assignee)?.stats || [];
|
||||
@@ -124,7 +134,6 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
total
|
||||
);
|
||||
|
||||
|
||||
console.log("Level", level);
|
||||
const commonData = {
|
||||
user: userData?.name || "",
|
||||
@@ -145,12 +154,14 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
};
|
||||
}
|
||||
|
||||
const partsData = userStats.every((e) => e.module === "level") ? userStats.reduce((acc, e, index) => {
|
||||
const partsData = userStats.every((e) => e.module === "level")
|
||||
? userStats.reduce((acc, e, index) => {
|
||||
return {
|
||||
...acc,
|
||||
[`part${index}`]: `${e.score.correct}/${e.score.total}`
|
||||
}
|
||||
}, {}) : {};
|
||||
[`part${index}`]: `${e.score.correct}/${e.score.total}`,
|
||||
};
|
||||
}, {})
|
||||
: {};
|
||||
|
||||
return {
|
||||
...commonData,
|
||||
@@ -162,9 +173,8 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
}) as TableData[];
|
||||
|
||||
return [...accmA, ...userResults];
|
||||
},
|
||||
[]
|
||||
).sort((a,b) => b.score - a.score);
|
||||
}, [])
|
||||
.sort((a, b) => b.score - a.score);
|
||||
|
||||
// Create a new workbook and add a worksheet
|
||||
const workbook = new ExcelJS.Workbook();
|
||||
@@ -179,10 +189,14 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
|
||||
label: "Email",
|
||||
value: (entry: TableData) => entry.email,
|
||||
},
|
||||
...(displaySelection
|
||||
? [
|
||||
{
|
||||
label: "Corporate",
|
||||
value: (entry: TableData) => entry.corporate,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
label: "Assignment",
|
||||
value: (entry: TableData) => entry.assignment,
|
||||
|
||||
Reference in New Issue
Block a user