Added search text to Paypal payments
Updated CSV Downlaod Reordered the UI of the page
This commit is contained in:
@@ -37,7 +37,7 @@ import PaymentAssetManager from "@/components/PaymentAssetManager";
|
|||||||
import { toFixedNumber } from "@/utils/number";
|
import { toFixedNumber } from "@/utils/number";
|
||||||
import { CSVLink } from "react-csv";
|
import { CSVLink } from "react-csv";
|
||||||
import { Tab } from "@headlessui/react";
|
import { Tab } from "@headlessui/react";
|
||||||
|
import { useListSearch } from "@/hooks/useListSearch";
|
||||||
export const getServerSideProps = withIronSessionSsr(({ req, res }) => {
|
export const getServerSideProps = withIronSessionSsr(({ req, res }) => {
|
||||||
const user = req.session.user;
|
const user = req.session.user;
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ export const getServerSideProps = withIronSessionSsr(({ req, res }) => {
|
|||||||
}, sessionOptions);
|
}, sessionOptions);
|
||||||
|
|
||||||
const columnHelper = createColumnHelper<Payment>();
|
const columnHelper = createColumnHelper<Payment>();
|
||||||
const paypalColumnHelper = createColumnHelper<PaypalPayment>();
|
const paypalColumnHelper = createColumnHelper<PaypalPaymentWithUserData>();
|
||||||
|
|
||||||
const PaymentCreator = ({
|
const PaymentCreator = ({
|
||||||
onClose,
|
onClose,
|
||||||
@@ -348,7 +348,7 @@ const IS_FILE_SUBMITTED_OPTIONS = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const CSV_WHITELISTED_KEYS = [
|
const CSV_PAYMENTS_WHITELISTED_KEYS = [
|
||||||
"corporateId",
|
"corporateId",
|
||||||
"corporate",
|
"corporate",
|
||||||
"date",
|
"date",
|
||||||
@@ -359,12 +359,28 @@ const CSV_WHITELISTED_KEYS = [
|
|||||||
"isPaid",
|
"isPaid",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const CSV_PAYPAL_WHITELISTED_KEYS = [
|
||||||
|
"orderId",
|
||||||
|
"status",
|
||||||
|
"name",
|
||||||
|
"email",
|
||||||
|
"value",
|
||||||
|
"createdAt",
|
||||||
|
"subscriptionExpirationDate",
|
||||||
|
];
|
||||||
|
|
||||||
interface SimpleCSVColumn {
|
interface SimpleCSVColumn {
|
||||||
key: string;
|
key: string;
|
||||||
label: string;
|
label: string;
|
||||||
index: number;
|
index: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface PaypalPaymentWithUserData extends PaypalPayment {
|
||||||
|
name: string;
|
||||||
|
email: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const paypalFilterRows = [["email"], ["name"]];
|
||||||
export default function PaymentRecord() {
|
export default function PaymentRecord() {
|
||||||
const [selectedCorporateUser, setSelectedCorporateUser] = useState<User>();
|
const [selectedCorporateUser, setSelectedCorporateUser] = useState<User>();
|
||||||
const [selectedAgentUser, setSelectedAgentUser] = useState<User>();
|
const [selectedAgentUser, setSelectedAgentUser] = useState<User>();
|
||||||
@@ -407,6 +423,8 @@ export default function PaymentRecord() {
|
|||||||
});
|
});
|
||||||
}, [originalPayments, startDate, endDate]);
|
}, [originalPayments, startDate, endDate]);
|
||||||
|
|
||||||
|
const [selectedIndex, setSelectedIndex] = useState(0);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setDisplayPayments(
|
setDisplayPayments(
|
||||||
filters
|
filters
|
||||||
@@ -839,6 +857,15 @@ export default function PaymentRecord() {
|
|||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const updatedPaypalPayments = useMemo(
|
||||||
|
() =>
|
||||||
|
paypalPayments.map((p) => {
|
||||||
|
const user = users.find((x) => x.id === p.userId) as User;
|
||||||
|
return { ...p, name: user?.name, email: user?.email };
|
||||||
|
}),
|
||||||
|
[paypalPayments, users]
|
||||||
|
);
|
||||||
|
|
||||||
const paypalColumns = [
|
const paypalColumns = [
|
||||||
paypalColumnHelper.accessor("orderId", {
|
paypalColumnHelper.accessor("orderId", {
|
||||||
header: "Order ID",
|
header: "Order ID",
|
||||||
@@ -856,24 +883,20 @@ export default function PaymentRecord() {
|
|||||||
return <span>{value}</span>;
|
return <span>{value}</span>;
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
paypalColumnHelper.accessor("userId", {
|
paypalColumnHelper.accessor("name", {
|
||||||
header: "User Name",
|
header: "User Name",
|
||||||
id: "name",
|
id: "name",
|
||||||
cell: (info) => {
|
cell: (info) => {
|
||||||
const { value } = columHelperValue("userId", info);
|
const { value } = columHelperValue(info.column.id, info);
|
||||||
|
return <span>{value}</span>;
|
||||||
const user = users.find((x) => x.id === value) as User;
|
|
||||||
return <span>{user?.name}</span>;
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
paypalColumnHelper.accessor("userId", {
|
paypalColumnHelper.accessor("email", {
|
||||||
header: "Email",
|
header: "Email",
|
||||||
id: "email",
|
id: "email",
|
||||||
cell: (info) => {
|
cell: (info) => {
|
||||||
const { value } = columHelperValue("userId", info);
|
const { value } = columHelperValue(info.column.id, info);
|
||||||
|
return <span>{value}</span>;
|
||||||
const user = users.find((x) => x.id === value) as User;
|
|
||||||
return <span>{user?.email}</span>;
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
paypalColumnHelper.accessor("value", {
|
paypalColumnHelper.accessor("value", {
|
||||||
@@ -906,8 +929,13 @@ export default function PaymentRecord() {
|
|||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const { rows: filteredRows, renderSearch } = useListSearch(
|
||||||
|
paypalFilterRows,
|
||||||
|
updatedPaypalPayments
|
||||||
|
);
|
||||||
|
|
||||||
const paypalTable = useReactTable({
|
const paypalTable = useReactTable({
|
||||||
data: paypalPayments,
|
data: filteredRows,
|
||||||
columns: paypalColumns,
|
columns: paypalColumns,
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
});
|
});
|
||||||
@@ -967,11 +995,18 @@ export default function PaymentRecord() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getCSVData = () => {
|
const getCSVData = () => {
|
||||||
const columns = table
|
const tables = [table, paypalTable];
|
||||||
|
const whitelists = [
|
||||||
|
CSV_PAYMENTS_WHITELISTED_KEYS,
|
||||||
|
CSV_PAYPAL_WHITELISTED_KEYS,
|
||||||
|
];
|
||||||
|
const currentTable = tables[selectedIndex];
|
||||||
|
const whitelist = whitelists[selectedIndex];
|
||||||
|
const columns = currentTable
|
||||||
.getHeaderGroups()
|
.getHeaderGroups()
|
||||||
.reduce((accm: SimpleCSVColumn[], group: HeaderGroup<Payment>) => {
|
.reduce((accm: SimpleCSVColumn[], group: HeaderGroup<Payment>) => {
|
||||||
const whitelistedColumns = group.headers.filter((header) =>
|
const whitelistedColumns = group.headers.filter((header) =>
|
||||||
CSV_WHITELISTED_KEYS.includes(header.id)
|
whitelist.includes(header.id)
|
||||||
);
|
);
|
||||||
|
|
||||||
const data = whitelistedColumns.map((data) => ({
|
const data = whitelistedColumns.map((data) => ({
|
||||||
@@ -982,7 +1017,7 @@ export default function PaymentRecord() {
|
|||||||
return [...accm, ...data];
|
return [...accm, ...data];
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const { rows } = table.getRowModel();
|
const { rows } = currentTable.getRowModel();
|
||||||
|
|
||||||
const finalColumns = [
|
const finalColumns = [
|
||||||
...columns,
|
...columns,
|
||||||
@@ -1045,6 +1080,7 @@ export default function PaymentRecord() {
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Head>
|
<Head>
|
||||||
@@ -1099,6 +1135,39 @@ export default function PaymentRecord() {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<Tab.Group selectedIndex={selectedIndex} onChange={setSelectedIndex}>
|
||||||
|
<Tab.List className="flex space-x-1 rounded-xl bg-mti-purple-ultralight/40 p-1">
|
||||||
|
<Tab
|
||||||
|
className={({ selected }) =>
|
||||||
|
clsx(
|
||||||
|
"w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-mti-purple-light",
|
||||||
|
"ring-white ring-opacity-60 ring-offset-2 ring-offset-mti-purple-light focus:outline-none focus:ring-2",
|
||||||
|
"transition duration-300 ease-in-out",
|
||||||
|
selected
|
||||||
|
? "bg-white shadow"
|
||||||
|
: "text-blue-100 hover:bg-white/[0.12] hover:text-mti-purple-dark"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Payments
|
||||||
|
</Tab>
|
||||||
|
<Tab
|
||||||
|
className={({ selected }) =>
|
||||||
|
clsx(
|
||||||
|
"w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-mti-purple-light",
|
||||||
|
"ring-white ring-opacity-60 ring-offset-2 ring-offset-mti-purple-light focus:outline-none focus:ring-2",
|
||||||
|
"transition duration-300 ease-in-out",
|
||||||
|
selected
|
||||||
|
? "bg-white shadow"
|
||||||
|
: "text-blue-100 hover:bg-white/[0.12] hover:text-mti-purple-dark"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Paypal
|
||||||
|
</Tab>
|
||||||
|
</Tab.List>
|
||||||
|
<Tab.Panels>
|
||||||
|
<Tab.Panel className="overflow-y-scroll max-h-[600px] rounded-xl scrollbar-hide gap-8 flex flex-col gap-8">
|
||||||
<div
|
<div
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"grid grid-cols-1 md:grid-cols-2 gap-8 w-full",
|
"grid grid-cols-1 md:grid-cols-2 gap-8 w-full",
|
||||||
@@ -1117,7 +1186,9 @@ export default function PaymentRecord() {
|
|||||||
"!bg-mti-gray-platinum/40 !text-mti-gray-dim !cursor-not-allowed"
|
"!bg-mti-gray-platinum/40 !text-mti-gray-dim !cursor-not-allowed"
|
||||||
)}
|
)}
|
||||||
options={(
|
options={(
|
||||||
users.filter((u) => u.type === "corporate") as CorporateUser[]
|
users.filter(
|
||||||
|
(u) => u.type === "corporate"
|
||||||
|
) as CorporateUser[]
|
||||||
).map((user) => ({
|
).map((user) => ({
|
||||||
value: user.id,
|
value: user.id,
|
||||||
meta: user,
|
meta: user,
|
||||||
@@ -1132,8 +1203,8 @@ export default function PaymentRecord() {
|
|||||||
value: user.id,
|
value: user.id,
|
||||||
meta: user,
|
meta: user,
|
||||||
label: `${
|
label: `${
|
||||||
user.corporateInformation?.companyInformation?.name ||
|
user.corporateInformation?.companyInformation
|
||||||
user.name
|
?.name || user.name
|
||||||
} - ${user.email}`,
|
} - ${user.email}`,
|
||||||
}
|
}
|
||||||
: undefined
|
: undefined
|
||||||
@@ -1196,7 +1267,9 @@ export default function PaymentRecord() {
|
|||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
onChange={(value) =>
|
onChange={(value) =>
|
||||||
setAgent(value !== null ? (value as any).meta : undefined)
|
setAgent(
|
||||||
|
value !== null ? (value as any).meta : undefined
|
||||||
|
)
|
||||||
}
|
}
|
||||||
menuPortalTarget={document?.body}
|
menuPortalTarget={document?.body}
|
||||||
styles={{
|
styles={{
|
||||||
@@ -1231,7 +1304,9 @@ export default function PaymentRecord() {
|
|||||||
isClearable
|
isClearable
|
||||||
className={clsx(
|
className={clsx(
|
||||||
"px-4 py-4 w-full text-sm font-normal placeholder:text-mti-gray-cool disabled:bg-mti-gray-platinum/40 disabled:text-mti-gray-dim disabled:cursor-not-allowed rounded-full border border-mti-gray-platinum focus:outline-none",
|
"px-4 py-4 w-full text-sm font-normal placeholder:text-mti-gray-cool disabled:bg-mti-gray-platinum/40 disabled:text-mti-gray-dim disabled:cursor-not-allowed rounded-full border border-mti-gray-platinum focus:outline-none",
|
||||||
user.type === "agent" ? "bg-mti-gray-platinum/40" : "bg-white"
|
user.type === "agent"
|
||||||
|
? "bg-mti-gray-platinum/40"
|
||||||
|
: "bg-white"
|
||||||
)}
|
)}
|
||||||
options={IS_PAID_OPTIONS}
|
options={IS_PAID_OPTIONS}
|
||||||
value={IS_PAID_OPTIONS.find((e) => e.value === paid)}
|
value={IS_PAID_OPTIONS.find((e) => e.value === paid)}
|
||||||
@@ -1279,7 +1354,9 @@ export default function PaymentRecord() {
|
|||||||
moment(date).isSameOrBefore(moment(new Date()))
|
moment(date).isSameOrBefore(moment(new Date()))
|
||||||
}
|
}
|
||||||
onChange={([initialDate, finalDate]: [Date, Date]) => {
|
onChange={([initialDate, finalDate]: [Date, Date]) => {
|
||||||
setStartDate(initialDate ?? moment("01/01/2023").toDate());
|
setStartDate(
|
||||||
|
initialDate ?? moment("01/01/2023").toDate()
|
||||||
|
);
|
||||||
if (finalDate) {
|
if (finalDate) {
|
||||||
// basicly selecting a final day works as if I'm selecting the first
|
// basicly selecting a final day works as if I'm selecting the first
|
||||||
// minute of that day. this way it covers the whole day
|
// minute of that day. this way it covers the whole day
|
||||||
@@ -1375,43 +1452,11 @@ export default function PaymentRecord() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Tab.Group>
|
|
||||||
<Tab.List className="flex space-x-1 rounded-xl bg-mti-purple-ultralight/40 p-1">
|
|
||||||
<Tab
|
|
||||||
className={({ selected }) =>
|
|
||||||
clsx(
|
|
||||||
"w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-mti-purple-light",
|
|
||||||
"ring-white ring-opacity-60 ring-offset-2 ring-offset-mti-purple-light focus:outline-none focus:ring-2",
|
|
||||||
"transition duration-300 ease-in-out",
|
|
||||||
selected
|
|
||||||
? "bg-white shadow"
|
|
||||||
: "text-blue-100 hover:bg-white/[0.12] hover:text-mti-purple-dark"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Payments
|
|
||||||
</Tab>
|
|
||||||
<Tab
|
|
||||||
className={({ selected }) =>
|
|
||||||
clsx(
|
|
||||||
"w-full rounded-lg py-2.5 text-sm font-medium leading-5 text-mti-purple-light",
|
|
||||||
"ring-white ring-opacity-60 ring-offset-2 ring-offset-mti-purple-light focus:outline-none focus:ring-2",
|
|
||||||
"transition duration-300 ease-in-out",
|
|
||||||
selected
|
|
||||||
? "bg-white shadow"
|
|
||||||
: "text-blue-100 hover:bg-white/[0.12] hover:text-mti-purple-dark"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Paypal
|
|
||||||
</Tab>
|
|
||||||
</Tab.List>
|
|
||||||
<Tab.Panels className="mt-2">
|
|
||||||
<Tab.Panel className="overflow-y-scroll max-h-[600px] rounded-xl scrollbar-hide">
|
|
||||||
{renderTable(table as Table<Payment>)}
|
{renderTable(table as Table<Payment>)}
|
||||||
</Tab.Panel>
|
</Tab.Panel>
|
||||||
<Tab.Panel className="overflow-y-scroll max-h-[600px] rounded-xl scrollbar-hide">
|
<Tab.Panel className="overflow-y-scroll max-h-[600px] rounded-xl scrollbar-hide flex flex-col gap-8">
|
||||||
{renderTable(paypalTable as Table<PaypalPayment>)}
|
{renderSearch()}
|
||||||
|
{renderTable(paypalTable as Table<PaypalPaymentWithUserData>)}
|
||||||
</Tab.Panel>
|
</Tab.Panel>
|
||||||
</Tab.Panels>
|
</Tab.Panels>
|
||||||
</Tab.Group>
|
</Tab.Group>
|
||||||
|
|||||||
Reference in New Issue
Block a user