diff --git a/src/dashboards/Owner.tsx b/src/dashboards/Owner.tsx index b0c3e679..bd9053e6 100644 --- a/src/dashboards/Owner.tsx +++ b/src/dashboards/Owner.tsx @@ -1,8 +1,10 @@ +/* eslint-disable @next/next/no-img-element */ import ProgressBar from "@/components/Low/ProgressBar"; import ProfileSummary from "@/components/ProfileSummary"; import useStats from "@/hooks/useStats"; import useUsers from "@/hooks/useUsers"; import {User} from "@/interfaces/user"; +import {dateSorter} from "@/utils"; import {MODULE_ARRAY} from "@/utils/moduleUtils"; import {averageScore, groupBySession} from "@/utils/stats"; import {capitalize} from "lodash"; @@ -34,29 +36,29 @@ export default function OwnerDashboard({user}: Props) { return ( <> -
-
+
+
Students {users.filter((x) => x.type === "student").length}
-
+
Teachers {users.filter((x) => x.type === "teacher").length}
-
+
- Corporates + Corporate {users.filter((x) => x.type === "admin").length}
-
+
Countries @@ -65,7 +67,7 @@ export default function OwnerDashboard({user}: Props) {
-
+
Inactive Students @@ -74,16 +76,54 @@ export default function OwnerDashboard({user}: Props) {
-
+
- Inactive Corporates + Inactive Corporate {users.filter((x) => x.type === "admin" && (x.isDisabled || moment().isAfter(x.subscriptionExpirationDate))).length}
+
+
+ Latest students +
+ {users + .filter((x) => x.type === "student") + .sort((a, b) => dateSorter(a, b, "asc", "registrationDate")) + .slice(0, (users.filter((x) => x.type === "student").length - 1) / 2) + .map((x) => ( +
+ {x.name} +
+ {x.name} + {x.email} +
+
+ ))} +
+
+
+ Latest corporate +
+ {users + .filter((x) => x.type === "admin") + .sort((a, b) => dateSorter(a, b, "asc", "registrationDate")) + .slice(0, (users.filter((x) => x.type === "admin").length - 1) / 2) + .map((x) => ( +
+ {x.name} +
+ {x.name} + {x.email} +
+
+ ))} +
+
+
); } diff --git a/src/interfaces/user.ts b/src/interfaces/user.ts index 1b3d783c..e182d457 100644 --- a/src/interfaces/user.ts +++ b/src/interfaces/user.ts @@ -16,6 +16,7 @@ export interface User { demographicInformation?: DemographicInformation; subscriptionExpirationDate?: null | Date; isDisabled?: boolean; + registrationDate?: Date; } export interface DemographicInformation { diff --git a/src/pages/api/register.ts b/src/pages/api/register.ts index 37fb142b..67e5fb45 100644 --- a/src/pages/api/register.ts +++ b/src/pages/api/register.ts @@ -53,6 +53,7 @@ async function login(req: NextApiRequest, res: NextApiResponse) { focus: "academic", type: codeData.type, subscriptionExpirationDate: codeData.expiryDate, + registrationDate: new Date(), }; await setDoc(doc(db, "users", userId), user); diff --git a/src/utils/index.ts b/src/utils/index.ts new file mode 100644 index 00000000..9bdf3dee --- /dev/null +++ b/src/utils/index.ts @@ -0,0 +1,10 @@ +import moment from "moment"; + +export function dateSorter(a: any, b: any, direction: "asc" | "desc", key: string) { + if (!a[key] && b[key]) return direction === "asc" ? -1 : 1; + if (a[key] && !b[key]) return direction === "asc" ? 1 : -1; + if (!a[key] && !b[key]) return 0; + if (moment(a[key]).isAfter(b[key])) return direction === "asc" ? -1 : 1; + if (moment(b[key]).isAfter(a[key])) return direction === "asc" ? 1 : -1; + return 0; +}