ENCOA-26: Student profile count stats was invalid
This commit is contained in:
@@ -35,7 +35,7 @@ interface Props {
|
|||||||
export default function StudentDashboard({user}: Props) {
|
export default function StudentDashboard({user}: Props) {
|
||||||
const [corporateUserToShow, setCorporateUserToShow] = useState<CorporateUser>();
|
const [corporateUserToShow, setCorporateUserToShow] = useState<CorporateUser>();
|
||||||
|
|
||||||
const {stats} = useStats(user.id);
|
const {stats} = useStats(user.id, !user?.id);
|
||||||
const {users} = useUsers();
|
const {users} = useUsers();
|
||||||
const {assignments, isLoading: isAssignmentsLoading, reload: reloadAssignments} = useAssignments({assignees: user?.id});
|
const {assignments, isLoading: isAssignmentsLoading, reload: reloadAssignments} = useAssignments({assignees: user?.id});
|
||||||
const {invites, isLoading: isInvitesLoading, reload: reloadInvites} = useInvites({to: user.id});
|
const {invites, isLoading: isInvitesLoading, reload: reloadInvites} = useInvites({to: user.id});
|
||||||
|
|||||||
@@ -2,18 +2,22 @@ import {Stat, User} from "@/interfaces/user";
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
|
|
||||||
export default function useStats(id?: string) {
|
export default function useStats(id?: string, shouldNotQuery?: boolean) {
|
||||||
const [stats, setStats] = useState<Stat[]>([]);
|
const [stats, setStats] = useState<Stat[]>([]);
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [isError, setIsError] = useState(false);
|
const [isError, setIsError] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
const getData = () => {
|
||||||
|
if (shouldNotQuery) return;
|
||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
axios
|
axios
|
||||||
.get<Stat[]>(!id ? "/api/stats" : `/api/stats/user/${id}`)
|
.get<Stat[]>(!id ? "/api/stats" : `/api/stats/user/${id}`)
|
||||||
.then((response) => setStats(response.data))
|
.then((response) => setStats(response.data.filter((x) => (id ? x.user === id : true))))
|
||||||
.finally(() => setIsLoading(false));
|
.finally(() => setIsLoading(false));
|
||||||
}, [id]);
|
};
|
||||||
|
|
||||||
return {stats, isLoading, isError};
|
useEffect(getData, [id, shouldNotQuery]);
|
||||||
|
|
||||||
|
return {stats, reload: getData, isLoading, isError};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,8 +72,7 @@ export default function Stats() {
|
|||||||
const {user} = useUser({redirectTo: "/login"});
|
const {user} = useUser({redirectTo: "/login"});
|
||||||
const {users} = useUsers();
|
const {users} = useUsers();
|
||||||
const {groups} = useGroups(user?.id);
|
const {groups} = useGroups(user?.id);
|
||||||
const {stats} = useStats(statsUserId);
|
const {stats} = useStats(statsUserId, !statsUserId);
|
||||||
const {stats: userStats} = useStats(user?.id);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (user) setStatsUserId(user.id);
|
if (user) setStatsUserId(user.id);
|
||||||
@@ -160,23 +159,23 @@ export default function Stats() {
|
|||||||
{user && (
|
{user && (
|
||||||
<Layout user={user} className="gap-8">
|
<Layout user={user} className="gap-8">
|
||||||
<ProfileSummary
|
<ProfileSummary
|
||||||
user={user}
|
user={users.find((x) => x.id === statsUserId) || user}
|
||||||
items={[
|
items={[
|
||||||
{
|
{
|
||||||
icon: <BsFileEarmarkText className="w-6 h-6 md:w-8 md:h-8 text-mti-red-light" />,
|
icon: <BsFileEarmarkText className="w-6 h-6 md:w-8 md:h-8 text-mti-red-light" />,
|
||||||
value: countFullExams(userStats),
|
value: countFullExams(stats),
|
||||||
label: "Exams",
|
label: "Exams",
|
||||||
tooltip: "Number of all conducted completed exams",
|
tooltip: "Number of all conducted completed exams",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: <BsPencil className="w-6 h-6 md:w-8 md:h-8 text-mti-red-light" />,
|
icon: <BsPencil className="w-6 h-6 md:w-8 md:h-8 text-mti-red-light" />,
|
||||||
value: countExamModules(userStats),
|
value: countExamModules(stats),
|
||||||
label: "Modules",
|
label: "Modules",
|
||||||
tooltip: "Number of all exam modules performed including Level Test",
|
tooltip: "Number of all exam modules performed including Level Test",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
icon: <BsStar className="w-6 h-6 md:w-8 md:h-8 text-mti-red-light" />,
|
icon: <BsStar className="w-6 h-6 md:w-8 md:h-8 text-mti-red-light" />,
|
||||||
value: `${userStats.length > 0 ? averageScore(userStats) : 0}%`,
|
value: `${stats.length > 0 ? averageScore(stats) : 0}%`,
|
||||||
label: "Average Score",
|
label: "Average Score",
|
||||||
tooltip: "Average success rate for questions responded",
|
tooltip: "Average success rate for questions responded",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export const countFullExams = (stats: Stat[]) => {
|
|||||||
const sessionExams = groupBySession(stats);
|
const sessionExams = groupBySession(stats);
|
||||||
return Object.keys(sessionExams).filter((x) => {
|
return Object.keys(sessionExams).filter((x) => {
|
||||||
const sessionStats = sessionExams[x as keyof typeof sessionExams];
|
const sessionStats = sessionExams[x as keyof typeof sessionExams];
|
||||||
const sessionModules = uniq(sessionStats.map((x) => x.module));
|
const sessionModules = sessionStats.map((x) => x.module);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
sessionModules.includes("reading") &&
|
sessionModules.includes("reading") &&
|
||||||
|
|||||||
Reference in New Issue
Block a user