Skip to content

Commit e91f1f0

Browse files
committed
fix(checkout): refactor CheckoutCompleteDialog to improve plan type handling
- Replaced local variable with state management for plan type to ensure accurate rendering. - Updated logic to conditionally render content based on stored plan type. - Improved icon imports for better clarity and consistency in the UI.
1 parent 3e1db8d commit e91f1f0

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

apps/app/src/components/dialogs/checkout-complete-dialog.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ import {
1313
} from '@comp/ui/dialog';
1414
import confetti from 'canvas-confetti';
1515
import {
16-
BookOpen,
16+
Brain,
1717
CheckCircle2,
18-
Code2,
18+
FileText,
1919
Headphones,
2020
LucideIcon,
2121
MessageSquare,
2222
Rocket,
2323
Shield,
2424
Sparkles,
2525
Users,
26-
Brain,
27-
FileText,
2826
Zap,
2927
} from 'lucide-react';
3028
import { useQueryState } from 'nuqs';
@@ -58,10 +56,14 @@ export function CheckoutCompleteDialog() {
5856
clearOnDefault: true,
5957
});
6058
const [open, setOpen] = useState(false);
59+
const [planType, setPlanType] = useState<PlanType | null>(null);
6160

6261
useEffect(() => {
6362
if (checkoutComplete === 'starter' || checkoutComplete === 'done-for-you') {
64-
const planType = checkoutComplete as PlanType;
63+
const detectedPlanType = checkoutComplete as PlanType;
64+
65+
// Store the plan type before clearing the query param
66+
setPlanType(detectedPlanType);
6567

6668
// Show the dialog
6769
setOpen(true);
@@ -85,7 +87,7 @@ export function CheckoutCompleteDialog() {
8587
const particleCount = 50 * (timeLeft / duration);
8688
// Use different colors based on plan type
8789
const colors =
88-
planType === 'done-for-you'
90+
detectedPlanType === 'done-for-you'
8991
? ['#10b981', '#34d399', '#6ee7b7', '#a7f3d0', '#d1fae5'] // Green for paid
9092
: ['#3b82f6', '#60a5fa', '#93bbfc', '#bfdbfe', '#dbeafe']; // Blue for starter
9193

@@ -148,9 +150,10 @@ export function CheckoutCompleteDialog() {
148150
buttonText: 'Get Started',
149151
footerText: 'Your success team will reach out within 24 hours',
150152
},
151-
'starter': {
153+
starter: {
152154
title: 'Welcome to Starter!',
153-
description: "Everything you need to get compliant, fast. Let's begin your DIY compliance journey!",
155+
description:
156+
"Everything you need to get compliant, fast. Let's begin your DIY compliance journey!",
154157
badge: 'DIY (Do It Yourself) Compliance',
155158
badgeDescription: 'Build your compliance program at your own pace',
156159
badgeClass: 'bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300',
@@ -184,12 +187,12 @@ export function CheckoutCompleteDialog() {
184187
},
185188
};
186189

187-
// Get current content, default to done-for-you if the value is not a valid plan type
188-
const validPlanType =
189-
checkoutComplete === 'starter' || checkoutComplete === 'done-for-you'
190-
? checkoutComplete
191-
: 'done-for-you';
192-
const currentContent = content[validPlanType];
190+
// Only render content if we have a valid plan type stored
191+
if (!planType) {
192+
return null;
193+
}
194+
195+
const currentContent = content[planType];
193196

194197
return (
195198
<Dialog open={open} onOpenChange={handleClose}>
@@ -220,7 +223,7 @@ export function CheckoutCompleteDialog() {
220223

221224
<div className="space-y-3">
222225
<h3 className="text-sm font-semibold text-muted-foreground">
223-
{validPlanType === 'starter' ? 'What you get:' : 'What's included:'}
226+
{planType === 'starter' ? 'What you get:' : "What's included:"}
224227
</h3>
225228
<div className="grid gap-3">
226229
{currentContent.features.map((feature: Feature) => {
@@ -242,7 +245,7 @@ export function CheckoutCompleteDialog() {
242245
</div>
243246
</div>
244247

245-
{validPlanType === 'starter' && (
248+
{planType === 'starter' && (
246249
<div className="mt-4 p-3 bg-muted/50 rounded-lg">
247250
<p className="text-xs text-muted-foreground text-center">
248251
<MessageSquare className="h-3 w-3 inline mr-1" />

0 commit comments

Comments
 (0)