From e6528392a281bdb4760f57e95d6f5319565671de Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Sun, 8 Sep 2024 16:06:54 +0100 Subject: [PATCH] Changed the totals of the admin pretty much --- src/dashboards/Admin.tsx | 128 +++++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 59 deletions(-) diff --git a/src/dashboards/Admin.tsx b/src/dashboards/Admin.tsx index e3bc48ce..f2a7af67 100644 --- a/src/dashboards/Admin.tsx +++ b/src/dashboards/Admin.tsx @@ -31,12 +31,40 @@ interface Props { user: User; } +const studentHash = { + type: "student", + size: 25, + orderBy: "registrationDate", +}; + +const teacherHash = { + type: "teacher", + size: 25, + orderBy: "registrationDate", +}; + +const corporateHash = { + type: "corporate", + size: 25, + orderBy: "registrationDate", +}; + +const agentsHash = { + type: "agent", + size: 25, + orderBy: "registrationDate", +}; + export default function AdminDashboard({user}: Props) { const [page, setPage] = useState(""); const [selectedUser, setSelectedUser] = useState(); const [showModal, setShowModal] = useState(false); - const {users, reload, isLoading} = useUsers(); + const {users: students, total: totalStudents, reload: reloadStudents, isLoading: isStudentsLoading} = useUsers(studentHash); + const {users: teachers, total: totalTeachers, reload: reloadTeachers, isLoading: isTeachersLoading} = useUsers(teacherHash); + const {users: corporates, total: totalCorporate, reload: reloadCorporates, isLoading: isCorporatesLoading} = useUsers(corporateHash); + const {users: agents, total: totalAgents, reload: reloadAgents, isLoading: isAgentsLoading} = useUsers(corporateHash); + const {groups} = useGroups({}); const {pending, done} = usePaymentStatusUsers(); @@ -47,9 +75,6 @@ export default function AdminDashboard({user}: Props) { setShowModal(!!selectedUser && router.asPath === "/#"); }, [selectedUser, router.asPath]); - // eslint-disable-next-line react-hooks/exhaustive-deps - useEffect(reload, [page]); - const inactiveCountryManagerFilter = (x: User) => x.status === "disabled" || moment().isAfter(x.subscriptionExpirationDate); const UserDisplay = (displayUser: User) => ( @@ -279,50 +304,50 @@ export default function AdminDashboard({user}: Props) {
x.type === "student").length} + value={totalStudents} onClick={() => router.push("/#students")} color="purple" /> x.type === "teacher").length} + value={totalTeachers} onClick={() => router.push("/#teachers")} color="purple" /> x.type === "corporate").length} + value={totalCorporate} onClick={() => router.push("/#corporate")} color="purple" /> x.type === "agent").length} + value={totalAgents} onClick={() => router.push("/#agents")} color="purple" /> x.demographicInformation).map((x) => x.demographicInformation?.country))].length} + value={[...new Set(agents.filter((x) => x.demographicInformation).map((x) => x.demographicInformation?.country))].length} color="purple" /> router.push("/#inactiveStudents")} Icon={BsPersonFill} - isLoading={isLoading} + isLoading={isStudentsLoading} label="Inactive Students" value={ - users.filter((x) => x.type === "student" && (x.status === "disabled" || moment().isAfter(x.subscriptionExpirationDate))) + students.filter((x) => x.type === "student" && (x.status === "disabled" || moment().isAfter(x.subscriptionExpirationDate))) .length } color="rose" @@ -330,26 +355,26 @@ export default function AdminDashboard({user}: Props) { router.push("/#inactiveCountryManagers")} Icon={BsBriefcaseFill} - isLoading={isLoading} + isLoading={isAgentsLoading} label="Inactive Country Managers" - value={users.filter(inactiveCountryManagerFilter).length} + value={agents.filter(inactiveCountryManagerFilter).length} color="rose" /> router.push("/#inactiveCorporate")} Icon={BsBank} - isLoading={isLoading} + isLoading={isCorporatesLoading} label="Inactive Corporate" value={ - users.filter((x) => x.type === "corporate" && (x.status === "disabled" || moment().isAfter(x.subscriptionExpirationDate))) - .length + corporates.filter( + (x) => x.type === "corporate" && (x.status === "disabled" || moment().isAfter(x.subscriptionExpirationDate)), + ).length } color="rose" /> router.push("/#paymentdone")} Icon={BsCurrencyDollar} - isLoading={isLoading} label="Payment Done" value={done.length} color="purple" @@ -357,7 +382,6 @@ export default function AdminDashboard({user}: Props) { router.push("/#paymentpending")} Icon={BsCurrencyDollar} - isLoading={isLoading} label="Pending Payment" value={pending.length} color="rose" @@ -365,14 +389,13 @@ export default function AdminDashboard({user}: Props) { router.push("https://cms.encoach.com/admin")} Icon={BsLayoutSidebar} - isLoading={isLoading} label="Content Management System (CMS)" color="green" /> router.push("/#corporatestudentslevels")} Icon={BsPersonFill} - isLoading={isLoading} + isLoading={isStudentsLoading} label="Corporate Students Levels" color="purple" /> @@ -382,8 +405,7 @@ export default function AdminDashboard({user}: Props) {
Latest students
- {users - .filter((x) => x.type === "student") + {students .sort((a, b) => dateSorter(a, b, "desc", "registrationDate")) .map((x) => ( @@ -393,8 +415,7 @@ export default function AdminDashboard({user}: Props) {
Latest teachers
- {users - .filter((x) => x.type === "teacher") + {teachers .sort((a, b) => { return dateSorter(a, b, "desc", "registrationDate"); }) @@ -406,8 +427,7 @@ export default function AdminDashboard({user}: Props) {
Latest corporate
- {users - .filter((x) => x.type === "corporate") + {corporates .sort((a, b) => { return dateSorter(a, b, "desc", "registrationDate"); }) @@ -419,8 +439,8 @@ export default function AdminDashboard({user}: Props) {
Unpaid Corporate
- {users - .filter((x) => x.type === "corporate" && x.status === "paymentDue") + {corporates + .filter((x) => x.status === "paymentDue") .map((x) => ( ))} @@ -429,10 +449,9 @@ export default function AdminDashboard({user}: Props) {
Students expiring in 1 month
- {users + {students .filter( (x) => - x.type === "student" && x.subscriptionExpirationDate && moment().isAfter(moment(x.subscriptionExpirationDate).subtract(30, "days")) && moment().isBefore(moment(x.subscriptionExpirationDate)), @@ -445,10 +464,9 @@ export default function AdminDashboard({user}: Props) {
Teachers expiring in 1 month
- {users + {teachers .filter( (x) => - x.type === "teacher" && x.subscriptionExpirationDate && moment().isAfter(moment(x.subscriptionExpirationDate).subtract(30, "days")) && moment().isBefore(moment(x.subscriptionExpirationDate)), @@ -461,10 +479,9 @@ export default function AdminDashboard({user}: Props) {
Country Manager expiring in 1 month
- {users + {agents .filter( (x) => - x.type === "agent" && x.subscriptionExpirationDate && moment().isAfter(moment(x.subscriptionExpirationDate).subtract(30, "days")) && moment().isBefore(moment(x.subscriptionExpirationDate)), @@ -477,10 +494,9 @@ export default function AdminDashboard({user}: Props) {
Corporate expiring in 1 month
- {users + {corporates .filter( (x) => - x.type === "corporate" && x.subscriptionExpirationDate && moment().isAfter(moment(x.subscriptionExpirationDate).subtract(30, "days")) && moment().isBefore(moment(x.subscriptionExpirationDate)), @@ -493,10 +509,8 @@ export default function AdminDashboard({user}: Props) {
Expired Students
- {users - .filter( - (x) => x.type === "student" && x.subscriptionExpirationDate && moment().isAfter(moment(x.subscriptionExpirationDate)), - ) + {students + .filter((x) => x.subscriptionExpirationDate && moment().isAfter(moment(x.subscriptionExpirationDate))) .map((x) => ( ))} @@ -505,10 +519,8 @@ export default function AdminDashboard({user}: Props) {
Expired Teachers
- {users - .filter( - (x) => x.type === "teacher" && x.subscriptionExpirationDate && moment().isAfter(moment(x.subscriptionExpirationDate)), - ) + {teachers + .filter((x) => x.subscriptionExpirationDate && moment().isAfter(moment(x.subscriptionExpirationDate))) .map((x) => ( ))} @@ -517,10 +529,8 @@ export default function AdminDashboard({user}: Props) {
Expired Country Manager
- {users - .filter( - (x) => x.type === "agent" && x.subscriptionExpirationDate && moment().isAfter(moment(x.subscriptionExpirationDate)), - ) + {agents + .filter((x) => x.subscriptionExpirationDate && moment().isAfter(moment(x.subscriptionExpirationDate))) .map((x) => ( ))} @@ -529,11 +539,8 @@ export default function AdminDashboard({user}: Props) {
Expired Corporate
- {users - .filter( - (x) => - x.type === "corporate" && x.subscriptionExpirationDate && moment().isAfter(moment(x.subscriptionExpirationDate)), - ) + {corporates + .filter((x) => x.subscriptionExpirationDate && moment().isAfter(moment(x.subscriptionExpirationDate))) .map((x) => ( ))} @@ -553,7 +560,10 @@ export default function AdminDashboard({user}: Props) { loggedInUser={user} onClose={(shouldReload) => { setSelectedUser(undefined); - if (shouldReload) reload(); + if (shouldReload && selectedUser!.type === "student") reloadStudents(); + if (shouldReload && selectedUser!.type === "teacher") reloadTeachers(); + if (shouldReload && selectedUser!.type === "corporate") reloadCorporates(); + if (shouldReload && selectedUser!.type === "agent") reloadAgents(); }} onViewStudents={ selectedUser.type === "corporate" || selectedUser.type === "teacher"