Skip to content

Commit 77a7575

Browse files
committed
feat: scaffold fetching of user receipts
1 parent e920d26 commit 77a7575

File tree

4 files changed

+66
-2
lines changed

4 files changed

+66
-2
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { DashboardReceipts } from "@/components/dashboard/receipts";
2+
import { getCurrentSession } from "@/server/auth";
3+
import { api } from "@/trpc/server";
4+
import { redirect } from "next/navigation";
5+
6+
export default async function ReceiptsPage() {
7+
const { user } = await getCurrentSession();
8+
9+
if (!user) {
10+
redirect("/");
11+
}
12+
13+
const clientPayments = await api.ecommerce.getAllUserReceipts.query();
14+
15+
return <DashboardReceipts initialClientPayments={clientPayments} />;
16+
}

src/components/dashboard-navigation.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ export function DashboardNavigation() {
1414
setActiveTab("pay");
1515
} else if (pathname.includes("/subscriptions")) {
1616
setActiveTab("subscriptions");
17+
} else if (pathname.includes("/receipts")) {
18+
setActiveTab("receipts");
1719
} else {
1820
setActiveTab("get-paid");
1921
}
2022
}, [pathname]);
2123

2224
return (
2325
<Tabs value={activeTab} className="w-full mb-8">
24-
<TabsList className="grid w-full grid-cols-3">
26+
<TabsList className="grid w-full grid-cols-4">
2527
<TabsTrigger value="get-paid" asChild>
2628
<Link href="/dashboard/get-paid">Get Paid</Link>
2729
</TabsTrigger>
@@ -31,6 +33,9 @@ export function DashboardNavigation() {
3133
<TabsTrigger value="subscriptions" asChild>
3234
<Link href="/dashboard/subscriptions">Subscriptions</Link>
3335
</TabsTrigger>
36+
<TabsTrigger value="receipts" asChild>
37+
<Link href="/dashboard/receipts">Receipts</Link>
38+
</TabsTrigger>
3439
</TabsList>
3540
</Tabs>
3641
);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use client";
2+
3+
import type { ClientPayment } from "@/server/db/schema";
4+
5+
interface DashboardReceiptsProps {
6+
initialClientPayments: ClientPayment[];
7+
}
8+
9+
export function DashboardReceipts({
10+
initialClientPayments,
11+
}: DashboardReceiptsProps) {
12+
return (
13+
<div className="space-y-6">
14+
<div>
15+
<h1 className="text-2xl font-semibold">My Receipts</h1>
16+
<p className="text-sm text-muted-foreground">
17+
View all your payment receipts from ecommerce transactions
18+
</p>
19+
</div>
20+
<div className="p-8 bg-zinc-50 rounded-lg text-center">
21+
<p className="text-zinc-600">Receipts component coming soon...</p>
22+
<p className="text-sm text-zinc-500 mt-2">
23+
Found {initialClientPayments.length} payment receipts
24+
</p>
25+
</div>
26+
</div>
27+
);
28+
}

src/server/routers/ecommerce.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
ecommerceClientApiSchema,
66
editecommerceClientApiSchema,
77
} from "@/lib/schemas/ecommerce";
8-
import { and, eq, not } from "drizzle-orm";
8+
import { and, eq, not, sql } from "drizzle-orm";
99
import { ulid } from "ulid";
1010
import { z } from "zod";
1111
import { clientPaymentTable, ecommerceClientTable } from "../db/schema";
@@ -161,4 +161,19 @@ export const ecommerceRouter = router({
161161
throw toTRPCError(error);
162162
}
163163
}),
164+
getAllUserReceipts: protectedProcedure.query(async ({ ctx }) => {
165+
const { db, user } = ctx;
166+
try {
167+
const receipts = await db
168+
.select()
169+
.from(clientPaymentTable)
170+
.where(
171+
sql`${clientPaymentTable.customerInfo}->>'email' = ${user.email}`,
172+
);
173+
174+
return receipts;
175+
} catch (error) {
176+
throw toTRPCError(error);
177+
}
178+
}),
164179
});

0 commit comments

Comments
 (0)