From eab6ab03b70c59dc6edb5be19dc622acd3e365e7 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Sun, 8 Sep 2024 22:46:09 +0100 Subject: [PATCH] Not shown when not completed --- .../MasterCorporate/MasterStatistical.tsx | 59 ++++++++++--------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/dashboards/MasterCorporate/MasterStatistical.tsx b/src/dashboards/MasterCorporate/MasterStatistical.tsx index 46291bec..17d0708c 100644 --- a/src/dashboards/MasterCorporate/MasterStatistical.tsx +++ b/src/dashboards/MasterCorporate/MasterStatistical.tsx @@ -59,7 +59,6 @@ const MasterStatistical = (props: Props) => { const [endDate, setEndDate] = React.useState(moment().endOf("year").toDate()); const {assignments} = useAssignmentsCorporates({ - // corporates: [...corporates, "tYU0HTiJdjMsS8SB7XJsUdMMP892"], corporates: selectedCorporates, startDate, endDate, @@ -69,38 +68,40 @@ const MasterStatistical = (props: Props) => { const tableResults = React.useMemo( () => - assignments.reduce((accmA: TableData[], a: AssignmentWithCorporateId) => { - const userResults = a.assignees.map((assignee) => { - const userStats = a.results.find((r) => r.user === assignee)?.stats || []; - const userData = users.find((u) => u.id === assignee); - const corporate = users.find((u) => u.id === a.assigner)?.name || ""; - const commonData = { - user: userData?.name || "", - email: userData?.email || "", - userId: assignee, - corporateId: a.corporateId, - corporate, - assignment: a.name, - }; - if (userStats.length === 0) { + assignments + .reduce((accmA: TableData[], a: AssignmentWithCorporateId) => { + const userResults = a.assignees.map((assignee) => { + const userStats = a.results.find((r) => r.user === assignee)?.stats || []; + const userData = users.find((u) => u.id === assignee); + const corporate = users.find((u) => u.id === a.assigner)?.name || ""; + const commonData = { + user: userData?.name || "N/A", + email: userData?.email || "N/A", + userId: assignee, + corporateId: a.corporateId, + corporate, + assignment: a.name, + }; + if (userStats.length === 0) { + return { + ...commonData, + correct: 0, + submitted: false, + // date: moment(), + }; + } + return { ...commonData, - correct: 0, - submitted: false, - // date: moment(), + correct: userStats.reduce((n, e) => n + e.score.correct, 0), + submitted: true, + date: moment.max(userStats.map((e) => moment(e.date))), }; - } + }) as TableData[]; - return { - ...commonData, - correct: userStats.reduce((n, e) => n + e.score.correct, 0), - submitted: true, - date: moment.max(userStats.map((e) => moment(e.date))), - }; - }) as TableData[]; - - return [...accmA, ...userResults]; - }, []), + return [...accmA, ...userResults]; + }, []) + .filter((x) => x.user !== "N/A"), [assignments, users], );