Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

add invoices page

Steven Teycbba16817677
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.ts
new file mode 100644
index 0000000000..8094720dd7
--- /dev/null
+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.ts
@@ -0,0 +1,20 @@
+import { withWorkspace } from "@/lib/auth";
+import { stripe } from "@/lib/stripe";
+import { NextResponse } from "next/server";
+
+export const GET = withWorkspace(async ({ workspace }) => {
+ if (!workspace.stripeId) {
+ return NextResponse.json([]);
+ }
+
+ try {
+ const invoices = await stripe.invoices.list({
+ customer: workspace.stripeId,
+ });
+
+ return NextResponse.json(invoices.data);
+ } catch (error) {
+ console.error(error);
+ return NextResponse.json([]);
+ }
+});
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/invoices/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/invoices/page-client.tsx
new file mode 100644
index 0000000000..0a55ea9dcd
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/invoices/page-client.tsx
@@ -0,0 +1,113 @@
+"use client";
+
+import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
+import { Receipt2 } from "@dub/ui";
+import { fetcher } from "@dub/utils";
+import { ChevronLeft } from "lucide-react";
+import Link from "next/link";
+import { useParams } from "next/navigation";
+import { Stripe } from "stripe";
+import useSWR from "swr";
+
+export default function WorkspaceInvoicesClient() {
+ const { slug } = useParams();
+ const { data: invoices } = useSWR<Stripe.Invoice[]>(
+ `/api/workspaces/${slug}/billing/invoices`,
+ fetcher,
+ );
+
+ return (
+ <div className="rounded-lg border border-gray-200 bg-white">
+ <div className="flex flex-col items-start justify-between gap-y-4 p-6 md:p-8 xl:flex-row">
+ <div className="flex items-center gap-4">
+ <Link
+ href={`/${slug}/settings/billing`}
+ className="rounded-lg p-1.5 text-neutral-500 transition-colors hover:bg-neutral-100 hover:text-neutral-900"
+ >
+ <ChevronLeft className="size-5" />
+ </Link>
+ <div>
+ <h2 className="text-xl font-medium">Invoices</h2>
+ <p className="text-balance text-sm leading-normal text-gray-500">
+ A history of all your Dub invoices
+ </p>
+ </div>
+ </div>
+ </div>
+ <div className="grid divide-y divide-gray-200 border-t border-gray-200 p-4">
+ {invoices ? (
+ invoices.length > 0 ? (
+ invoices.map((invoice) => (
+ <InvoiceCard key={invoice.id} invoice={invoice} />
+ ))
+ ) : (
+ <AnimatedEmptyState
+ title="No invoices found"
+ description="You don't have any invoices yet"
+ cardContent={() => (
+ <>
+ <Receipt2 className="size-4 text-neutral-700" />
+ <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />
+ </>
+ )}
+ className="border-none"
+ />
+ )
+ ) : (
+ <>
+ <InvoiceCardSkeleton />
+ <InvoiceCardSkeleton />
+ <InvoiceCardSkeleton />
+ </>
+ )}
+ </div>
+ </div>
+ );
+}
+
+const InvoiceCard = ({ invoice }: { invoice: Stripe.Invoice }) => {
+ return (
+ <div className="flex items-center justify-between p-4">
+ <div className="text-sm">
+ <div className="font-medium">Dub subscription</div>
+ <div className="text-gray-500">
+ {new Date(invoice.created * 1000).toLocaleDateString("en-US", {
+ month: "short",
+ year: "numeric",
+ day: "numeric",
+ })}
+ </div>
+ </div>
+ <div className="text-sm">
+ <div className="font-medium">Total</div>
+ <div className="text-gray-500">
+ ${(invoice.amount_paid / 100).toFixed(2)}
+ </div>
+ </div>
+ <a
+ href={invoice.invoice_pdf || "#"}
+ target="_blank"
+ download
+ className="rounded-md border border-gray-200 px-3 py-1.5 text-sm transition-colors hover:bg-gray-100"
+ >
+ View
+ </a>
+ </div>
+ );
+};
+
+const InvoiceCardSkeleton = () => {
+ return (
+ <div className="flex items-center justify-between p-4">
+ <div className="flex flex-col gap-1 text-sm">
+ <div className="h-4 w-32 animate-pulse rounded-md bg-gray-200" />
+ <div className="h-4 w-24 animate-pulse rounded-md bg-gray-200" />
+ </div>
+ <div className="text-sm">
+ <div className="h-4 w-16 animate-pulse rounded-md bg-gray-200" />
+ <div className="h-4 w-20 animate-pulse rounded-md bg-gray-200" />
+ </div>
+ <div className="h-8 w-16 animate-pulse rounded-md bg-gray-200" />
+ </div>
+ );
+};
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/invoices/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/invoices/page.tsx
new file mode 100644
index 0000000000..211698d941
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/invoices/page.tsx
@@ -0,0 +1,10 @@
+import { Suspense } from "react";
+import WorkspaceInvoicesClient from "./page-client";
+
+export default function WorkspaceInvoices() {
+ return (
+ <Suspense>
+ <WorkspaceInvoicesClient />
+ </Suspense>
+ );
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx
index d2e376c02a..46268b0e19 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsx
@@ -61,7 +61,7 @@ export default function WorkspaceBillingClient() {
return (
<div className="rounded-lg border border-gray-200 bg-white">
- <div className="flex flex-col items-start justify-between gap-y-4 p-6 md:p-8 lg:flex-row">
+ <div className="flex flex-col items-start justify-between gap-y-4 p-6 md:p-8 xl:flex-row">
<div>
<h2 className="text-xl font-medium">Plan and Usage</h2>
<p className="mt-1 text-balance text-sm leading-normal text-gray-500">
@@ -86,7 +86,18 @@ export default function WorkspaceBillingClient() {
)}
</p>
</div>
- {stripeId && <ManageSubscriptionButton className="w-fit" />}
+ <div className="flex items-center gap-2">
+ <Link
+ href={`/${slug}/settings/billing/invoices`}
+ className={cn(
+ buttonVariants({ variant: "secondary" }),
+ "flex h-8 w-full items-center justify-center rounded-md border px-4 text-sm",
+ )}
+ >
+ View invoices
+ </Link>
+ {stripeId && <ManageSubscriptionButton />}
+ </div>
</div>
<div className="grid grid-cols-[minmax(0,1fr)] divide-y divide-gray-200 border-t border-gray-200">
<div>
diff --git a/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/page-client.tsx b/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/page-client.tsx
index 114ff7479d..f3a5f2aab4 100644
--- a/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/page-client.tsx
+++ b/apps/web/app/partners.dub.co/(dashboard)/settings/payouts/page-client.tsx
@@ -3,23 +3,16 @@
import useDotsUser from "@/lib/swr/use-dots-user";
import usePartnerProfile from "@/lib/swr/use-partner-profile";
import usePayoutMethods from "@/lib/swr/use-payout-methods";
-import LayoutLoader from "@/ui/layout/layout-loader";
import { usePayoutWithdrawSheet } from "@/ui/partners/payout-withdraw-sheet";
-import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
-import { CheckCircleFill, X } from "@/ui/shared/icons";
-import { Button, Modal, Note, SimpleTooltipContent, Tooltip } from "@dub/ui";
-import { GiftFill, GreekTemple } from "@dub/ui/src/icons";
+import { Note, SimpleTooltipContent, Tooltip } from "@dub/ui";
+import { GiftFill } from "@dub/ui/icons";
import {
cn,
currencyFormatter,
FREE_WITHDRAWAL_MINIMUM_BALANCE,
} from "@dub/utils";
import { useState } from "react";
-import { PartnerWithdrawalsActivity } from "./activity";
import { ComplianceButton } from "./compliance-button";
-import PayoutMethodCard, {
- PayoutMethodCardSkeleton,
-} from "./payout-method-card";
export function WalletSettingsPageClient() {
const { partner } = usePartnerProfile();
@@ -263,7 +256,7 @@ export function WalletSettingsPageClient() {
// )}
// </div>
// </>
- // );
+ // );
}
function FreeWithdrawalProgress({ balance }: { balance: number }) {