Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 1x 1x 4x 4x 4x 4x 4x 4x 4x 5x 5x 5x 5x 5x 5x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 4x 4x 5x 5x 5x 5x 5x 3x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 5x 2x 2x 5x 5x 2x 2x 2x 2x 5x 1x 1x 1x 1x 1x 1x 5x 5x 43x 43x 43x 43x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 1x 1x 1x 3x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x | import { Metadata } from 'next';
import Link from 'next/link';
import { redirect } from 'next/navigation';
import { CreditCard, Calendar, Check, Receipt, AlertCircle } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { getUser, createClient } from '@/lib/supabase/server';
import { getAdminClient } from '@/lib/supabase/admin';
import { formatDate } from '@/lib/utils';
import { SubscriptionActions } from './SubscriptionActions';
export const dynamic = 'force-dynamic';
export const metadata: Metadata = {
title: 'Subscription - ProofID',
description: 'Manage your ProofID subscription and billing',
};
const tierFeatures: Record<string, string[]> = {
free: [
'1 Work Sample',
'1 Service Package',
'1 Work Experience',
'Basic Profile',
'ProofID Identity Code',
'WhatsApp Button',
'Referral System',
],
basic: [
'5 Work Samples',
'3 Testimonials',
'3 Service Packages',
'3 Work Experiences',
'10 Testimonial Requests',
'Basic Analytics',
'Email Support',
],
pro: [
'15 Work Samples',
'10 Testimonials',
'10 Service Packages',
'10 Work Experiences',
'30 Testimonial Requests',
'Advanced Analytics',
'Growth & Trend Insights',
'Visitor Retention & Peak Hours',
'Custom Profile URL',
'Remove Branding',
'SEO Optimization',
'Priority Support',
],
premium: [
'Unlimited Work Samples',
'Unlimited Testimonials',
'Unlimited Packages',
'Unlimited Experiences',
'Unlimited Testimonial Requests',
'Full Analytics Suite',
'Conversion Funnel Analytics',
'Content Performance Tracking',
'Verified Badge',
'Featured in Directory',
'API & Developer Tools',
'Priority Support',
],
};
const tierNames: Record<string, string> = {
free: 'Free',
basic: 'Basic',
pro: 'Pro',
premium: 'Premium',
};
export default async function SubscriptionPage() {
const user = await getUser();
if (!user) {
redirect('/login');
}
const supabase = await createClient();
const adminClient = getAdminClient();
// Get user's profile
const { data: profile } = await supabase
.from('profiles')
.select('id, subscription_tier')
.eq('user_id', user.id)
.single();
const currentTier = profile?.subscription_tier || 'free';
// Get subscription details
const { data: subscription } = await adminClient
.from('subscriptions')
.select('*, plan:subscription_plans(*)')
.eq('user_id', user.id)
.single();
// Get payment history
const { data: payments } = await adminClient
.from('payments')
.select('id, description, created_at, razorpay_payment_id, amount')
.eq('user_id', user.id)
.eq('status', 'captured')
.order('created_at', { ascending: false })
.limit(5);
// Get content counts for downgrade impact
const [samplesResult, testimonialsResult, packagesResult] = await Promise.all([
supabase
.from('samples')
.select('id', { count: 'exact', head: true })
.eq('profile_id', profile?.id || ''),
supabase
.from('testimonials')
.select('id', { count: 'exact', head: true })
.eq('profile_id', profile?.id || ''),
supabase
.from('packages')
.select('id', { count: 'exact', head: true })
.eq('profile_id', profile?.id || '')
.eq('is_active', true),
]);
const contentCounts = {
samples: samplesResult.count || 0,
testimonials: testimonialsResult.count || 0,
packages: packagesResult.count || 0,
};
const isSubscribed = currentTier !== 'free';
const expiresAt = subscription?.current_period_end
? new Date(subscription.current_period_end)
: null;
const isExpired = expiresAt ? expiresAt < new Date() : false;
const hasPendingDowngrade = !!subscription?.pending_downgrade_tier;
return (
<div className="space-y-8">
<div>
<h1 className="text-3xl font-bold">Subscription</h1>
<p className="text-muted-foreground">Manage your plan and billing</p>
</div>
{/* Current Plan */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<CreditCard className="h-5 w-5" />
Current Plan
</CardTitle>
<CardDescription>Your active subscription details</CardDescription>
</CardHeader>
<CardContent>
<div className="flex flex-col gap-6 md:flex-row md:items-start md:justify-between">
<div>
<div className="mb-4">
<span className="text-2xl font-bold">{tierNames[currentTier]}</span>
{isExpired && (
<span className="ml-2 rounded-full bg-destructive/10 px-2 py-1 text-xs text-destructive">
Expired
</span>
)}
{!isExpired && isSubscribed && (
<span className="ml-2 rounded-full bg-primary/10 px-2 py-1 text-xs text-primary">
Active
</span>
)}
</div>
{expiresAt && !isExpired && (
<div className="mb-4 flex items-center gap-2 text-sm text-muted-foreground">
<Calendar className="h-4 w-4" />
<span>{`Valid until ${formatDate(expiresAt.toISOString())}`}</span>
</div>
)}
{hasPendingDowngrade && (
<div className="mb-4 flex items-center gap-2 rounded-lg border border-orange-200 bg-orange-50 px-3 py-2 text-sm dark:border-orange-900 dark:bg-orange-950/30">
<AlertCircle className="h-4 w-4 text-orange-500" />
<span className="text-orange-800 dark:text-orange-200">
{`Scheduled to downgrade to ${tierNames[subscription?.pending_downgrade_tier || 'free']} on ${formatDate(subscription?.downgrade_effective_date || '')}`}
</span>
</div>
)}
<ul className="space-y-2">
{tierFeatures[currentTier]?.map((feature) => (
<li key={feature} className="flex items-center gap-2 text-sm">
<Check className="h-4 w-4 text-primary" />
{feature}
</li>
))}
</ul>
</div>
<SubscriptionActions
currentTier={currentTier}
currentPeriodEnd={subscription?.current_period_end || null}
hasPendingDowngrade={hasPendingDowngrade}
pendingDowngradeTier={subscription?.pending_downgrade_tier || null}
contentCounts={contentCounts}
/>
</div>
</CardContent>
</Card>
{/* Payment History */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Receipt className="h-5 w-5" />
Payment History
</CardTitle>
<CardDescription>Your recent transactions</CardDescription>
</CardHeader>
<CardContent>
{payments && payments.length > 0 ? (
<div className="space-y-4">
{payments.map((payment) => (
<div
key={payment.id}
className="flex items-center justify-between border-b pb-4 last:border-0"
>
<div>
<p className="font-medium">{payment.description || 'Subscription Payment'}</p>
<p className="text-sm text-muted-foreground">
{formatDate(payment.created_at)}
</p>
{payment.razorpay_payment_id && (
<p className="text-xs text-muted-foreground">
ID: {payment.razorpay_payment_id}
</p>
)}
</div>
<div className="text-right">
<p className="font-semibold">₹{((payment.amount || 0) / 100).toFixed(2)}</p>
<p className="text-xs text-green-600">Paid</p>
</div>
</div>
))}
</div>
) : (
<div className="py-8 text-center">
<p className="text-muted-foreground">No payment history yet</p>
{currentTier === 'free' && (
<Button asChild className="mt-4">
<Link href="/pricing">Upgrade Now</Link>
</Button>
)}
</div>
)}
</CardContent>
</Card>
{/* Help */}
<Card>
<CardHeader>
<CardTitle>Need Help?</CardTitle>
</CardHeader>
<CardContent>
<p className="text-sm text-muted-foreground">
For billing inquiries or subscription issues, contact us at{' '}
<a href="mailto:support@proofid.in" className="text-primary hover:underline">
support@proofid.in
</a>
</p>
</CardContent>
</Card>
</div>
);
}
|