The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix StatusBadge, improve invoice/retry-failed
Steven Teycbf2171a46e7
diff --git a/apps/web/app/(ee)/api/cron/invoices/retry-failed/route.ts b/apps/web/app/(ee)/api/cron/invoices/retry-failed/route.tsindex 5eaa451e70..1c2320ec4d 100644--- a/apps/web/app/(ee)/api/cron/invoices/retry-failed/route.ts+++ b/apps/web/app/(ee)/api/cron/invoices/retry-failed/route.ts@@ -2,6 +2,7 @@ import { handleAndReturnErrorResponse } from "@/lib/api/errors";import { verifyQstashSignature } from "@/lib/cron/verify-qstash";import { prisma } from "@/lib/prisma";import { createPaymentIntent } from "@/lib/stripe/create-payment-intent";+import { ACME_WORKSPACE_ID, DUB_WORKSPACE_ID } from "@dub/utils";import * as z from "zod/v4";export const dynamic = "force-dynamic";@@ -63,13 +64,32 @@ export async function POST(req: Request) {return new Response(`Only domain renewals can be retried at this time.`);}- if (!invoice.workspace.stripeId) {- console.log(`Workspace ${invoice.workspace.id} has no stripeId.`);- return new Response(`Workspace ${invoice.workspace.id} has no stripeId.`);+ let { workspace } = invoice;++ // If Acme workspace, use Dub workspace stripeId+ if (workspace.id === ACME_WORKSPACE_ID) {+ const dubWorkspace = await prisma.project.findUniqueOrThrow({+ where: {+ id: DUB_WORKSPACE_ID,+ },+ select: {+ stripeId: true,+ },+ });++ workspace = {+ ...workspace,+ stripeId: dubWorkspace.stripeId,+ };+ }++ if (!workspace.stripeId) {+ console.log(`Workspace ${workspace.id} has no stripeId.`);+ return new Response(`Workspace ${workspace.id} has no stripeId.`);}await createPaymentIntent({- stripeId: invoice.workspace.stripeId,+ stripeId: workspace.stripeId,amount: invoice.total,invoiceId: invoice.id,statementDescriptor: "DUB.CO DOMAIN RENEWAL",diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page-client.tsxdeleted file mode 100644index af440d2218..0000000000--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page-client.tsx+++ /dev/null@@ -1,346 +0,0 @@-"use client";--import { INVOICE_PAYMENT_METHODS } from "@/lib/constants/payouts";-import useWorkspace from "@/lib/swr/use-workspace";-import { InvoiceProps } from "@/lib/types";-import { PayoutStatusBadges } from "@/ui/partners/payout-status-badges";-import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";-import {- buttonVariants,- DynamicTooltipWrapper,- Receipt2,- StatusBadge,- TabSelect,- useRouterStuff,-} from "@dub/ui";-import { cn, currencyFormatter, fetcher } from "@dub/utils";-import { AlertCircle } from "lucide-react";-import { useMemo } from "react";-import useSWR from "swr";--const INVOICE_TYPES = [- { id: "subscription", label: "Subscription" },- { id: "partnerPayout", label: "Partner payouts" },- { id: "domainRenewal", label: "Domain renewals" },-];--export default function WorkspaceInvoicesClient() {- const { slug } = useWorkspace();- const { searchParams, queryParams } = useRouterStuff();-- const selectedInvoiceType = useMemo(() => {- let type = searchParams.get("type");-- if (type === "payout") {- type = "partnerPayout";- }-- return INVOICE_TYPES.find((t) => t.id === type) || INVOICE_TYPES[0];- }, [searchParams]);-- const { data: invoices } = useSWR<InvoiceProps[]>(- `/api/workspaces/${slug}/billing/invoices?type=${selectedInvoiceType.id}`,- fetcher,- );-- const displayPaymentMethod = selectedInvoiceType.id === "partnerPayout";-- 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 md:pb-2 lg:flex-row">- <div>- <h2 className="text-xl font-medium">Invoices</h2>- <p className="text-balance text-sm leading-normal text-neutral-500">- A history of all your Dub invoices- </p>- </div>- </div>- <TabSelect- className="px-4 md:px-5"- options={INVOICE_TYPES}- selected={selectedInvoiceType.id}- onSelect={(id) => {- queryParams({- set: {- type: id,- },- });- }}- />- <div className="grid divide-y divide-neutral-200 border-t border-neutral-200">- {invoices ? (- invoices.length > 0 ? (- invoices.map((invoice) => (- <InvoiceCard- key={invoice.id}- invoice={invoice}- displayPaymentMethod={displayPaymentMethod}- />- ))- ) : (- <AnimatedEmptyState- title={`No ${selectedInvoiceType.label.toLowerCase()} invoices found`}- description={`You don't have any ${selectedInvoiceType.label.toLowerCase()} 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 displayPaymentMethod={displayPaymentMethod} />- <InvoiceCardSkeleton displayPaymentMethod={displayPaymentMethod} />- <InvoiceCardSkeleton displayPaymentMethod={displayPaymentMethod} />- </>- )}- </div>- </div>- );-}--const InvoiceCard = ({- invoice,- displayPaymentMethod = false,-}: {- invoice: InvoiceProps;- displayPaymentMethod: boolean;-}) => {- const invoicePaymentMethod =- INVOICE_PAYMENT_METHODS[invoice.paymentMethod ?? "ach"];-- return (- <div className="px-3 py-4 xl:px-12">- {/* Mobile layout */}- <div className="block xl:hidden">- <div className="mb-4 flex items-start justify-between">- <div className="text-sm">- <div className="font-medium">{invoice.description}</div>- <div className="text-neutral-500">- {new Date(invoice.createdAt).toLocaleDateString("en-US", {- month: "short",- year: "numeric",- day: "numeric",- })}- </div>- </div>- <div className="flex items-center">- {invoice.pdfUrl && invoice.status !== "failed" ? (- <a- href={invoice.pdfUrl}- target="_blank"- className={cn(- buttonVariants({ variant: "secondary" }),- "flex h-9 items-center justify-center rounded-md border px-3 text-sm",- )}- >- <span>View invoice</span>- </a>- ) : (- <div />- )}- </div>- </div>-- <div className="space-y-4">- <div className="text-left text-sm">- <div className="font-medium">Total</div>- <div className="flex items-center gap-1.5 text-neutral-500">- <span className="text-sm font-medium">- {currencyFormatter(invoice.total)}- </span>- {invoice.status &&- (() => {- const badge = PayoutStatusBadges[invoice.status];- return (- <DynamicTooltipWrapper- tooltipProps={- invoice.failedReason- ? { content: invoice.failedReason }- : undefined- }- >- <StatusBadge- icon={invoice.status === "failed" ? AlertCircle : null}- variant={badge.variant}- className="rounded-md py-0.5"- >- {badge.label}- </StatusBadge>- </DynamicTooltipWrapper>- );- })()}- </div>- </div>-- {displayPaymentMethod && (- <div className="text-left text-sm">- <div className="font-medium">Method</div>- {invoicePaymentMethod ? (- <div className="flex items-center gap-1.5 text-neutral-500">- <div className="text-content-subtle text-sm font-medium">- {invoicePaymentMethod.label}- </div>- <StatusBadge- icon={null}- variant="neutral"- className="rounded-md py-0.5 text-xs font-semibold text-neutral-700"- >- {invoicePaymentMethod.duration}- </StatusBadge>- </div>- ) : (- <span className="text-neutral-500">-</span>- )}- </div>- )}- </div>- </div>-- {/* Desktop layout */}- <div className="hidden xl:grid xl:grid-cols-4 xl:gap-4">- <div className="text-sm xl:col-span-1">- <div className="font-medium">{invoice.description}</div>- <div className="text-neutral-500">- {new Date(invoice.createdAt).toLocaleDateString("en-US", {- month: "short",- year: "numeric",- day: "numeric",- })}- </div>- </div>-- <div className="text-left text-sm sm:col-span-1">- <div className="font-medium">Total</div>- <div className="flex items-center gap-1.5 text-neutral-500">- <span className="text-sm font-medium">- {currencyFormatter(invoice.total)}- </span>- {invoice.status &&- (() => {- const badge = PayoutStatusBadges[invoice.status];- return (- <DynamicTooltipWrapper- tooltipProps={- invoice.failedReason- ? { content: invoice.failedReason }- : undefined- }- >- <StatusBadge- icon={invoice.status === "failed" ? AlertCircle : null}- variant={badge.variant}- className="rounded-md py-0.5"- >- {badge.label}- </StatusBadge>- </DynamicTooltipWrapper>- );- })()}- </div>- </div>-- {displayPaymentMethod && (- <div className="text-left text-sm sm:col-span-1 lg:block">- <div className="font-medium">Method</div>- {invoicePaymentMethod ? (- <div className="flex items-center gap-1.5 text-neutral-500">- <div className="text-content-subtle text-sm font-medium">- {invoicePaymentMethod.label}- </div>- <StatusBadge- icon={null}- variant="neutral"- className="rounded-md py-0.5 text-xs font-semibold text-neutral-700"- >- {invoicePaymentMethod.duration}- </StatusBadge>- </div>- ) : (- <span className="text-neutral-500">-</span>- )}- </div>- )}-- <div className="flex items-center justify-end sm:col-span-1 sm:justify-end">- {invoice.pdfUrl && invoice.status !== "failed" ? (- <a- href={invoice.pdfUrl}- target="_blank"- className={cn(- buttonVariants({ variant: "secondary" }),- "flex h-9 items-center justify-center rounded-md border px-3 text-sm",- )}- >- <span>View invoice</span>- </a>- ) : (- <div />- )}- </div>- </div>- </div>- );-};--const InvoiceCardSkeleton = ({- displayPaymentMethod = false,-}: {- displayPaymentMethod?: boolean;-}) => {- return (- <div className="px-4 py-6 sm:px-12">- {/* Mobile skeleton */}- <div className="block sm:hidden">- <div className="mb-4 flex items-start justify-between">- <div className="flex flex-col gap-1 text-sm">- <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="h-9 w-24 animate-pulse rounded-md bg-neutral-200" />- </div>-- <div className="space-y-4">- <div className="flex flex-col gap-1">- <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>-- {displayPaymentMethod && (- <div className="flex flex-col gap-1">- <div className="h-4 w-12 animate-pulse rounded-md bg-neutral-200" />- <div className="h-4 w-20 animate-pulse rounded-md bg-neutral-200" />- </div>- )}- </div>- </div>-- {/* Desktop skeleton */}- <div className="hidden sm:grid sm:grid-cols-3 sm:gap-4 lg:grid-cols-4">- <div className="flex flex-col gap-1 text-sm sm:col-span-1">- <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="flex flex-col gap-1 sm:col-span-1">- <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>-- {displayPaymentMethod && (- <div className="flex flex-col gap-1 sm:col-span-1">- <div className="h-4 w-12 animate-pulse rounded-md bg-neutral-200" />- <div className="h-4 w-20 animate-pulse rounded-md bg-neutral-200" />- </div>- )}-- <div className="flex items-center justify-end sm:col-span-1 sm:justify-end">- <div className="h-9 w-24 animate-pulse rounded-md bg-neutral-200" />- </div>- </div>- </div>- );-};diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page.tsxindex 0cd8e18938..50a5160b7d 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/page.tsx@@ -10,7 +10,6 @@ import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";import {buttonVariants,ChevronRight,- DynamicTooltipWrapper,Receipt2,StatusBadge,TabSelect,@@ -175,21 +174,16 @@ const InvoiceCard = ({(() => {const badge = PayoutStatusBadges[invoice.status];return (- <DynamicTooltipWrapper- tooltipProps={- invoice.failedReason- ? { content: invoice.failedReason }- : undefined- }+ <StatusBadge+ icon={invoice.status === "failed" ? AlertCircle : null}+ variant={badge.variant}+ className="rounded-md py-0.5"+ {...(invoice.status === "failed" && invoice.failedReason+ ? { tooltip: invoice.failedReason }+ : {})}>- <StatusBadge- icon={invoice.status === "failed" ? AlertCircle : null}- variant={badge.variant}- className="rounded-md py-0.5"- >- {badge.label}- </StatusBadge>- </DynamicTooltipWrapper>+ {badge.label}+ </StatusBadge>);})()}</div>@@ -242,21 +236,16 @@ const InvoiceCard = ({(() => {const badge = PayoutStatusBadges[invoice.status];return (- <DynamicTooltipWrapper- tooltipProps={- invoice.failedReason- ? { content: invoice.failedReason }- : undefined- }+ <StatusBadge+ icon={invoice.status === "failed" ? AlertCircle : null}+ variant={badge.variant}+ className="rounded-md py-0.5"+ {...(invoice.status === "failed" && invoice.failedReason+ ? { tooltip: invoice.failedReason }+ : {})}>- <StatusBadge- icon={invoice.status === "failed" ? AlertCircle : null}- variant={badge.variant}- className="rounded-md py-0.5"- >- {badge.label}- </StatusBadge>- </DynamicTooltipWrapper>+ {badge.label}+ </StatusBadge>);})()}</div>diff --git a/packages/ui/src/status-badge.tsx b/packages/ui/src/status-badge.tsxindex 738e78d225..1af95a5652 100644--- a/packages/ui/src/status-badge.tsx+++ b/packages/ui/src/status-badge.tsx@@ -55,7 +55,6 @@ function StatusBadge({size,icon,tooltip,- onClick,children,...props}: BadgeProps) {@@ -70,11 +69,8 @@ function StatusBadge({className={cn(statusBadgeVariants({ variant, size }),tooltip && "cursor-help",- onClick &&- "cursor-pointer select-none transition-[filter] duration-150 hover:brightness-75 hover:saturate-[1.25]",className,)}- onClick={onClick}{...props}>{Icon && <Icon className="h-3 w-3 shrink-0" />}