Skip to content

Commit f404b23

Browse files
authored
Merge pull request #4198 from Dokploy/feat/billing-cloud-improvements
Feat/billing cloud improvements
2 parents b4c57b6 + 7a986e5 commit f404b23

13 files changed

Lines changed: 8914 additions & 12 deletions

File tree

apps/dokploy/components/dashboard/settings/billing/show-billing.tsx

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { loadStripe } from "@stripe/stripe-js";
22
import clsx from "clsx";
33
import {
44
AlertTriangle,
5+
Bell,
56
CheckIcon,
67
CreditCard,
78
FileText,
@@ -25,7 +26,17 @@ import {
2526
CardTitle,
2627
} from "@/components/ui/card";
2728
import { NumberInput } from "@/components/ui/input";
29+
import {
30+
Dialog,
31+
DialogContent,
32+
DialogDescription,
33+
DialogHeader,
34+
DialogTitle,
35+
DialogTrigger,
36+
} from "@/components/ui/dialog";
37+
import { Label } from "@/components/ui/label";
2838
import { Progress } from "@/components/ui/progress";
39+
import { Switch } from "@/components/ui/switch";
2940
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
3041
import { cn } from "@/lib/utils";
3142
import { api } from "@/utils/api";
@@ -90,6 +101,8 @@ export const ShowBilling = () => {
90101
api.stripe.createCustomerPortalSession.useMutation();
91102
const { mutateAsync: upgradeSubscription, isPending: isUpgrading } =
92103
api.stripe.upgradeSubscription.useMutation();
104+
const { mutateAsync: updateInvoiceNotifications } =
105+
api.stripe.updateInvoiceNotifications.useMutation();
93106
const utils = api.useUtils();
94107

95108
const [hobbyServerQuantity, setHobbyServerQuantity] = useState(1);
@@ -151,14 +164,68 @@ export const ShowBilling = () => {
151164
<div className="w-full">
152165
<Card className="bg-sidebar p-2.5 rounded-xl max-w-6xl mx-auto">
153166
<div className="rounded-xl bg-background shadow-md">
154-
<CardHeader>
155-
<CardTitle className="text-xl flex flex-row gap-2">
156-
<CreditCard className="size-6 text-muted-foreground self-center" />
157-
Billing
158-
</CardTitle>
159-
<CardDescription>
160-
Manage your subscription and invoices
161-
</CardDescription>
167+
<CardHeader className="flex flex-row items-start justify-between">
168+
<div>
169+
<CardTitle className="text-xl flex flex-row gap-2">
170+
<CreditCard className="size-6 text-muted-foreground self-center" />
171+
Billing
172+
</CardTitle>
173+
<CardDescription>
174+
Manage your subscription and invoices
175+
</CardDescription>
176+
</div>
177+
{(admin?.user.stripeSubscriptionId || isEnterpriseCloud) && (
178+
<Dialog>
179+
<DialogTrigger asChild>
180+
<Button variant="outline" size="icon">
181+
<Bell className="size-4" />
182+
</Button>
183+
</DialogTrigger>
184+
<DialogContent className="sm:max-w-md">
185+
<DialogHeader>
186+
<DialogTitle>Notification Settings</DialogTitle>
187+
<DialogDescription>
188+
Configure your billing email notifications.
189+
</DialogDescription>
190+
</DialogHeader>
191+
<div className="flex items-center justify-between rounded-lg border p-4">
192+
<div className="space-y-0.5">
193+
<Label htmlFor="invoice-notifications">
194+
Invoice Notifications
195+
</Label>
196+
<p className="text-sm text-muted-foreground">
197+
Receive email notifications for payments and failed
198+
charges.
199+
</p>
200+
</div>
201+
<Switch
202+
id="invoice-notifications"
203+
checked={
204+
admin?.user.sendInvoiceNotifications ?? false
205+
}
206+
onCheckedChange={async (checked) => {
207+
await updateInvoiceNotifications({
208+
enabled: checked,
209+
})
210+
.then(() => {
211+
utils.user.get.invalidate();
212+
toast.success(
213+
checked
214+
? "Invoice notifications enabled"
215+
: "Invoice notifications disabled",
216+
);
217+
})
218+
.catch(() => {
219+
toast.error(
220+
"Failed to update invoice notifications",
221+
);
222+
});
223+
}}
224+
/>
225+
</div>
226+
</DialogContent>
227+
</Dialog>
228+
)}
162229
</CardHeader>
163230
<CardContent className="space-y-4 py-4 border-t">
164231
<nav className="flex space-x-2 border-b">

apps/dokploy/components/dashboard/settings/servers/welcome-stripe/welcome-subscription.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export const WelcomeSubscription = () => {
5555
const [showConfetti, setShowConfetti] = useState(false);
5656
const stepper = useStepper();
5757
const [isOpen, setIsOpen] = useState(true);
58-
const { push } = useRouter();
58+
const router = useRouter();
59+
const { push } = router;
5960

6061
useEffect(() => {
6162
const confettiShown = localStorage.getItem("hasShownConfetti");
@@ -66,7 +67,18 @@ export const WelcomeSubscription = () => {
6667
}, [showConfetti]);
6768

6869
return (
69-
<Dialog open={isOpen}>
70+
<Dialog
71+
open={isOpen}
72+
onOpenChange={(open) => {
73+
setIsOpen(open);
74+
if (!open) {
75+
const { success, ...rest } = router.query;
76+
router.replace({ pathname: router.pathname, query: rest }, undefined, {
77+
shallow: true,
78+
});
79+
}
80+
}}
81+
>
7082
<DialogContent className="sm:max-w-7xl min-h-[75vh]">
7183
{showConfetti ?? "Flaso"}
7284
<div className="flex justify-center items-center w-full">
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "user" ADD COLUMN "sendInvoiceNotifications" boolean DEFAULT false NOT NULL;

0 commit comments

Comments
 (0)