From 72b9e1f11dbbb1b0d71dce3cfd0e64f4dba2b9fd Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Fri, 12 Jan 2024 19:55:46 +0000 Subject: [PATCH 1/4] Added payment done and pending visible to Admin and Developers without filters --- src/dashboards/Admin.tsx | 40 +++++++++++++++++++++++++++++- src/pages/api/payments/assigned.ts | 24 ++++++++++-------- 2 files changed, 53 insertions(+), 11 deletions(-) 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) { From 9e6dc4b4c26d2bb81563266a36f94bf37a2324ff Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Fri, 12 Jan 2024 20:00:31 +0000 Subject: [PATCH 2/4] Reviewed all IconCard for non-matching icons --- src/dashboards/Admin.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dashboards/Admin.tsx b/src/dashboards/Admin.tsx index 8c3019f2..74dc157c 100644 --- a/src/dashboards/Admin.tsx +++ b/src/dashboards/Admin.tsx @@ -265,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))) @@ -275,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" From 580ddfd9e67cd1479d4ebc2dfcea99c307b6cf54 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Fri, 12 Jan 2024 21:27:46 +0000 Subject: [PATCH 3/4] Fixed Pending payment page key --- src/dashboards/Admin.tsx | 2 +- src/dashboards/Agent.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dashboards/Admin.tsx b/src/dashboards/Admin.tsx index 74dc157c..8737cb0b 100644 --- a/src/dashboards/Admin.tsx +++ b/src/dashboards/Admin.tsx @@ -298,7 +298,7 @@ export default function AdminDashboard({user}: Props) { color="purple" /> setPage("paymentdone")} + onClick={() => setPage("paymentpending")} Icon={BsCurrencyDollar} label="Pending Payment" value={pending.length} 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} From 99758d860dd9597c17ed874a0f50b93e7d9a0108 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Sat, 13 Jan 2024 18:54:21 +0000 Subject: [PATCH 4/4] BatchCodeGenerator.tsx edited online with Bitbucket --- src/pages/(admin)/BatchCodeGenerator.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 (
- +