diff --git a/src/dashboards/Admin.tsx b/src/dashboards/Admin.tsx index c72550b0..8c3019f2 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 ( <> @@ -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("paymentdone")} + 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/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) {