Skip to content

Commit d7d75f7

Browse files
authored
Merge pull request Dokploy#5477 from Dokploy/feat/trial-expiration-emails
fix(billing): pick a plan for the trial and warn before it expires
2 parents 853ca33 + a0e1001 commit d7d75f7

12 files changed

Lines changed: 732 additions & 416 deletions

File tree

‎apps/dokploy/components/dashboard/billing/trial-banner.tsx‎

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,41 @@ import { api } from "@/utils/api";
66
export const TrialBanner = () => {
77
const router = useRouter();
88
const { data: billingStatus } = api.stripe.getBillingStatus.useQuery();
9+
const { mutateAsync: createCustomerPortalSession, isPending } =
10+
api.stripe.createCustomerPortalSession.useMutation();
911

10-
if (!billingStatus?.isOnTrial) {
12+
const handleAddPaymentMethod = async () => {
13+
const session = await createCustomerPortalSession().catch(() => null);
14+
if (session?.url) {
15+
window.open(session.url);
16+
return;
17+
}
18+
router.push("/dashboard/settings/billing");
19+
};
20+
21+
if (!billingStatus?.isOnTrial || billingStatus.hasPaymentMethod) {
1122
return null;
1223
}
1324

1425
const daysRemaining = billingStatus.trialDaysRemaining ?? 0;
26+
const daysLabel = `${daysRemaining} day${daysRemaining === 1 ? "" : "s"}`;
1527

1628
return (
1729
<div className="sticky top-0 z-20 mx-4 mt-4 flex flex-wrap items-center justify-center gap-x-3 gap-y-2 rounded-lg border border-primary/20 bg-primary/10 px-4 py-2 text-sm">
1830
<span className="flex items-center gap-2">
1931
<Rocket className="h-4 w-4 text-primary shrink-0" />
2032
{daysRemaining > 0
21-
? `You have ${daysRemaining} day${daysRemaining === 1 ? "" : "s"} left in your free trial.`
22-
: "Your free trial ends today."}
33+
? `You have ${daysLabel} left in your free trial. Add a payment method to keep your servers.`
34+
: "Your free trial ends today. Add a payment method to keep your servers."}
2335
</span>
2436
<Button
2537
size="sm"
2638
variant="default"
2739
className="h-7"
28-
onClick={() => router.push("/dashboard/settings/billing")}
40+
isLoading={isPending}
41+
onClick={handleAddPaymentMethod}
2942
>
30-
Upgrade now
43+
Add payment method
3144
</Button>
3245
</div>
3346
);

‎apps/dokploy/components/dashboard/onboarding/onboarding-wizard.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,9 @@ export const OnboardingWizard = ({ onClose }: Props) => {
278278
<DialogTitle>Skip onboarding?</DialogTitle>
279279
<DialogDescription>
280280
If this is your first time using Dokploy, we recommend going
281-
through these steps — it only takes a couple of minutes and gives
282-
you a feel for how projects, servers and deployments fit together.
281+
through these steps – it only takes a couple of minutes and gives
282+
you a feel for how projects, servers, and deployments fit
283+
together.
283284
</DialogDescription>
284285
</DialogHeader>
285286
<DialogFooter>

‎apps/dokploy/components/dashboard/onboarding/steps/plan-step.tsx‎

Lines changed: 106 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,50 @@ const stripePromise = loadStripe(
1515
process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY!,
1616
);
1717

18+
type Tier = "hobby" | "startup";
19+
20+
const PLANS: {
21+
tier: Tier;
22+
name: string;
23+
description: string;
24+
price: number;
25+
features: string[];
26+
recommended?: boolean;
27+
}[] = [
28+
{
29+
tier: "hobby",
30+
name: "Hobby",
31+
description: "For individual developers",
32+
price: calculatePriceHobby(1, false),
33+
features: [
34+
"Setup 1 server",
35+
"Unlimited apps & databases",
36+
"2 environments",
37+
"Community support",
38+
],
39+
},
40+
{
41+
tier: "startup",
42+
name: "Startup",
43+
description: "For small to mid-size teams",
44+
price: calculatePriceStartup(STARTUP_SERVERS_INCLUDED, false),
45+
recommended: true,
46+
features: [
47+
`Setup up to ${STARTUP_SERVERS_INCLUDED} servers`,
48+
"Unlimited users & environments",
49+
"Basic RBAC + 2FA",
50+
"Email & chat support",
51+
],
52+
},
53+
];
54+
1855
interface Props {
1956
onNext: () => void;
2057
}
2158

2259
export const PlanStep = ({ onNext }: Props) => {
23-
const [loadingTier, setLoadingTier] = useState<
24-
"hobby" | "startup" | "trial" | null
60+
const [loading, setLoading] = useState<
61+
`${"trial" | "checkout"}:${Tier}` | null
2562
>(null);
2663
const { data } = api.stripe.getProducts.useQuery();
2764
const { mutateAsync: createCheckoutSession } =
@@ -30,12 +67,12 @@ export const PlanStep = ({ onNext }: Props) => {
3067
api.stripe.startFreeTrial.useMutation();
3168
const utils = api.useUtils();
3269

33-
const handleCheckout = async (tier: "hobby" | "startup") => {
70+
const handleCheckout = async (tier: Tier) => {
3471
if (!data) return;
3572
const productId =
3673
tier === "hobby" ? data.hobbyProductId : data.startupProductId;
3774
if (!productId) return;
38-
setLoadingTier(tier);
75+
setLoading(`checkout:${tier}`);
3976
try {
4077
const stripe = await stripePromise;
4178
const session = await createCheckoutSession({
@@ -47,14 +84,14 @@ export const PlanStep = ({ onNext }: Props) => {
4784
await stripe?.redirectToCheckout({ sessionId: session.sessionId });
4885
} catch {
4986
toast.error("Error starting checkout");
50-
setLoadingTier(null);
87+
setLoading(null);
5188
}
5289
};
5390

54-
const handleTrial = async () => {
55-
setLoadingTier("trial");
91+
const handleTrial = async (tier: Tier) => {
92+
setLoading(`trial:${tier}`);
5693
try {
57-
await startFreeTrial();
94+
await startFreeTrial({ tier });
5895
await utils.project.onboardingStatus.invalidate();
5996
toast.success("Your 7-day trial has started");
6097
onNext();
@@ -63,7 +100,7 @@ export const PlanStep = ({ onNext }: Props) => {
63100
error instanceof Error ? error.message : "Error starting trial",
64101
);
65102
} finally {
66-
setLoadingTier(null);
103+
setLoading(null);
67104
}
68105
};
69106

@@ -79,134 +116,72 @@ export const PlanStep = ({ onNext }: Props) => {
79116
Start free, upgrade when ready.
80117
</h1>
81118
<p className="text-muted-foreground text-lg max-w-md leading-relaxed">
82-
No credit card for the trial — add one only if you decide to stay.
119+
Try any plan free for 7 days. No credit card required — add one only
120+
if you decide to stay.
83121
</p>
84122
</div>
85123

86-
<div className="flex flex-col rounded-2xl bg-zinc-950 dark:bg-white text-white dark:text-zinc-950 overflow-hidden">
87-
<div className="flex flex-col sm:flex-row sm:items-start justify-between gap-6 p-7">
88-
<div>
89-
<span className="inline-flex items-center rounded-full bg-white text-zinc-950 dark:bg-zinc-950 dark:text-white font-mono text-[10px] font-semibold uppercase tracking-[0.15em] px-2.5 py-1">
90-
Recommended
91-
</span>
92-
<p className={`${displayFont.className} text-2xl mt-3`}>
93-
7-day free trial
94-
</p>
95-
<p className="text-sm text-zinc-400 dark:text-zinc-600 mt-1 max-w-xs">
96-
No card required — cancel anytime.
97-
</p>
98-
<ul className="flex flex-col gap-1.5 mt-4">
99-
{[
100-
"Setup 1 server",
101-
"Unlimited apps & databases",
102-
"Community support",
103-
].map((f) => (
104-
<li
105-
key={f}
106-
className="flex items-center gap-2 text-sm text-zinc-300 dark:text-zinc-700"
107-
>
108-
<CheckIcon className="size-3.5 text-zinc-500 shrink-0" />
109-
{f}
110-
</li>
111-
))}
112-
</ul>
113-
</div>
114-
<Button
115-
size="lg"
116-
className="bg-white text-zinc-950 hover:bg-zinc-200 dark:bg-zinc-950 dark:text-white dark:hover:bg-zinc-800 w-fit shrink-0 px-6"
117-
isLoading={loadingTier === "trial"}
118-
disabled={loadingTier !== null}
119-
onClick={handleTrial}
120-
>
121-
Start trial
122-
<ArrowRightIcon className="size-4" />
123-
</Button>
124-
</div>
125-
</div>
126-
127124
<div className="grid grid-cols-1 sm:grid-cols-2 gap-px bg-border rounded-2xl overflow-hidden border">
128-
<div className="flex flex-col justify-between gap-6 bg-background p-7">
129-
<div>
130-
<p className="font-medium">Hobby</p>
131-
<p className="text-sm text-muted-foreground mt-1">
132-
For individual developers
133-
</p>
134-
<p className="text-3xl font-semibold mt-4 tabular-nums">
135-
${calculatePriceHobby(1, false).toFixed(2)}
136-
<span className="text-sm font-normal text-muted-foreground">
137-
{" "}
138-
/mo
139-
</span>
140-
</p>
141-
<ul className="flex flex-col gap-1.5 mt-4">
142-
{[
143-
"Setup 1 server",
144-
"Unlimited apps & databases",
145-
"2 environments",
146-
"Community support",
147-
].map((f) => (
148-
<li
149-
key={f}
150-
className="flex items-center gap-2 text-sm text-muted-foreground"
125+
{PLANS.map((plan) => {
126+
const productId =
127+
plan.tier === "hobby"
128+
? data?.hobbyProductId
129+
: data?.startupProductId;
130+
return (
131+
<div
132+
key={plan.tier}
133+
className="flex flex-col justify-between gap-6 bg-background p-7"
134+
>
135+
<div>
136+
{plan.recommended && (
137+
<span className="inline-flex items-center rounded-full bg-primary text-primary-foreground font-mono text-[10px] font-semibold uppercase tracking-[0.15em] px-2.5 py-1 mb-3">
138+
Recommended
139+
</span>
140+
)}
141+
<p className="font-medium">{plan.name}</p>
142+
<p className="text-sm text-muted-foreground mt-1">
143+
{plan.description}
144+
</p>
145+
<p className="text-3xl font-semibold mt-4 tabular-nums">
146+
${plan.price.toFixed(2)}
147+
<span className="text-sm font-normal text-muted-foreground">
148+
{" "}
149+
/mo
150+
</span>
151+
</p>
152+
<ul className="flex flex-col gap-1.5 mt-4">
153+
{plan.features.map((f) => (
154+
<li
155+
key={f}
156+
className="flex items-center gap-2 text-sm text-muted-foreground"
157+
>
158+
<CheckIcon className="size-3.5 shrink-0" />
159+
{f}
160+
</li>
161+
))}
162+
</ul>
163+
</div>
164+
<div className="flex flex-col gap-2">
165+
<Button
166+
isLoading={loading === `trial:${plan.tier}`}
167+
disabled={loading !== null}
168+
onClick={() => handleTrial(plan.tier)}
151169
>
152-
<CheckIcon className="size-3.5 shrink-0" />
153-
{f}
154-
</li>
155-
))}
156-
</ul>
157-
</div>
158-
<Button
159-
variant="outline"
160-
isLoading={loadingTier === "hobby"}
161-
disabled={loadingTier !== null || !data?.hobbyProductId}
162-
onClick={() => handleCheckout("hobby")}
163-
>
164-
Subscribe
165-
</Button>
166-
</div>
167-
168-
<div className="flex flex-col justify-between gap-6 bg-background p-7">
169-
<div>
170-
<p className="font-medium">Startup</p>
171-
<p className="text-sm text-muted-foreground mt-1">
172-
For small to mid-size teams
173-
</p>
174-
<p className="text-3xl font-semibold mt-4 tabular-nums">
175-
$
176-
{calculatePriceStartup(STARTUP_SERVERS_INCLUDED, false).toFixed(
177-
2,
178-
)}
179-
<span className="text-sm font-normal text-muted-foreground">
180-
{" "}
181-
/mo
182-
</span>
183-
</p>
184-
<ul className="flex flex-col gap-1.5 mt-4">
185-
{[
186-
`Setup up to ${STARTUP_SERVERS_INCLUDED} servers`,
187-
"Unlimited users & environments",
188-
"Basic RBAC + 2FA",
189-
"Email & chat support",
190-
].map((f) => (
191-
<li
192-
key={f}
193-
className="flex items-center gap-2 text-sm text-muted-foreground"
170+
Start 7-day free trial
171+
<ArrowRightIcon className="size-4" />
172+
</Button>
173+
<Button
174+
variant="outline"
175+
isLoading={loading === `checkout:${plan.tier}`}
176+
disabled={loading !== null || !productId}
177+
onClick={() => handleCheckout(plan.tier)}
194178
>
195-
<CheckIcon className="size-3.5 shrink-0" />
196-
{f}
197-
</li>
198-
))}
199-
</ul>
200-
</div>
201-
<Button
202-
variant="outline"
203-
isLoading={loadingTier === "startup"}
204-
disabled={loadingTier !== null || !data?.startupProductId}
205-
onClick={() => handleCheckout("startup")}
206-
>
207-
Subscribe
208-
</Button>
209-
</div>
179+
Subscribe now
180+
</Button>
181+
</div>
182+
</div>
183+
);
184+
})}
210185
</div>
211186
</div>
212187
);

‎apps/dokploy/components/dashboard/onboarding/steps/project-step.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const ProjectStep = ({ onNext, plainTitle }: Props) => {
6565
</span>
6666
<h1 className={titleClassName}>Create your first project.</h1>
6767
<p className="text-muted-foreground text-lg max-w-md leading-relaxed">
68-
Projects group your apps, databases and environments together.
68+
Projects group your apps, databases, and environments together.
6969
</p>
7070
</div>
7171

0 commit comments

Comments
 (0)