-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpricing-table.tsx
42 lines (36 loc) · 1.13 KB
/
pricing-table.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { unitPriceToDollars } from "@/lib/utils";
import { Prisma } from "@prisma/client";
import { StripeButton } from "./stripe-button";
import { db } from "@/lib/db";
import { auth } from "@clerk/nextjs";
import { redirect } from "next/navigation";
interface PricingTableProps {
// For type safety, include the related product reocord
prices: Prisma.PriceGetPayload<{
include: { product: true };
}>[];
}
export const PricingTable = async ({ prices }: PricingTableProps) => {
const { orgId } = auth();
if (!orgId) {
redirect("/select-org");
}
const subscription = await db.subscription.findUnique({
where: {
orgId,
}
})
return (
<div className="flex flex-row gap-4 w-full">
{prices.map((price) => (
<div key={price.id} className="flex flex-col justify-between gap-2 border p-8">
<div>
<div>{price.product.name}</div>
<p className="text-3xl">{unitPriceToDollars(price.unitAmount)}</p>
</div>
<StripeButton priceId={price.id} label={price.id === subscription?.priceId ? "Current" : "Change Plan"} />
</div>
))}
</div>
);
};