diff --git a/src/dashboards/Admin.tsx b/src/dashboards/Admin.tsx index c72550b0..8737cb0b 100644 --- a/src/dashboards/Admin.tsx +++ b/src/dashboards/Admin.tsx @@ -7,12 +7,13 @@ import UserList from "@/pages/(admin)/Lists/UserList"; import {dateSorter} from "@/utils"; import moment from "moment"; import {useEffect, useState} from "react"; -import {BsArrowLeft, BsBriefcaseFill, BsGlobeCentralSouthAsia, BsPerson, BsPersonFill, BsPencilSquare, BsBank} from "react-icons/bs"; +import {BsArrowLeft, BsBriefcaseFill, BsGlobeCentralSouthAsia, BsPerson, BsPersonFill, BsPencilSquare, BsBank, BsCurrencyDollar} from "react-icons/bs"; import UserCard from "@/components/UserCard"; import useGroups from "@/hooks/useGroups"; import IconCard from "./IconCard"; import useFilterStore from "@/stores/listFilterStore"; import {useRouter} from "next/router"; +import usePaymentStatusUsers from '@/hooks/usePaymentStatusUsers'; interface Props { user: User; @@ -26,6 +27,7 @@ export default function AdminDashboard({user}: Props) { const {stats} = useStats(user.id); const {users, reload} = useUsers(); const {groups} = useGroups(); + const { pending, done } = usePaymentStatusUsers(); const appendUserFilters = useFilterStore((state) => state.appendUserFilter); const router = useRouter(); @@ -146,6 +148,26 @@ export default function AdminDashboard({user}: Props) { ); + const CorporatePaidStatusList = ({ paid }: {paid: Boolean}) => { + const list = paid ? done : pending; + const filter = (x: User) => x.type === "corporate" && list.includes(x.id); + + return ( + <> +
+
setPage("")} + className="flex gap-2 items-center text-mti-purple-light cursor-pointer hover:text-mti-purple-dark transition ease-in-out duration-300"> + + Back +
+

{paid ? 'Payment Done' : 'Pending Payment'} ({list.length})

+
+ + + ); + }; + const InactiveCountryManagerList = () => { return ( <> @@ -243,7 +265,7 @@ export default function AdminDashboard({user}: Props) { /> setPage("inactiveStudents")} - Icon={BsPerson} + Icon={BsPersonFill} label="Inactive Students" value={ users.filter((x) => x.type === "student" && (x.status === "disabled" || moment().isAfter(x.subscriptionExpirationDate))) @@ -253,7 +275,7 @@ export default function AdminDashboard({user}: Props) { /> setPage("inactiveCountryManagers")} - Icon={BsPerson} + Icon={BsBriefcaseFill} label="Inactive Country Managers" value={users.filter(inactiveCountryManagerFilter).length} color="rose" @@ -268,6 +290,20 @@ export default function AdminDashboard({user}: Props) { } color="rose" /> + setPage("paymentdone")} + Icon={BsCurrencyDollar} + label="Payment Done" + value={done.length} + color="purple" + /> + setPage("paymentpending")} + Icon={BsCurrencyDollar} + label="Pending Payment" + value={pending.length} + color="rose" + />
@@ -477,6 +513,8 @@ export default function AdminDashboard({user}: Props) { {page === "inactiveStudents" && } {page === "inactiveCorporate" && } {page === "inactiveCountryManagers" && } + {page === "paymentdone" && } + {page === "paymentpending" && } {page === "" && } ); diff --git a/src/dashboards/Agent.tsx b/src/dashboards/Agent.tsx index b32158c4..88148158 100644 --- a/src/dashboards/Agent.tsx +++ b/src/dashboards/Agent.tsx @@ -161,7 +161,7 @@ export default function AgentDashboard({user}: Props) { color="purple" /> setPage("paymentdone")} + onClick={() => setPage("paymentpending")} Icon={BsCurrencyDollar} label="Pending Payment" value={pending.length} diff --git a/src/pages/(admin)/BatchCodeGenerator.tsx b/src/pages/(admin)/BatchCodeGenerator.tsx index 5a0ba531..e4988a15 100644 --- a/src/pages/(admin)/BatchCodeGenerator.tsx +++ b/src/pages/(admin)/BatchCodeGenerator.tsx @@ -103,7 +103,7 @@ export default function BatchCodeGenerator({user}: {user: User}) { return (
- + diff --git a/src/pages/api/payments/assigned.ts b/src/pages/api/payments/assigned.ts index 107e619e..d15de946 100644 --- a/src/pages/api/payments/assigned.ts +++ b/src/pages/api/payments/assigned.ts @@ -30,16 +30,20 @@ async function get(req: NextApiRequest, res: NextApiResponse) { return; } - const codeQuery = query( - collection(db, "payments"), - // where("agent", "==", "xRMirufz6PPQqxKBgvPTWiWKBD63"), - where(req.session.user.type, "==", req.session.user.id) - // Based on the logic of query we should be able to do this: - // where("isPaid", "==", paid === "paid"), - // but for some reason it is ignoring all but the first clause - // I opted into only fetching relevant content for the user - // and then filter it with JS - ); + // if it's an admin, don't apply query filters + const whereClauses = ["admin", "developer"].includes(req.session.user.type) + ? [] + : [ + // where("agent", "==", "xRMirufz6PPQqxKBgvPTWiWKBD63"), + where(req.session.user.type, "==", req.session.user.id), + // Based on the logic of query we should be able to do this: + // where("isPaid", "==", paid === "paid"), + // but for some reason it is ignoring all but the first clause + // I opted into only fetching relevant content for the user + // and then filter it with JS + ]; + + const codeQuery = query(collection(db, "payments"), ...whereClauses); const snapshot = await getDocs(codeQuery); if (snapshot.empty) {