mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-09 21:45:17 +00:00
feat(billing): add billing invoices page and update billing components
- Introduced `ShowBillingInvoices` component to manage and display billing invoices. - Updated `ShowBilling` component to include navigation for invoices and enhanced subscription management. - Refactored `ShowInvoices` component for improved loading and display logic. - Created a new invoices page with server-side validation and layout integration.
This commit is contained in:
@@ -0,0 +1,74 @@
|
|||||||
|
import { CreditCard, FileText } from "lucide-react";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardContent,
|
||||||
|
CardDescription,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
} from "@/components/ui/card";
|
||||||
|
import { cn } from "@/lib/utils";
|
||||||
|
import { ShowInvoices } from "./show-invoices";
|
||||||
|
|
||||||
|
const navigationItems = [
|
||||||
|
{
|
||||||
|
name: "Subscription",
|
||||||
|
href: "/dashboard/settings/billing",
|
||||||
|
icon: CreditCard,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Invoices",
|
||||||
|
href: "/dashboard/settings/invoices",
|
||||||
|
icon: FileText,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export const ShowBillingInvoices = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="w-full">
|
||||||
|
<Card className="bg-sidebar p-2.5 rounded-xl max-w-5xl mx-auto">
|
||||||
|
<div className="rounded-xl bg-background shadow-md">
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="text-xl flex flex-row gap-2">
|
||||||
|
<CreditCard className="size-6 text-muted-foreground self-center" />
|
||||||
|
Billing
|
||||||
|
</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
Manage your subscription and invoices
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4 py-4 border-t">
|
||||||
|
<nav className="flex space-x-2 border-b">
|
||||||
|
{navigationItems.map((item) => {
|
||||||
|
const Icon = item.icon;
|
||||||
|
const isActive = router.pathname === item.href;
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
key={item.name}
|
||||||
|
href={item.href}
|
||||||
|
className={cn(
|
||||||
|
"flex items-center gap-2 px-4 py-2 text-sm font-medium border-b-2 transition-colors",
|
||||||
|
isActive
|
||||||
|
? "border-primary text-primary"
|
||||||
|
: "border-transparent text-muted-foreground hover:text-primary hover:border-muted",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Icon className="h-4 w-4" />
|
||||||
|
{item.name}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div className="mt-6">
|
||||||
|
<ShowInvoices />
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -4,11 +4,13 @@ import {
|
|||||||
AlertTriangle,
|
AlertTriangle,
|
||||||
CheckIcon,
|
CheckIcon,
|
||||||
CreditCard,
|
CreditCard,
|
||||||
|
FileText,
|
||||||
Loader2,
|
Loader2,
|
||||||
MinusIcon,
|
MinusIcon,
|
||||||
PlusIcon,
|
PlusIcon,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
@@ -24,7 +26,6 @@ import { Progress } from "@/components/ui/progress";
|
|||||||
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
import { api } from "@/utils/api";
|
import { api } from "@/utils/api";
|
||||||
import { ShowInvoices } from "./show-invoices";
|
|
||||||
|
|
||||||
const stripePromise = loadStripe(
|
const stripePromise = loadStripe(
|
||||||
process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY!,
|
process.env.NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY!,
|
||||||
@@ -38,7 +39,22 @@ export const calculatePrice = (count: number, isAnnual = false) => {
|
|||||||
if (count <= 1) return 4.5;
|
if (count <= 1) return 4.5;
|
||||||
return count * 3.5;
|
return count * 3.5;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const navigationItems = [
|
||||||
|
{
|
||||||
|
name: "Subscription",
|
||||||
|
href: "/dashboard/settings/billing",
|
||||||
|
icon: CreditCard,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Invoices",
|
||||||
|
href: "/dashboard/settings/invoices",
|
||||||
|
icon: FileText,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
export const ShowBilling = () => {
|
export const ShowBilling = () => {
|
||||||
|
const router = useRouter();
|
||||||
const { data: servers } = api.server.count.useQuery();
|
const { data: servers } = api.server.count.useQuery();
|
||||||
const { data: admin } = api.user.get.useQuery();
|
const { data: admin } = api.user.get.useQuery();
|
||||||
const { data, isLoading } = api.stripe.getProducts.useQuery();
|
const { data, isLoading } = api.stripe.getProducts.useQuery();
|
||||||
@@ -76,252 +92,274 @@ export const ShowBilling = () => {
|
|||||||
const safePercentage = Math.min(percentage, 100);
|
const safePercentage = Math.min(percentage, 100);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="w-full space-y-6">
|
<div className="w-full">
|
||||||
<Card className="bg-sidebar p-2.5 rounded-xl max-w-5xl mx-auto">
|
<Card className="bg-sidebar p-2.5 rounded-xl max-w-5xl mx-auto">
|
||||||
<div className="rounded-xl bg-background shadow-md ">
|
<div className="rounded-xl bg-background shadow-md">
|
||||||
<CardHeader className="">
|
<CardHeader>
|
||||||
<CardTitle className="text-xl flex flex-row gap-2">
|
<CardTitle className="text-xl flex flex-row gap-2">
|
||||||
<CreditCard className="size-6 text-muted-foreground self-center" />
|
<CreditCard className="size-6 text-muted-foreground self-center" />
|
||||||
Billing
|
Billing
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<CardDescription>Manage your subscription</CardDescription>
|
<CardDescription>
|
||||||
|
Manage your subscription and invoices
|
||||||
|
</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="space-y-2 py-8 border-t">
|
<CardContent className="space-y-4 py-4 border-t">
|
||||||
<div className="flex flex-col gap-4 w-full">
|
<nav className="flex space-x-2 border-b">
|
||||||
<Tabs
|
{navigationItems.map((item) => {
|
||||||
defaultValue="monthly"
|
const Icon = item.icon;
|
||||||
value={isAnnual ? "annual" : "monthly"}
|
const isActive = router.pathname === item.href;
|
||||||
className="w-full"
|
return (
|
||||||
onValueChange={(e) => setIsAnnual(e === "annual")}
|
<Link
|
||||||
>
|
key={item.name}
|
||||||
<TabsList>
|
href={item.href}
|
||||||
<TabsTrigger value="monthly">Monthly</TabsTrigger>
|
className={cn(
|
||||||
<TabsTrigger value="annual">Annual</TabsTrigger>
|
"flex items-center gap-2 px-4 py-2 text-sm font-medium border-b-2 transition-colors",
|
||||||
</TabsList>
|
isActive
|
||||||
</Tabs>
|
? "border-primary text-primary"
|
||||||
{admin?.user.stripeSubscriptionId && (
|
: "border-transparent text-muted-foreground hover:text-primary hover:border-muted",
|
||||||
<div className="space-y-2 flex flex-col">
|
)}
|
||||||
<h3 className="text-lg font-medium">Servers Plan</h3>
|
>
|
||||||
<p className="text-sm text-muted-foreground">
|
<Icon className="h-4 w-4" />
|
||||||
You have {servers} server on your plan of{" "}
|
{item.name}
|
||||||
{admin?.user.serversQuantity} servers
|
</Link>
|
||||||
</p>
|
);
|
||||||
<div>
|
})}
|
||||||
<Progress value={safePercentage} className="max-w-lg" />
|
</nav>
|
||||||
</div>
|
|
||||||
{admin && admin.user.serversQuantity! <= (servers ?? 0) && (
|
<div className="flex flex-col gap-4 w-full mt-6">
|
||||||
<div className="flex flex-row gap-4 p-2 bg-yellow-50 dark:bg-yellow-950 rounded-lg items-center">
|
<Tabs
|
||||||
<AlertTriangle className="text-yellow-600 dark:text-yellow-400" />
|
defaultValue="monthly"
|
||||||
<span className="text-sm text-yellow-600 dark:text-yellow-400">
|
value={isAnnual ? "annual" : "monthly"}
|
||||||
You have reached the maximum number of servers you can
|
className="w-full"
|
||||||
create, please upgrade your plan to add more servers.
|
onValueChange={(e) => setIsAnnual(e === "annual")}
|
||||||
</span>
|
>
|
||||||
|
<TabsList>
|
||||||
|
<TabsTrigger value="monthly">Monthly</TabsTrigger>
|
||||||
|
<TabsTrigger value="annual">Annual</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
</Tabs>
|
||||||
|
{admin?.user.stripeSubscriptionId && (
|
||||||
|
<div className="space-y-2 flex flex-col">
|
||||||
|
<h3 className="text-lg font-medium">Servers Plan</h3>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
You have {servers} server on your plan of{" "}
|
||||||
|
{admin?.user.serversQuantity} servers
|
||||||
|
</p>
|
||||||
|
<div>
|
||||||
|
<Progress value={safePercentage} className="max-w-lg" />
|
||||||
|
</div>
|
||||||
|
{admin && admin.user.serversQuantity! <= (servers ?? 0) && (
|
||||||
|
<div className="flex flex-row gap-4 p-2 bg-yellow-50 dark:bg-yellow-950 rounded-lg items-center">
|
||||||
|
<AlertTriangle className="text-yellow-600 dark:text-yellow-400" />
|
||||||
|
<span className="text-sm text-yellow-600 dark:text-yellow-400">
|
||||||
|
You have reached the maximum number of servers you can
|
||||||
|
create, please upgrade your plan to add more servers.
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
<div className="flex flex-col gap-1.5 mt-4">
|
||||||
)}
|
<span className="text-base text-primary">
|
||||||
<div className="flex flex-col gap-1.5 mt-4">
|
Need Help? We are here to help you.
|
||||||
<span className="text-base text-primary">
|
</span>
|
||||||
Need Help? We are here to help you.
|
<span className="text-sm text-muted-foreground">
|
||||||
</span>
|
Join to our Discord server and we will help you.
|
||||||
<span className="text-sm text-muted-foreground">
|
</span>
|
||||||
Join to our Discord server and we will help you.
|
<Button className="rounded-full bg-[#5965F2] hover:bg-[#4A55E0] w-fit">
|
||||||
</span>
|
<Link
|
||||||
<Button className="rounded-full bg-[#5965F2] hover:bg-[#4A55E0] w-fit">
|
href="https://discord.gg/2tBnJ3jDJc"
|
||||||
<Link
|
aria-label="Dokploy on GitHub"
|
||||||
href="https://discord.gg/2tBnJ3jDJc"
|
target="_blank"
|
||||||
aria-label="Dokploy on GitHub"
|
className="flex flex-row items-center gap-2 text-white"
|
||||||
target="_blank"
|
>
|
||||||
className="flex flex-row items-center gap-2 text-white"
|
<svg
|
||||||
>
|
role="img"
|
||||||
<svg
|
className="h-6 w-6 fill-white"
|
||||||
role="img"
|
viewBox="0 0 24 24"
|
||||||
className="h-6 w-6 fill-white"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
viewBox="0 0 24 24"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
>
|
|
||||||
<path d="M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z" />
|
|
||||||
</svg>
|
|
||||||
Join Discord
|
|
||||||
</Link>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
{isLoading ? (
|
|
||||||
<span className="text-base text-muted-foreground flex flex-row gap-3 items-center justify-center min-h-[10vh]">
|
|
||||||
Loading...
|
|
||||||
<Loader2 className="animate-spin" />
|
|
||||||
</span>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
{products?.map((product) => {
|
|
||||||
const featured = true;
|
|
||||||
return (
|
|
||||||
<div key={product.id}>
|
|
||||||
<section
|
|
||||||
className={clsx(
|
|
||||||
"flex flex-col rounded-3xl border-dashed border-2 px-4 max-w-sm",
|
|
||||||
featured
|
|
||||||
? "order-first border py-8 lg:order-none"
|
|
||||||
: "lg:py-8",
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
{isAnnual && (
|
<path d="M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.946 2.4189-2.1568 2.4189Z" />
|
||||||
<div className="mb-4 flex flex-row items-center gap-2">
|
</svg>
|
||||||
<Badge>Recommended 🚀</Badge>
|
Join Discord
|
||||||
</div>
|
</Link>
|
||||||
)}
|
</Button>
|
||||||
{isAnnual ? (
|
</div>
|
||||||
<div className="flex flex-row gap-2 items-center">
|
{isLoading ? (
|
||||||
<p className="text-2xl font-semibold tracking-tight text-primary ">
|
<span className="text-base text-muted-foreground flex flex-row gap-3 items-center justify-center min-h-[10vh]">
|
||||||
${" "}
|
Loading...
|
||||||
{calculatePrice(
|
<Loader2 className="animate-spin" />
|
||||||
serverQuantity,
|
</span>
|
||||||
isAnnual,
|
) : (
|
||||||
).toFixed(2)}{" "}
|
<>
|
||||||
USD
|
{products?.map((product) => {
|
||||||
</p>
|
const featured = true;
|
||||||
|
|
return (
|
||||||
<p className="text-base font-semibold tracking-tight text-muted-foreground">
|
<div key={product.id}>
|
||||||
${" "}
|
<section
|
||||||
{(
|
className={clsx(
|
||||||
calculatePrice(serverQuantity, isAnnual) / 12
|
"flex flex-col rounded-3xl border-dashed border-2 px-4 max-w-sm",
|
||||||
).toFixed(2)}{" "}
|
featured
|
||||||
/ Month USD
|
? "order-first border py-8 lg:order-none"
|
||||||
</p>
|
: "lg:py-8",
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<p className="text-2xl font-semibold tracking-tight text-primary ">
|
|
||||||
${" "}
|
|
||||||
{calculatePrice(serverQuantity, isAnnual).toFixed(
|
|
||||||
2,
|
|
||||||
)}{" "}
|
|
||||||
USD
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
<h3 className="mt-5 font-medium text-lg text-primary">
|
|
||||||
{product.name}
|
|
||||||
</h3>
|
|
||||||
<p
|
|
||||||
className={clsx(
|
|
||||||
"text-sm",
|
|
||||||
featured ? "text-white" : "text-slate-400",
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{product.description}
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<ul
|
|
||||||
className={clsx(
|
|
||||||
" mt-4 flex flex-col gap-y-2 text-sm",
|
|
||||||
featured ? "text-white" : "text-slate-200",
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{[
|
|
||||||
"All the features of Dokploy",
|
|
||||||
"Unlimited deployments",
|
|
||||||
"Self-hosted on your own infrastructure",
|
|
||||||
"Full access to all deployment features",
|
|
||||||
"Dokploy integration",
|
|
||||||
"Backups",
|
|
||||||
"All Incoming features",
|
|
||||||
].map((feature) => (
|
|
||||||
<li
|
|
||||||
key={feature}
|
|
||||||
className="flex text-muted-foreground"
|
|
||||||
>
|
|
||||||
<CheckIcon />
|
|
||||||
<span className="ml-4">{feature}</span>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
<div className="flex flex-col gap-2 mt-4">
|
|
||||||
<div className="flex items-center gap-2 justify-center">
|
|
||||||
<span className="text-sm text-muted-foreground">
|
|
||||||
{serverQuantity} Servers
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center space-x-2">
|
|
||||||
<Button
|
|
||||||
disabled={serverQuantity <= 1}
|
|
||||||
variant="outline"
|
|
||||||
onClick={() => {
|
|
||||||
if (serverQuantity <= 1) return;
|
|
||||||
|
|
||||||
setServerQuantity(serverQuantity - 1);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<MinusIcon className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
<NumberInput
|
|
||||||
value={serverQuantity}
|
|
||||||
onChange={(e) => {
|
|
||||||
setServerQuantity(
|
|
||||||
e.target.value as unknown as number,
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
onClick={() => {
|
|
||||||
setServerQuantity(serverQuantity + 1);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<PlusIcon className="h-4 w-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
data?.subscriptions &&
|
|
||||||
data?.subscriptions?.length > 0
|
|
||||||
? "justify-between"
|
|
||||||
: "justify-end",
|
|
||||||
"flex flex-row items-center gap-2 mt-4",
|
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{admin?.user.stripeCustomerId && (
|
{isAnnual && (
|
||||||
<Button
|
<div className="mb-4 flex flex-row items-center gap-2">
|
||||||
variant="secondary"
|
<Badge>Recommended 🚀</Badge>
|
||||||
className="w-full"
|
|
||||||
onClick={async () => {
|
|
||||||
const session =
|
|
||||||
await createCustomerPortalSession();
|
|
||||||
|
|
||||||
window.open(session.url);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Manage Subscription
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{data?.subscriptions?.length === 0 && (
|
|
||||||
<div className="justify-end w-full">
|
|
||||||
<Button
|
|
||||||
className="w-full"
|
|
||||||
onClick={async () => {
|
|
||||||
handleCheckout(product.id);
|
|
||||||
}}
|
|
||||||
disabled={serverQuantity < 1}
|
|
||||||
>
|
|
||||||
Subscribe
|
|
||||||
</Button>
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
{isAnnual ? (
|
||||||
|
<div className="flex flex-row gap-2 items-center">
|
||||||
|
<p className="text-2xl font-semibold tracking-tight text-primary ">
|
||||||
|
${" "}
|
||||||
|
{calculatePrice(
|
||||||
|
serverQuantity,
|
||||||
|
isAnnual,
|
||||||
|
).toFixed(2)}{" "}
|
||||||
|
USD
|
||||||
|
</p>
|
||||||
|
|
|
||||||
|
<p className="text-base font-semibold tracking-tight text-muted-foreground">
|
||||||
|
${" "}
|
||||||
|
{(
|
||||||
|
calculatePrice(serverQuantity, isAnnual) / 12
|
||||||
|
).toFixed(2)}{" "}
|
||||||
|
/ Month USD
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className="text-2xl font-semibold tracking-tight text-primary ">
|
||||||
|
${" "}
|
||||||
|
{calculatePrice(serverQuantity, isAnnual).toFixed(
|
||||||
|
2,
|
||||||
|
)}{" "}
|
||||||
|
USD
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
<h3 className="mt-5 font-medium text-lg text-primary">
|
||||||
|
{product.name}
|
||||||
|
</h3>
|
||||||
|
<p
|
||||||
|
className={clsx(
|
||||||
|
"text-sm",
|
||||||
|
featured ? "text-white" : "text-slate-400",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{product.description}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ul
|
||||||
|
className={clsx(
|
||||||
|
" mt-4 flex flex-col gap-y-2 text-sm",
|
||||||
|
featured ? "text-white" : "text-slate-200",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{[
|
||||||
|
"All the features of Dokploy",
|
||||||
|
"Unlimited deployments",
|
||||||
|
"Self-hosted on your own infrastructure",
|
||||||
|
"Full access to all deployment features",
|
||||||
|
"Dokploy integration",
|
||||||
|
"Backups",
|
||||||
|
"All Incoming features",
|
||||||
|
].map((feature) => (
|
||||||
|
<li
|
||||||
|
key={feature}
|
||||||
|
className="flex text-muted-foreground"
|
||||||
|
>
|
||||||
|
<CheckIcon />
|
||||||
|
<span className="ml-4">{feature}</span>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
<div className="flex flex-col gap-2 mt-4">
|
||||||
|
<div className="flex items-center gap-2 justify-center">
|
||||||
|
<span className="text-sm text-muted-foreground">
|
||||||
|
{serverQuantity} Servers
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center space-x-2">
|
||||||
|
<Button
|
||||||
|
disabled={serverQuantity <= 1}
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
if (serverQuantity <= 1) return;
|
||||||
|
|
||||||
|
setServerQuantity(serverQuantity - 1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<MinusIcon className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
<NumberInput
|
||||||
|
value={serverQuantity}
|
||||||
|
onChange={(e) => {
|
||||||
|
setServerQuantity(
|
||||||
|
e.target.value as unknown as number,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
setServerQuantity(serverQuantity + 1);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<PlusIcon className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
data?.subscriptions &&
|
||||||
|
data?.subscriptions?.length > 0
|
||||||
|
? "justify-between"
|
||||||
|
: "justify-end",
|
||||||
|
"flex flex-row items-center gap-2 mt-4",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{admin?.user.stripeCustomerId && (
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
className="w-full"
|
||||||
|
onClick={async () => {
|
||||||
|
const session =
|
||||||
|
await createCustomerPortalSession();
|
||||||
|
|
||||||
|
window.open(session.url);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Manage Subscription
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{data?.subscriptions?.length === 0 && (
|
||||||
|
<div className="justify-end w-full">
|
||||||
|
<Button
|
||||||
|
className="w-full"
|
||||||
|
onClick={async () => {
|
||||||
|
handleCheckout(product.id);
|
||||||
|
}}
|
||||||
|
disabled={serverQuantity < 1}
|
||||||
|
>
|
||||||
|
Subscribe
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
);
|
||||||
</div>
|
})}
|
||||||
);
|
</>
|
||||||
})}
|
)}
|
||||||
</>
|
</div>
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
{admin?.user.stripeCustomerId && <ShowInvoices />}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,13 +2,6 @@ import { Download, ExternalLink, FileText, Loader2 } from "lucide-react";
|
|||||||
import type Stripe from "stripe";
|
import type Stripe from "stripe";
|
||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
|
||||||
Card,
|
|
||||||
CardContent,
|
|
||||||
CardDescription,
|
|
||||||
CardHeader,
|
|
||||||
CardTitle,
|
|
||||||
} from "@/components/ui/card";
|
|
||||||
import {
|
import {
|
||||||
Table,
|
Table,
|
||||||
TableBody,
|
TableBody,
|
||||||
@@ -63,97 +56,82 @@ export const ShowInvoices = () => {
|
|||||||
const { data: invoices, isLoading } = api.stripe.getInvoices.useQuery();
|
const { data: invoices, isLoading } = api.stripe.getInvoices.useQuery();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="bg-sidebar p-2.5 rounded-xl max-w-5xl mx-auto">
|
<div className="space-y-4">
|
||||||
<div className="rounded-xl bg-background shadow-md">
|
{isLoading ? (
|
||||||
<CardHeader>
|
<div className="flex items-center justify-center min-h-[20vh]">
|
||||||
<CardTitle className="text-xl flex flex-row gap-2">
|
<span className="text-base text-muted-foreground flex flex-row gap-3 items-center">
|
||||||
<FileText className="size-6 text-muted-foreground self-center" />
|
Loading invoices...
|
||||||
Invoices
|
<Loader2 className="animate-spin" />
|
||||||
</CardTitle>
|
</span>
|
||||||
<CardDescription>
|
</div>
|
||||||
View and download your billing invoices
|
) : invoices && invoices.length > 0 ? (
|
||||||
</CardDescription>
|
<div className="rounded-md border">
|
||||||
</CardHeader>
|
<Table>
|
||||||
<CardContent className="space-y-2 py-4 border-t">
|
<TableHeader>
|
||||||
{isLoading ? (
|
<TableRow>
|
||||||
<div className="flex items-center justify-center min-h-[20vh]">
|
<TableHead>Invoice</TableHead>
|
||||||
<span className="text-base text-muted-foreground flex flex-row gap-3 items-center">
|
<TableHead>Date</TableHead>
|
||||||
Loading invoices...
|
<TableHead>Due Date</TableHead>
|
||||||
<Loader2 className="animate-spin" />
|
<TableHead>Amount</TableHead>
|
||||||
</span>
|
<TableHead>Status</TableHead>
|
||||||
</div>
|
<TableHead className="text-right">Actions</TableHead>
|
||||||
) : invoices && invoices.length > 0 ? (
|
</TableRow>
|
||||||
<div className="rounded-md border">
|
</TableHeader>
|
||||||
<Table>
|
<TableBody>
|
||||||
<TableHeader>
|
{invoices.map((invoice) => (
|
||||||
<TableRow>
|
<TableRow key={invoice.id}>
|
||||||
<TableHead>Invoice</TableHead>
|
<TableCell className="font-medium">
|
||||||
<TableHead>Date</TableHead>
|
{invoice.number || invoice.id.slice(0, 12)}
|
||||||
<TableHead>Due Date</TableHead>
|
</TableCell>
|
||||||
<TableHead>Amount</TableHead>
|
<TableCell>{formatDate(invoice.created)}</TableCell>
|
||||||
<TableHead>Status</TableHead>
|
<TableCell>{formatDate(invoice.dueDate)}</TableCell>
|
||||||
<TableHead className="text-right">Actions</TableHead>
|
<TableCell>
|
||||||
</TableRow>
|
{formatAmount(invoice.amountDue, invoice.currency)}
|
||||||
</TableHeader>
|
</TableCell>
|
||||||
<TableBody>
|
<TableCell>{getStatusBadge(invoice.status)}</TableCell>
|
||||||
{invoices.map((invoice) => (
|
<TableCell className="text-right">
|
||||||
<TableRow key={invoice.id}>
|
<div className="flex justify-end gap-2">
|
||||||
<TableCell className="font-medium">
|
{invoice.hostedInvoiceUrl && (
|
||||||
{invoice.number || invoice.id.slice(0, 12)}
|
<Button
|
||||||
</TableCell>
|
variant="outline"
|
||||||
<TableCell>{formatDate(invoice.created)}</TableCell>
|
size="sm"
|
||||||
<TableCell>{formatDate(invoice.dueDate)}</TableCell>
|
onClick={() =>
|
||||||
<TableCell>
|
window.open(
|
||||||
{formatAmount(invoice.amountDue, invoice.currency)}
|
invoice.hostedInvoiceUrl || "",
|
||||||
</TableCell>
|
"_blank",
|
||||||
<TableCell>{getStatusBadge(invoice.status)}</TableCell>
|
)
|
||||||
<TableCell className="text-right">
|
}
|
||||||
<div className="flex justify-end gap-2">
|
>
|
||||||
{invoice.hostedInvoiceUrl && (
|
<ExternalLink className="h-4 w-4" />
|
||||||
<Button
|
</Button>
|
||||||
variant="outline"
|
)}
|
||||||
size="sm"
|
{invoice.invoicePdf && (
|
||||||
onClick={() =>
|
<Button
|
||||||
window.open(
|
variant="outline"
|
||||||
invoice.hostedInvoiceUrl || "",
|
size="sm"
|
||||||
"_blank",
|
onClick={() =>
|
||||||
)
|
window.open(invoice.invoicePdf || "", "_blank")
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<ExternalLink className="h-4 w-4" />
|
<Download className="h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{invoice.invoicePdf && (
|
</div>
|
||||||
<Button
|
</TableCell>
|
||||||
variant="outline"
|
</TableRow>
|
||||||
size="sm"
|
))}
|
||||||
onClick={() =>
|
</TableBody>
|
||||||
window.open(invoice.invoicePdf || "", "_blank")
|
</Table>
|
||||||
}
|
</div>
|
||||||
>
|
) : (
|
||||||
<Download className="h-4 w-4" />
|
<div className="flex flex-col items-center justify-center min-h-[20vh] gap-2">
|
||||||
</Button>
|
<FileText className="size-12 text-muted-foreground" />
|
||||||
)}
|
<p className="text-base text-muted-foreground">No invoices found</p>
|
||||||
</div>
|
<p className="text-sm text-muted-foreground">
|
||||||
</TableCell>
|
Your invoices will appear here once you have a subscription
|
||||||
</TableRow>
|
</p>
|
||||||
))}
|
</div>
|
||||||
</TableBody>
|
)}
|
||||||
</Table>
|
</div>
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="flex flex-col items-center justify-center min-h-[20vh] gap-2">
|
|
||||||
<FileText className="size-12 text-muted-foreground" />
|
|
||||||
<p className="text-base text-muted-foreground">
|
|
||||||
No invoices found
|
|
||||||
</p>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
Your invoices will appear here once you have a subscription
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</CardContent>
|
|
||||||
</div>
|
|
||||||
</Card>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import { IS_CLOUD } from "@dokploy/server/constants";
|
||||||
|
import { validateRequest } from "@dokploy/server/lib/auth";
|
||||||
|
import { createServerSideHelpers } from "@trpc/react-query/server";
|
||||||
|
import type { GetServerSidePropsContext } from "next";
|
||||||
|
import type { ReactElement } from "react";
|
||||||
|
import superjson from "superjson";
|
||||||
|
import { ShowBillingInvoices } from "@/components/dashboard/settings/billing/show-billing-invoices";
|
||||||
|
import { DashboardLayout } from "@/components/layouts/dashboard-layout";
|
||||||
|
import { appRouter } from "@/server/api/root";
|
||||||
|
|
||||||
|
const Page = () => {
|
||||||
|
return <ShowBillingInvoices />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Page;
|
||||||
|
|
||||||
|
Page.getLayout = (page: ReactElement) => {
|
||||||
|
return <DashboardLayout metaName="Invoices">{page}</DashboardLayout>;
|
||||||
|
};
|
||||||
|
export async function getServerSideProps(
|
||||||
|
ctx: GetServerSidePropsContext<{ serviceId: string }>,
|
||||||
|
) {
|
||||||
|
if (!IS_CLOUD) {
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
permanent: true,
|
||||||
|
destination: "/dashboard/projects",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const { req, res } = ctx;
|
||||||
|
const { user, session } = await validateRequest(req);
|
||||||
|
if (!user || user.role !== "owner") {
|
||||||
|
return {
|
||||||
|
redirect: {
|
||||||
|
permanent: true,
|
||||||
|
destination: "/",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const helpers = createServerSideHelpers({
|
||||||
|
router: appRouter,
|
||||||
|
ctx: {
|
||||||
|
req: req as any,
|
||||||
|
res: res as any,
|
||||||
|
db: null as any,
|
||||||
|
session: session as any,
|
||||||
|
user: user as any,
|
||||||
|
},
|
||||||
|
transformer: superjson,
|
||||||
|
});
|
||||||
|
|
||||||
|
await helpers.user.get.prefetch();
|
||||||
|
|
||||||
|
await helpers.settings.isCloud.prefetch();
|
||||||
|
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
trpcState: helpers.dehydrate(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user