feat: enhance payment retrieval with flexible query parameters and add dynamic filters to payments page
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 2m18s

This commit is contained in:
2025-07-05 20:39:28 +05:00
parent 5bc8366003
commit fa0d088f7f
4 changed files with 62 additions and 22 deletions

View File

@ -24,13 +24,17 @@ export async function PaymentsTable({
searchParams,
}: {
searchParams: Promise<{
query: string;
page: number;
sortBy: string;
[key: string]: unknown;
}>;
}) {
const query = (await searchParams)?.query || "";
const [error, payments] = await tryCatch(getPayments());
const resolvedParams = await searchParams;
const apiParams: Record<string, string | number | undefined> = {};
for (const [key, value] of Object.entries(resolvedParams)) {
if (value !== undefined && value !== "") {
apiParams[key] = typeof value === "number" ? value : String(value);
}
}
const [error, payments] = await tryCatch(getPayments(apiParams));
if (error) {
if (error.message.includes("Unauthorized")) {
@ -134,18 +138,17 @@ export async function PaymentsTable({
</TableBody>
<TableFooter>
<TableRow>
<TableCell colSpan={2}>
{query.length > 0 && (
<p className="text-sm text-muted-foreground">
Showing {payments?.data?.length} payments for &quot;
{query}
&quot;
<TableCell colSpan={3} className="text-muted-foreground">
{meta?.total === 1 ? (
<p className="text-center">
Total {meta?.total} payment.
</p>
)}
</TableCell>
<TableCell className="text-muted-foreground">
{meta.total} payments
</TableCell>
) : (
<p className="text-center">
Total {meta?.total} payments.
</p>
)} </TableCell>
</TableRow>
</TableFooter>
</Table>