The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add payment method list
Steven Tey109b1fd1a899
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/route.tsnew file mode 100644index 0000000000..4eca1e3bca--- /dev/null+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/payment-methods/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 paymentMethods = await stripe.paymentMethods.list({+ customer: workspace.stripeId,+ });++ return NextResponse.json(paymentMethods.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.tsxindex 0a55ea9dcd..52cf982c11 100644--- 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@@ -17,7 +17,7 @@ export default function WorkspaceInvoicesClient() {);return (- <div className="rounded-lg border border-gray-200 bg-white">+ <div className="rounded-lg border border-neutral-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@@ -28,13 +28,13 @@ export default function WorkspaceInvoicesClient() {</Link><div><h2 className="text-xl font-medium">Invoices</h2>- <p className="text-balance text-sm leading-normal text-gray-500">+ <p className="text-balance text-sm leading-normal text-neutral-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">+ <div className="grid divide-y divide-neutral-200 border-t border-neutral-200 p-4">{invoices ? (invoices.length > 0 ? (invoices.map((invoice) => (@@ -70,7 +70,7 @@ const InvoiceCard = ({ invoice }: { invoice: Stripe.Invoice }) => {<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">+ <div className="text-neutral-500">{new Date(invoice.created * 1000).toLocaleDateString("en-US", {month: "short",year: "numeric",@@ -80,7 +80,7 @@ const InvoiceCard = ({ invoice }: { invoice: Stripe.Invoice }) => {</div><div className="text-sm"><div className="font-medium">Total</div>- <div className="text-gray-500">+ <div className="text-neutral-500">${(invoice.amount_paid / 100).toFixed(2)}</div></div>@@ -88,7 +88,7 @@ const InvoiceCard = ({ invoice }: { invoice: Stripe.Invoice }) => {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"+ className="rounded-md border border-neutral-200 px-3 py-1.5 text-sm transition-colors hover:bg-neutral-100">View</a>@@ -100,14 +100,14 @@ 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 className="h-4 w-32 animate-pulse rounded-md bg-neutral-200" />+ <div className="h-4 w-24 animate-pulse rounded-md bg-neutral-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 className="h-4 w-16 animate-pulse rounded-md bg-neutral-200" />+ <div className="h-4 w-20 animate-pulse rounded-md bg-neutral-200" /></div>- <div className="h-8 w-16 animate-pulse rounded-md bg-gray-200" />+ <div className="h-8 w-16 animate-pulse rounded-md bg-neutral-200" /></div>);};diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page.tsxindex 52c3f7f8c7..6302320efe 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page.tsx@@ -1,10 +1,11 @@-import { Suspense } from "react";-import WorkspaceBillingClient from "./page-client";+import PaymentMethods from "./payment-methods";+import PlanUsage from "./plan-usage";export default function WorkspaceBilling() {return (- <Suspense>- <WorkspaceBillingClient />- </Suspense>+ <div className="grid gap-8">+ <PlanUsage />+ <PaymentMethods />+ </div>);}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/payment-methods.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/payment-methods.tsxnew file mode 100644index 0000000000..205cbef50f--- /dev/null+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/payment-methods.tsx@@ -0,0 +1,140 @@+"use client";++import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";+import { CreditCard, GreekTemple, StripeLink } from "@dub/ui/icons";+import { cn, fetcher } from "@dub/utils";+import { useParams } from "next/navigation";+import { Stripe } from "stripe";+import useSWR from "swr";++export default function PaymentMethods() {+ const { slug } = useParams();+ const { data: paymentMethods } = useSWR<Stripe.PaymentMethod[]>(+ `/api/workspaces/${slug}/billing/payment-methods`,+ fetcher,+ );++ return (+ <div className="rounded-lg border border-neutral-200 bg-white">+ <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">Payment methods</h2>+ <p className="text-balance text-sm leading-normal text-neutral-500">+ Manage your payment methods on Dub+ </p>+ </div>+ </div>+ <div className="grid gap-4 border-t border-neutral-200 p-6">+ {paymentMethods ? (+ paymentMethods.length > 0 ? (+ paymentMethods.map((paymentMethod) => (+ <PaymentMethodCard+ key={paymentMethod.id}+ paymentMethod={paymentMethod}+ />+ ))+ ) : (+ <AnimatedEmptyState+ title="No payment methods found"+ description="You haven't added any payment methods yet"+ cardContent={() => (+ <>+ <CreditCard className="size-4 text-neutral-700" />+ <div className="h-2.5 w-24 min-w-0 rounded-sm bg-neutral-200" />+ </>+ )}+ className="border-none md:min-h-[250px]"+ />+ )+ ) : (+ <>+ <PaymentMethodCardSkeleton />+ <PaymentMethodCardSkeleton />+ <PaymentMethodCardSkeleton />+ </>+ )}+ </div>+ </div>+ );+}++const PaymentMethodsDetails = (paymentMethod: Stripe.PaymentMethod) =>+ [+ {+ type: "card",+ title: "Card",+ icon: CreditCard,+ description: paymentMethod.card+ ? `Connected ${paymentMethod.card.brand} ***${paymentMethod.card.last4}`+ : "No card connected",+ },+ {+ type: "us_bank_account",+ title: "ACH Debit",+ icon: GreekTemple,+ description: paymentMethod.us_bank_account+ ? `Connected ${paymentMethod.us_bank_account.account_holder_type} account ending in ${paymentMethod.us_bank_account.last4}`+ : "No ACH Debit connected",+ },+ {+ type: "link",+ title: "Link",+ icon: StripeLink,+ iconBgColor: "bg-green-100",+ description: `Connected Link account ${paymentMethod.link?.email}`,+ },+ ] satisfies {+ type: Stripe.PaymentMethod.Type;+ title: string;+ icon: React.ElementType;+ description: string;+ iconBgColor?: string;+ }[];++const PaymentMethodCard = ({+ paymentMethod,+}: {+ paymentMethod: Stripe.PaymentMethod;+}) => {+ const {+ title,+ icon: Icon,+ iconBgColor,+ description,+ } = PaymentMethodsDetails(paymentMethod).find(+ (method) => method.type === paymentMethod.type,+ ) || PaymentMethodsDetails(paymentMethod)[0];++ return (+ <div className="flex items-center justify-between rounded-lg border border-neutral-200 p-4">+ <div className="flex items-center gap-4">+ <div+ className={cn(+ "flex size-12 items-center justify-center rounded-lg",+ iconBgColor,+ )}+ >+ <Icon className="size-6 text-neutral-700" />+ </div>+ <div>+ <p className="font-medium text-neutral-900">{title}</p>+ <p className="text-sm text-neutral-500">{description}</p>+ </div>+ </div>+ </div>+ );+};++const PaymentMethodCardSkeleton = () => {+ return (+ <div className="flex items-center justify-between rounded-lg border border-neutral-200 p-4">+ <div className="flex items-center gap-4">+ <div className="flex size-12 animate-pulse items-center justify-center rounded-lg bg-neutral-200" />+ <div>+ <div className="h-5 w-24 animate-pulse rounded-md bg-neutral-200" />+ <div className="mt-1 h-4 w-32 animate-pulse rounded-md bg-neutral-200" />+ </div>+ </div>+ </div>+ );+};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/plan-usage.tsxsimilarity index 91%rename from apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/page-client.tsxrename to apps/web/app/app.dub.co/(dashboard)/[slug]/settings/billing/plan-usage.tsxindex 46268b0e19..b04053a53a 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/plan-usage.tsx@@ -20,7 +20,7 @@ import Link from "next/link";import { CSSProperties, useMemo } from "react";import { UsageChart } from "./usage-chart";-export default function WorkspaceBillingClient() {+export default function PlanUsage() {const {slug,plan,@@ -60,16 +60,16 @@ export default function WorkspaceBillingClient() {}, [billingCycleStart]);return (- <div className="rounded-lg border border-gray-200 bg-white">+ <div className="rounded-lg border border-neutral-200 bg-white"><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">+ <p className="mt-1 text-balance text-sm leading-normal text-neutral-500">You are currently on the{" "}{plan ? (<PlanBadge plan={plan} />) : (- <span className="rounded-full bg-gray-200 px-2 py-0.5 text-xs text-gray-200">+ <span className="rounded-full bg-neutral-200 px-2 py-0.5 text-xs text-neutral-200">load</span>)}{" "}@@ -99,7 +99,7 @@ export default function WorkspaceBillingClient() {{stripeId && <ManageSubscriptionButton />}</div></div>- <div className="grid grid-cols-[minmax(0,1fr)] divide-y divide-gray-200 border-t border-gray-200">+ <div className="grid grid-cols-[minmax(0,1fr)] divide-y divide-neutral-200 border-t border-neutral-200"><div><divclassName={cn(@@ -136,7 +136,7 @@ export default function WorkspaceBillingClient() {<UsageChart /></div></div>- <div className="grid grid-cols-1 divide-y divide-gray-200 sm:divide-x sm:divide-y-0 md:grid-cols-3">+ <div className="grid grid-cols-1 divide-y divide-neutral-200 sm:divide-x sm:divide-y-0 md:grid-cols-3"><UsageCategorytitle="Custom Domains"icon={Globe}@@ -158,15 +158,15 @@ export default function WorkspaceBillingClient() {</div></div>{plan !== "enterprise" && (- <div className="flex flex-col items-center justify-between space-y-3 border-t border-gray-200 px-6 py-4 text-center md:flex-row md:space-y-0 md:px-8 md:text-left">+ <div className="flex flex-col items-center justify-between space-y-3 border-t border-neutral-200 px-6 py-4 text-center md:flex-row md:space-y-0 md:px-8 md:text-left">{plan ? (- <p className="text-sm text-gray-500">+ <p className="text-sm text-neutral-500">{plan === "business max"? "Need more clicks or links? Contact us for an Enterprise quote.": `For higher limits, upgrade to the ${nextPlan.name} plan.`}</p>) : (- <div className="h-3 w-28 animate-pulse rounded-full bg-gray-200" />+ <div className="h-3 w-28 animate-pulse rounded-full bg-neutral-200" />)}<div>{plan ? (@@ -180,7 +180,7 @@ export default function WorkspaceBillingClient() {Upgrade to {nextPlan.name}</Link>) : (- <div className="h-10 w-24 animate-pulse rounded-md bg-gray-200" />+ <div className="h-10 w-24 animate-pulse rounded-md bg-neutral-200" />)}</div></div>@@ -253,7 +253,7 @@ function UsageTabCard({}/>) : (- <div className="h-5 w-16 animate-pulse rounded-md bg-gray-200" />+ <div className="h-5 w-16 animate-pulse rounded-md bg-neutral-200" />)}</div><div className="mt-5">@@ -289,7 +289,7 @@ function UsageTabCard({: `${prefix}${nFormatter(remaining, { full: true })} remaining of ${prefix}${nFormatter(limit, { full: limit < 1000000000 })}`}</span>) : (- <div className="h-4 w-20 animate-pulse rounded-md bg-gray-200" />+ <div className="h-4 w-20 animate-pulse rounded-md bg-neutral-200" />)}</div></button>@@ -314,10 +314,10 @@ function UsageCategory(data: {{usage || usage === 0 ? (<p>{nFormatter(usage, { full: true })}</p>) : (- <div className="size-6 animate-pulse rounded-md bg-gray-200" />+ <div className="size-6 animate-pulse rounded-md bg-neutral-200" />)}<span>/</span>- <p className="text-gray-400">+ <p className="text-neutral-400">{usageLimit && usageLimit >= 1000000000? "∞": nFormatter(usageLimit, { full: true })}diff --git a/packages/ui/src/icons/nucleo/credit-card.tsx b/packages/ui/src/icons/nucleo/credit-card.tsxnew file mode 100644index 0000000000..bd71fd8df2--- /dev/null+++ b/packages/ui/src/icons/nucleo/credit-card.tsx@@ -0,0 +1,63 @@+import { SVGProps } from "react";++export function CreditCard(props: SVGProps<SVGSVGElement>) {+ return (+ <svg+ height="18"+ width="18"+ viewBox="0 0 18 18"+ xmlns="http://www.w3.org/2000/svg"+ {...props}+ >+ <g fill="currentColor">+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="1.75"+ x2="16.25"+ y1="7.25"+ y2="7.25"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="4.25"+ x2="7.25"+ y1="11.25"+ y2="11.25"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="12.75"+ x2="13.75"+ y1="11.25"+ y2="11.25"+ />+ <rect+ height="10.5"+ width="14.5"+ fill="none"+ rx="2"+ ry="2"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ transform="translate(18 18) rotate(180)"+ x="1.75"+ y="3.75"+ />+ </g>+ </svg>+ );+}diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.tsindex 7355d433ed..2782e598eb 100644--- a/packages/ui/src/icons/nucleo/index.ts+++ b/packages/ui/src/icons/nucleo/index.ts@@ -45,6 +45,7 @@ export * from "./connected-dots";export * from "./connected-dots-fill";export * from "./connected-dots4";export * from "./connections3";+export * from "./credit-card";export * from "./crosshairs3";export * from "./cube";export * from "./cube-settings";diff --git a/packages/ui/src/icons/payout-platforms/index.ts b/packages/ui/src/icons/payout-platforms/index.tsindex 4558bccd2e..52244924ef 100644--- a/packages/ui/src/icons/payout-platforms/index.ts+++ b/packages/ui/src/icons/payout-platforms/index.ts@@ -2,4 +2,5 @@ export * from "./airtm";export * from "./cash-app";export * from "./payoneer";export * from "./paypal";+export * from "./stripe-link";export * from "./venmo";diff --git a/packages/ui/src/icons/payout-platforms/stripe-link.tsx b/packages/ui/src/icons/payout-platforms/stripe-link.tsxnew file mode 100644index 0000000000..ebbd583551--- /dev/null+++ b/packages/ui/src/icons/payout-platforms/stripe-link.tsx@@ -0,0 +1,21 @@+export function StripeLink({ className }: { className?: string }) {+ return (+ <svg+ width="24"+ height="24"+ viewBox="0 0 24 24"+ fill="none"+ xmlns="http://www.w3.org/2000/svg"+ className={className}+ >+ <path+ d="M12 24C18.6274 24 24 18.6274 24 12C24 5.37257 18.6274 0 12 0C5.37259 0 0 5.37257 0 12C0 18.6274 5.37259 24 12 24Z"+ fill="#00D66F"+ />+ <path+ d="M11.4479 4.80005H7.74707C8.46707 7.80965 10.5695 10.3824 13.1999 12C10.5647 13.6176 8.46707 16.1904 7.74707 19.2H11.4479C12.3647 16.416 14.9039 13.9968 18.0239 13.5024V10.4929C14.8991 10.0033 12.3599 7.58405 11.4479 4.80005Z"+ fill="#011E0F"+ />+ </svg>+ );+}