From 18f163768c10f6ff311424231b8e92e641c46457 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Wed, 6 Dec 2023 15:15:50 +0000 Subject: [PATCH 1/4] Made it so, when a user registers with an eCrop e-mail, they get the role of a developer --- src/pages/api/register.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/api/register.ts b/src/pages/api/register.ts index e1607d3d..6a6b26de 100644 --- a/src/pages/api/register.ts +++ b/src/pages/api/register.ts @@ -65,7 +65,7 @@ async function registerIndividual(req: NextApiRequest, res: NextApiResponse) { bio: "", isFirstLogin: codeData ? codeData.type === "student" : true, focus: "academic", - type: codeData ? codeData.type : "student", + type: email.endsWith("@ecrop.dev") ? "developer" : codeData ? codeData.type : "student", subscriptionExpirationDate: codeData ? codeData.expiryDate : moment().subtract(1, "days").toISOString(), registrationDate: new Date(), status: code ? "active" : "paymentDue", From a526e76c70b5d6a6da7105fd8f69d50afa2abad2 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Wed, 6 Dec 2023 16:41:11 +0000 Subject: [PATCH 2/4] Added a feature to allow a user to filter the payment record --- src/pages/payment-record.tsx | 103 ++++++++++++++++++++++++++++++++++- 1 file changed, 102 insertions(+), 1 deletion(-) diff --git a/src/pages/payment-record.tsx b/src/pages/payment-record.tsx index 1831f20e..ee58653b 100644 --- a/src/pages/payment-record.tsx +++ b/src/pages/payment-record.tsx @@ -227,11 +227,47 @@ const PaymentCreator = ({onClose, reload}: {onClose: () => void; reload: () => v export default function PaymentRecord() { const [selectedUser, setSelectedUser] = useState(); const [isCreatingPayment, setIsCreatingPayment] = useState(false); + const [filters, setFilters] = useState<{filter: (p: Payment) => boolean; id: string}[]>([]); + const [displayPayments, setDisplayPayments] = useState([]); + + const [corporate, setCorporate] = useState(); + const [agent, setAgent] = useState(); const {user} = useUser({redirectTo: "/login"}); const {users} = useUsers(); const {payments, reload} = usePayments(); + useEffect(() => { + setDisplayPayments( + filters + .map((f) => f.filter) + .reduce((d, f) => d.filter(f), payments) + .sort((a, b) => moment(b.date).diff(moment(a.date))), + ); + }, [payments, filters]); + + useEffect(() => { + if (user && user.type === "agent") { + setAgent(user); + } + }, [user]); + + useEffect(() => { + setFilters((prev) => [ + ...prev.filter((x) => x.id !== "agent-filter"), + ...(!agent ? [] : [{id: "agent-filter", filter: (p: Payment) => p.agent === agent.id}]), + ]); + }, [agent]); + + useEffect(() => console.log(filters), [filters]); + + useEffect(() => { + setFilters((prev) => [ + ...prev.filter((x) => x.id !== "corporate-filter"), + ...(!corporate ? [] : [{id: "corporate-filter", filter: (p: Payment) => p.corporate === corporate.id}]), + ]); + }, [corporate]); + const updatePayment = (payment: Payment, key: string, value: any) => { axios .patch(`api/payments/${payment.id}`, {...payment, [key]: value}) @@ -339,7 +375,7 @@ export default function PaymentRecord() { ]; const table = useReactTable({ - data: (user?.type === "agent" ? payments.filter((p) => p.agent === user.id) : payments).sort((a, b) => moment(b.date).diff(moment(a.date))), + data: displayPayments, columns: defaultColumns, getCoreRowModel: getCoreRowModel(), }); @@ -387,6 +423,71 @@ export default function PaymentRecord() { )} +
+
+ + u.type === "agent") as AgentUser[]).map((user) => ({ + value: user.id, + meta: user, + label: `${user.name} - ${user.email}`, + }))} + value={agent ? {value: agent?.id, label: `${agent.name} - ${agent.email}`} : undefined} + onChange={(value) => setAgent(value !== null ? (value as any).meta : undefined)} + styles={{ + control: (styles) => ({ + ...styles, + paddingLeft: "4px", + border: "none", + outline: "none", + ":focus": { + outline: "none", + }, + }), + option: (styles, state) => ({ + ...styles, + backgroundColor: state.isFocused ? "#D5D9F0" : state.isSelected ? "#7872BF" : "white", + color: state.isFocused ? "black" : styles.color, + }), + }} + /> +
+
{table.getHeaderGroups().map((headerGroup) => ( From 6f5dd86cd15312caf2c96a5351b67444af3492d8 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Thu, 7 Dec 2023 16:36:57 +0000 Subject: [PATCH 3/4] Updated so the new payment prefills with all of the corporate's payment information --- src/components/UserCard.tsx | 2 +- src/pages/payment-record.tsx | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/UserCard.tsx b/src/components/UserCard.tsx index 682b32d8..76e8a830 100644 --- a/src/components/UserCard.tsx +++ b/src/components/UserCard.tsx @@ -58,7 +58,7 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers, ); const [userAmount, setUserAmount] = useState(user.type === "corporate" ? user.corporateInformation?.companyInformation.userAmount : undefined); const [paymentValue, setPaymentValue] = useState(user.type === "corporate" ? user.corporateInformation?.payment?.value : undefined); - const [paymentCurrency, setPaymentCurrency] = useState(user.type === "corporate" ? user.corporateInformation?.payment?.currency : undefined); + const [paymentCurrency, setPaymentCurrency] = useState(user.type === "corporate" ? user.corporateInformation?.payment?.currency : "EUR"); const [monthlyDuration, setMonthlyDuration] = useState(user.type === "corporate" ? user.corporateInformation?.monthlyDuration : undefined); const {stats} = useStats(user.id); diff --git a/src/pages/payment-record.tsx b/src/pages/payment-record.tsx index ee58653b..70f094d7 100644 --- a/src/pages/payment-record.tsx +++ b/src/pages/payment-record.tsx @@ -75,6 +75,13 @@ const PaymentCreator = ({onClose, reload}: {onClose: () => void; reload: () => v setReferralAgent(referralAgent as AgentUser | undefined); }, [corporate, users]); + useEffect(() => { + const payment = corporate?.corporateInformation?.payment; + + setPrice(payment?.value || 0); + setCurrency(payment?.currency || "EUR"); + }, [corporate]); + const submit = () => { axios .post(`/api/payments`, { @@ -138,14 +145,15 @@ const PaymentCreator = ({onClose, reload}: {onClose: () => void; reload: () => v name="paymentValue" onChange={(e) => setPrice(e ? parseInt(e) : 0)} type="number" - defaultValue={0} + value={price} className="col-span-3" /> +
@@ -159,7 +159,7 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers, type="text" name="commercialRegistration" onChange={setCommercialRegistration} - placeholder="Enter company name" + placeholder="Enter commercial registration" defaultValue={commercialRegistration} required /> @@ -171,11 +171,11 @@ const UserCard = ({user, loggedInUser, onClose, onViewStudents, onViewTeachers, <>
null} - placeholder="Enter company name" + placeholder="Enter corporate name" defaultValue={user.agentInformation.companyName} disabled /> @@ -227,7 +227,7 @@ export default function Home() { type="text" name="commercialRegistration" onChange={() => null} - placeholder="Enter company name" + placeholder="Enter commercial registration" defaultValue={user.agentInformation.commercialRegistration} disabled />