Skip to content

Commit 68fa894

Browse files
committed
Fix expired Pro messaging in settings subscription panel
1 parent 3ace534 commit 68fa894

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

src/components/settings/subscription-section.tsx

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,22 @@ export function SubscriptionSection() {
4141
const subscription_status = profile?.subscription_status;
4242
const current_period_end = profile?.current_period_end;
4343
const trial_end = profile?.trial_end;
44-
44+
45+
const now = new Date();
4546
const trialEndDate = trial_end ? new Date(trial_end) : null;
46-
const isTrialing = Boolean(trialEndDate && trialEndDate > new Date());
47+
const currentPeriodEndDate = current_period_end ? new Date(current_period_end) : null;
48+
49+
const isTrialing = Boolean(trialEndDate && trialEndDate > now);
50+
const isWithinAccessWindow = Boolean(currentPeriodEndDate && currentPeriodEndDate > now);
51+
const isProPlan = subscription_plan?.toLowerCase() === 'pro';
52+
53+
const hasProAccess =
54+
(subscription_status === 'active' && isProPlan) ||
55+
isTrialing ||
56+
(subscription_status === 'canceled' && isWithinAccessWindow);
4757

48-
const effectivePlan = isTrialing ? 'pro' : subscription_plan;
49-
const isPro = effectivePlan?.toLowerCase() === 'pro';
50-
const isCanceling = subscription_status === 'canceled';
51-
const hasProAccess = isPro || isTrialing;
58+
const isCanceling = subscription_status === 'canceled' && hasProAccess;
59+
const isExpiredProAccess = subscription_status === 'canceled' && !hasProAccess;
5260

5361
const handlePortalSession = async () => {
5462
try {
@@ -67,7 +75,7 @@ export function SubscriptionSection() {
6775

6876
// Calculate days remaining for canceling plan
6977
const daysRemaining = current_period_end
70-
? Math.max(0, Math.ceil((new Date(current_period_end).getTime() - new Date().getTime()) / (1000 * 60 * 60 * 24)))
78+
? Math.max(0, Math.ceil((new Date(current_period_end).getTime() - now.getTime()) / (1000 * 60 * 60 * 24)))
7179
: 0;
7280

7381
const endDate = current_period_end
@@ -79,7 +87,7 @@ export function SubscriptionSection() {
7987
: null;
8088

8189
const trialDaysRemaining = isTrialing && trialEndDate
82-
? Math.max(0, Math.ceil((trialEndDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24)))
90+
? Math.max(0, Math.ceil((trialEndDate.getTime() - now.getTime()) / (1000 * 60 * 60 * 24)))
8391
: 0;
8492

8593
const trialEndLabel = trialEndDate
@@ -125,6 +133,23 @@ export function SubscriptionSection() {
125133
Your Pro access ends on {endDate}. Reactivate to keep your premium features.
126134
</p>
127135
</>
136+
) : isExpiredProAccess ? (
137+
<>
138+
<div className="flex items-center justify-center mb-2">
139+
<Clock className="h-6 w-6 text-rose-500 mr-2" />
140+
<Badge variant="outline" className="text-rose-700 border-rose-300 bg-rose-50">
141+
Access expired
142+
</Badge>
143+
</div>
144+
<h2 className="text-2xl font-bold text-gray-900">
145+
Your Pro access has expired
146+
</h2>
147+
<p className="text-gray-600 max-w-lg mx-auto">
148+
{endDate
149+
? `Your previous Pro access ended on ${endDate}. Upgrade to regain premium features.`
150+
: "Your previous Pro access has ended. Upgrade to regain premium features."}
151+
</p>
152+
</>
128153
) : isTrialing ? (
129154
<>
130155
<div className="flex items-center justify-center mb-2">

0 commit comments

Comments
 (0)