+
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.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.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;
+}