-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.tsx
More file actions
145 lines (137 loc) · 5.55 KB
/
Copy pathpage.tsx
File metadata and controls
145 lines (137 loc) · 5.55 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { Suspense } from "react";
import { createClient } from "@/utils/supabase/server";
import { signout } from "@/app/login/actions";
import { getSubscriptionDetails } from "@/lib/stripe";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { CheckoutButton } from "@/components/subscribe-button";
const SUBSCRIPTION_PRICE_ID = process.env.STRIPE_PRICE_ID!;
const PRODUCT_PRICE_ID = process.env.STRIPE_PRODUCT_PRICE_ID!;
export default function Page() {
return (
<Suspense>
<HomeContent />
</Suspense>
);
}
async function HomeContent() {
const supabase = await createClient();
const {
data: { user },
} = await supabase.auth.getUser();
if (!user) return null;
const [subscription] = await Promise.all([getSubscriptionDetails(user.id)]);
const ownsProduct = false;
return (
<main className="min-h-screen p-4 w-full">
<div className="flex flex-row gap-4 w-full">
<Card className="flex-1">
<CardHeader>
<CardTitle className="text-2xl">Welcome t</CardTitle>
<CardDescription>You are signed in as</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<p className="text-sm font-medium">{user.email}</p>
<form>
<Button formAction={signout} variant="outline">
Sign out
</Button>
</form>
</CardContent>
</Card>
<Card className="flex-1">
<CardHeader>
<CardTitle>Subscription</CardTitle>
<CardDescription>
{subscription
? "Your current plan"
: "Subscribe to unlock premium features"}
</CardDescription>
</CardHeader>
<CardContent>
{subscription ? (
<div className="space-y-3">
<div className="flex items-center justify-between">
<span className="text-sm text-gray-500">Plan</span>
<span className="text-sm font-medium">
{subscription.planName}
</span>
</div>
<div className="flex items-center justify-between">
<span className="text-sm text-gray-500">Price</span>
<span className="text-sm font-medium">
${(subscription.priceAmount / 100).toFixed(2)}/
{subscription.priceInterval}
</span>
</div>
<div className="flex items-center justify-between">
<span className="text-sm text-gray-500">Status</span>
<div className="flex items-center gap-1.5">
<span className="h-2 w-2 rounded-full bg-green-500" />
<span className="text-sm font-medium text-green-700">
Active
</span>
</div>
</div>
{subscription.paymentMethodBrand && (
<div className="flex items-center justify-between">
<span className="text-sm text-gray-500">
Payment
</span>
<span className="text-sm font-medium capitalize">
{subscription.paymentMethodBrand} ****
{subscription.paymentMethodLast4}
</span>
</div>
)}
{subscription.cancelAtPeriodEnd && (
<p className="text-sm text-amber-600">
Cancels at end of billing period
</p>
)}
</div>
) : (
<CheckoutButton
priceId={SUBSCRIPTION_PRICE_ID}
mode="subscription"
label="Subscribe"
/>
)}
</CardContent>
</Card>
<Card className="flex-1">
<CardHeader>
<CardTitle>Product</CardTitle>
<CardDescription>
{ownsProduct
? "You own this product"
: "One-time purchase"}
</CardDescription>
</CardHeader>
<CardContent>
{ownsProduct ? (
<div className="flex items-center gap-2">
<span className="h-2 w-2 rounded-full bg-green-500" />
<span className="text-sm font-medium text-green-700">
Purchased
</span>
</div>
) : (
<CheckoutButton
priceId={PRODUCT_PRICE_ID}
mode="payment"
label="Buy Now"
/>
)}
</CardContent>
</Card>
</div>
</main>
);
}