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.

Updates to `staging`/`sandbox` workspaces/progarms

Steven Tey42e563d8c1ff
diff --git a/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/domain-renewal-invoice.tsx b/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/domain-renewal-invoice.tsx
index c0d9e31175..10204312a4 100644
--- a/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/domain-renewal-invoice.tsx
+++ b/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/domain-renewal-invoice.tsx
@@ -13,6 +13,7 @@ import {
} from "@react-pdf/renderer";
import { createTw } from "react-pdf-tailwind";
import Stripe from "stripe";
+import { InvoiceEnvironmentBanner } from "./environment-banner";
const tw = createTw({
theme: {
@@ -27,7 +28,7 @@ export async function DomainRenewalInvoice({
workspace,
}: {
invoice: Invoice;
- workspace: Pick<Project, "id" | "name" | "stripeId">;
+ workspace: Pick<Project, "id" | "name" | "stripeId" | "environment">;
}) {
const domains = await prisma.registeredDomain.findMany({
where: {
@@ -118,6 +119,8 @@ export async function DomainRenewalInvoice({
return await renderToBuffer(
<Document>
<Page size="A4" style={tw("p-20 bg-white")}>
+ <InvoiceEnvironmentBanner environment={workspace.environment} />
+
<View style={tw("flex-row justify-between items-center mb-10")}>
<Image src={DUB_WORDMARK} style={tw("w-20 h-10")} />
</View>
diff --git a/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/environment-banner.tsx b/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/environment-banner.tsx
new file mode 100644
index 0000000000..84bc829154
--- /dev/null
+++ b/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/environment-banner.tsx
@@ -0,0 +1,39 @@
+import { capitalize } from "@dub/utils";
+import { WorkspaceEnvironment } from "@prisma/client";
+import { Image, Text, View } from "@react-pdf/renderer";
+import { createTw } from "react-pdf-tailwind";
+
+const tw = createTw({});
+
+export function InvoiceEnvironmentBanner({
+ environment,
+}: {
+ environment: WorkspaceEnvironment;
+}) {
+ if (environment === "production") {
+ return null;
+ }
+
+ return (
+ <View
+ style={tw(
+ `mb-4 flex-row items-center justify-between rounded-lg px-4 py-2 ${
+ environment === "staging" ? "bg-amber-200" : "bg-blue-200"
+ }`,
+ )}
+ >
+ <View style={tw("flex-row items-center")}>
+ <Image
+ src="https://assets.dub.co/misc/icons/nucleo/isolated-cube.png"
+ style={tw("h-4 w-4")}
+ />
+ <Text style={tw("ml-1.5 text-sm font-semibold text-neutral-800")}>
+ {capitalize(environment)}
+ </Text>
+ </View>
+ <Text style={tw("text-sm font-medium text-neutral-800")}>
+ No real money or payouts in {environment}.
+ </Text>
+ </View>
+ );
+}
diff --git a/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/partner-payout-invoice.tsx b/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/partner-payout-invoice.tsx
index 29d9804b7a..49d81b6db3 100644
--- a/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/partner-payout-invoice.tsx
+++ b/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/partner-payout-invoice.tsx
@@ -23,6 +23,7 @@ import {
import { endOfMonth, startOfMonth } from "date-fns";
import { createTw } from "react-pdf-tailwind";
import Stripe from "stripe";
+import { InvoiceEnvironmentBanner } from "./environment-banner";
const tw = createTw({
theme: {
@@ -37,7 +38,10 @@ export async function PartnerPayoutInvoice({
workspace,
}: {
invoice: Invoice;
- workspace: Pick<Project, "id" | "name" | "slug" | "stripeId">;
+ workspace: Pick<
+ Project,
+ "id" | "name" | "slug" | "stripeId" | "environment"
+ >;
}) {
const firstEightPayouts = await prisma.payout.findMany({
where: {
@@ -237,6 +241,8 @@ export async function PartnerPayoutInvoice({
return await renderToBuffer(
<Document>
<Page size="A4" style={tw("p-20 bg-white")}>
+ <InvoiceEnvironmentBanner environment={workspace.environment} />
+
<View style={tw("flex-row justify-between items-center mb-4")}>
<Image src={DUB_WORDMARK} style={tw("w-20 h-10")} />
</View>
diff --git a/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/route.tsx b/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/route.tsx
index a96a7ae56a..6554ce9b59 100644
--- a/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/route.tsx
+++ b/apps/web/app/(ee)/app.dub.co/invoices/[invoiceId]/route.tsx
@@ -20,6 +20,7 @@ export const GET = withSession(async ({ session, params }) => {
name: true,
slug: true,
stripeId: true,
+ environment: true,
},
},
},
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.ts
index ed25633193..8c4428a3c2 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/billing/invoices/route.ts
@@ -17,21 +17,24 @@ const querySchema = z.object({
// TODO: move to GET /invoices
export const GET = withWorkspace(
async ({ workspace, searchParams }) => {
- if (!workspace.stripeId) {
- return NextResponse.json([]);
- }
-
const { type, stripeStatus } = querySchema.parse(searchParams);
- const invoices =
- type === "subscription"
- ? await getSubscriptionInvoices(workspace.stripeId, {
- status: stripeStatus,
- })
- : await getOtherInvoices({
- workspaceId: workspace.id,
- type,
- });
+ if (type === "subscription") {
+ if (!workspace.stripeId) {
+ return NextResponse.json([]);
+ }
+
+ const invoices = await getSubscriptionInvoices(workspace.stripeId, {
+ status: stripeStatus,
+ });
+
+ return NextResponse.json(z.array(InvoiceSchema).parse(invoices));
+ }
+
+ const invoices = await getOtherInvoices({
+ workspaceId: workspace.id,
+ type,
+ });
return NextResponse.json(z.array(InvoiceSchema).parse(invoices));
},
@@ -96,7 +99,7 @@ const getOtherInvoices = async ({
return {
...invoice,
description:
- type === "partnerPayout" ? "Dub Partner payout" : "Dub Domain renewal",
+ type === "partnerPayout" ? "Dub partner payout" : "Dub domain renewal",
pdfUrl: `${APP_DOMAIN}/invoices/${invoice.id}`,
};
});
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/invoices-nav.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/invoices-nav.tsx
new file mode 100644
index 0000000000..4380b0b4d9
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/invoices-nav.tsx
@@ -0,0 +1,66 @@
+"use client";
+
+import { isProductionEnvironment } from "@/lib/sandbox/environment";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { PageNavTabs } from "@/ui/layout/page-nav-tabs";
+import { CreditCard, Globe, Icon, MoneyBills2, useRouterStuff } from "@dub/ui";
+
+export const INVOICE_TYPES = [
+ "subscription",
+ "partnerPayout",
+ "domainRenewal",
+] as const;
+
+export type InvoiceTypeId = (typeof INVOICE_TYPES)[number];
+
+export const INVOICE_TABS: {
+ id: InvoiceTypeId;
+ label: string;
+ icon: Icon;
+}[] = [
+ { id: "subscription", label: "Subscription", icon: CreditCard },
+ { id: "partnerPayout", label: "Partner payouts", icon: MoneyBills2 },
+ { id: "domainRenewal", label: "Domain renewals", icon: Globe },
+];
+
+export function getVisibleInvoiceTabs(isProduction: boolean) {
+ return isProduction
+ ? INVOICE_TABS
+ : INVOICE_TABS.filter((tab) => tab.id === "partnerPayout");
+}
+
+export function resolveInvoiceType(
+ type: string | null | undefined,
+ isProduction: boolean,
+): InvoiceTypeId {
+ const visibleTabs = getVisibleInvoiceTabs(isProduction);
+
+ return visibleTabs.find((tab) => tab.id === type)?.id ?? visibleTabs[0].id;
+}
+
+export function InvoicesNav() {
+ const { slug, environment, loading } = useWorkspace();
+ const { getQueryString, searchParams } = useRouterStuff();
+ const basePath = `/${slug}/settings/billing/invoices`;
+ const isProduction = isProductionEnvironment(environment);
+
+ if (loading || !environment) {
+ return <div className="h-12" />;
+ }
+
+ const selectedId = resolveInvoiceType(
+ searchParams.get("type"),
+ isProduction,
+ );
+
+ return (
+ <PageNavTabs
+ basePath={basePath}
+ tabs={getVisibleInvoiceTabs(isProduction).map((tab) => ({
+ ...tab,
+ href: `${basePath}${getQueryString({ type: tab.id })}`,
+ selected: tab.id === selectedId,
+ }))}
+ />
+ );
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/layout.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/layout.tsx
new file mode 100644
index 0000000000..0e632b9113
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/layout.tsx
@@ -0,0 +1,43 @@
+"use client";
+
+import useWorkspace from "@/lib/swr/use-workspace";
+import { PageContent } from "@/ui/layout/page-content";
+import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
+import { ChevronRight } from "@dub/ui";
+import Link from "next/link";
+import { ReactNode } from "react";
+import { InvoicesNav } from "./invoices-nav";
+
+export default function WorkspaceInvoicesLayout({
+ children,
+}: {
+ children: ReactNode;
+}) {
+ const { slug } = useWorkspace();
+
+ return (
+ <PageContent
+ title={
+ <div className="flex items-center gap-1.5">
+ <Link
+ href={`/${slug}/settings/billing`}
+ className="transition-all duration-150 hover:text-neutral-600 active:scale-95"
+ >
+ Billing
+ </Link>
+ <ChevronRight className="text-content-muted size-2.5 shrink-0 [&_*]:stroke-2" />
+ <h1>Invoices</h1>
+ </div>
+ }
+ >
+ <PageWidthWrapper>
+ <div className="border-border-subtle mb-10 overflow-hidden rounded-xl border bg-neutral-100">
+ <InvoicesNav />
+ <div className="border-border-subtle -mx-px -mb-px overflow-hidden rounded-xl border bg-white">
+ <div className="grid divide-y divide-neutral-200">{children}</div>
+ </div>
+ </div>
+ </PageWidthWrapper>
+ </PageContent>
+ );
+}
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.tsx
index 73a1fe606e..3fed1a9f0d 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
@@ -2,126 +2,74 @@
import { formatCommissionDescriptionTooltip } from "@/lib/commissions/format-commission-description-tooltip";
import { INVOICE_PAYMENT_METHODS } from "@/lib/constants/payouts";
+import { isProductionEnvironment } from "@/lib/sandbox/environment";
import useWorkspace from "@/lib/swr/use-workspace";
import { InvoiceProps } from "@/lib/types";
-import { PageContent } from "@/ui/layout/page-content";
-import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";
import { PayoutStatusBadges } from "@/ui/partners/payout-status-badges";
import { AnimatedEmptyState } from "@/ui/shared/animated-empty-state";
import {
Button,
buttonVariants,
- ChevronRight,
Receipt2,
StatusBadge,
- TabSelect,
useRouterStuff,
} from "@dub/ui";
import { ArrowTurnRight2 } from "@dub/ui/icons";
import { cn, currencyFormatter, fetcher, formatDateTime } from "@dub/utils";
import { StripeInvoiceStatusBadges } from "app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/invoices/stripe-invoice-status-badges";
import { AlertCircle } from "lucide-react";
-import Link from "next/link";
-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" },
-];
+import { INVOICE_TABS, resolveInvoiceType } from "./invoices-nav";
export default function WorkspaceInvoices() {
- 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 { slug, environment, loading } = useWorkspace();
+ const { searchParams } = useRouterStuff();
+ const environmentReady = !loading && !!environment;
+ const isProduction = isProductionEnvironment(environment);
+ const invoiceType = environmentReady
+ ? resolveInvoiceType(searchParams.get("type"), isProduction)
+ : null;
const { data: invoices } = useSWR<InvoiceProps[]>(
- `/api/workspaces/${slug}/billing/invoices?type=${selectedInvoiceType.id}`,
+ slug && invoiceType
+ ? `/api/workspaces/${slug}/billing/invoices?type=${invoiceType}`
+ : null,
fetcher,
);
- const displayPaymentMethod = selectedInvoiceType.id === "partnerPayout";
+ const displayPaymentMethod = invoiceType === "partnerPayout";
+ const invoiceTypeLabel =
+ INVOICE_TABS.find((tab) => tab.id === invoiceType)?.label ?? "invoice";
- return (
- <PageContent
- title={
- <div className="flex items-center gap-1.5">
- <Link
- href={`/${slug}/settings/billing`}
- className="transition-all duration-150 hover:text-neutral-600 active:scale-95"
- >
- Billing
- </Link>
- <ChevronRight className="text-content-muted size-2.5 shrink-0 [&_*]:stroke-2" />
- <h1>Invoices</h1>
- </div>
- }
- >
- <PageWidthWrapper>
- <div className="mb-10 rounded-xl border border-neutral-200 bg-white">
- <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}
- isSubscription={selectedInvoiceType.id === "subscription"}
- />
- ))
- ) : (
- <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>
- </PageWidthWrapper>
- </PageContent>
+ return invoices ? (
+ invoices.length > 0 ? (
+ invoices.map((invoice) => (
+ <InvoiceCard
+ key={invoice.id}
+ invoice={invoice}
+ displayPaymentMethod={displayPaymentMethod}
+ isSubscription={invoiceType === "subscription"}
+ />
+ ))
+ ) : (
+ <AnimatedEmptyState
+ title={`No ${invoiceTypeLabel.toLowerCase()} invoices found`}
+ description={`You don't have any ${invoiceTypeLabel.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} />
+ </>
);
}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/domains/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/domains/page-client.tsx
index 2d41f187ac..0d19b26667 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/domains/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/domains/page-client.tsx
@@ -1,6 +1,7 @@
"use client";
import { clientAccessCheck } from "@/lib/client-access-check";
+import { isProductionEnvironment } from "@/lib/sandbox/environment";
import useDomains from "@/lib/swr/use-domains";
import useDomainsCount from "@/lib/swr/use-domains-count";
import useWorkspace from "@/lib/swr/use-workspace";
@@ -42,6 +43,7 @@ export function CustomDomains() {
domainsLimit,
exceededDomains,
dotLinkClaimed,
+ environment,
} = useWorkspace();
const [openPopover, setOpenPopover] = useState(false);
@@ -165,60 +167,70 @@ export function CustomDomains() {
}
/>
- <Popover
- content={
- <div className="grid w-screen gap-px p-2 sm:w-fit sm:min-w-[17rem]">
- <Button
- text="Connect a domain you own"
- variant="outline"
- icon={<Globe className="h-4 w-4" />}
- className="h-9 justify-start px-2 text-neutral-800"
- onClick={() => setShowAddEditDomainModal(true)}
- />
- <Button
- text={
- <div className="flex items-center gap-3">
- Claim free .link domain
- {plan === "free" ? (
- <Badge
- variant="neutral"
- className="flex items-center gap-1"
- >
- <Crown className="size-3" />
- <span className="uppercase">Pro</span>
- </Badge>
- ) : dotLinkClaimed ? (
- <span className="rounded-md border border-green-200 bg-green-500/10 px-1 py-0.5 text-xs text-green-900">
- Claimed
- </span>
- ) : null}
- </div>
- }
- variant="outline"
- icon={<LinkBroken className="size-4" />}
- className="h-9 justify-start px-2 text-neutral-800 disabled:border-none disabled:bg-transparent disabled:text-neutral-500"
- onClick={() => setShowRegisterDomainModal(true)}
- disabled={dotLinkClaimed}
- />
- </div>
- }
- align="end"
- openPopover={openPopover}
- setOpenPopover={setOpenPopover}
- >
+ {isProductionEnvironment(environment) ? (
+ <Popover
+ content={
+ <div className="grid w-screen gap-px p-2 sm:w-fit sm:min-w-[17rem]">
+ <Button
+ text="Connect a domain you own"
+ variant="outline"
+ icon={<Globe className="h-4 w-4" />}
+ className="h-9 justify-start px-2 text-neutral-800"
+ onClick={() => setShowAddEditDomainModal(true)}
+ />
+ <Button
+ text={
+ <div className="flex items-center gap-3">
+ Claim free .link domain
+ {plan === "free" ? (
+ <Badge
+ variant="neutral"
+ className="flex items-center gap-1"
+ >
+ <Crown className="size-3" />
+ <span className="uppercase">Pro</span>
+ </Badge>
+ ) : dotLinkClaimed ? (
+ <span className="rounded-md border border-green-200 bg-green-500/10 px-1 py-0.5 text-xs text-green-900">
+ Claimed
+ </span>
+ ) : null}
+ </div>
+ }
+ variant="outline"
+ icon={<LinkBroken className="size-4" />}
+ className="h-9 justify-start px-2 text-neutral-800 disabled:border-none disabled:bg-transparent disabled:text-neutral-500"
+ onClick={() => setShowRegisterDomainModal(true)}
+ disabled={dotLinkClaimed}
+ />
+ </div>
+ }
+ align="end"
+ openPopover={openPopover}
+ setOpenPopover={setOpenPopover}
+ >
+ <Button
+ variant="primary"
+ className="h-9 w-fit rounded-lg"
+ text={
+ <div className="flex items-center gap-2">
+ Add custom domain{" "}
+ <ChevronDown className="size-4 transition-transform duration-75 group-data-[state=open]:rotate-180" />
+ </div>
+ }
+ onClick={() => setOpenPopover(!openPopover)}
+ disabledTooltip={disabledTooltip}
+ />
+ </Popover>
+ ) : (
<Button
variant="primary"
className="h-9 w-fit rounded-lg"
- text={
- <div className="flex items-center gap-2">
- Add custom domain{" "}
- <ChevronDown className="size-4 transition-transform duration-75 group-data-[state=open]:rotate-180" />
- </div>
- }
- onClick={() => setOpenPopover(!openPopover)}
+ text="Add custom domain"
+ onClick={() => setShowAddEditDomainModal(true)}
disabledTooltip={disabledTooltip}
/>
- </Popover>
+ )}
</div>
</div>
@@ -229,7 +241,9 @@ export function CustomDomains() {
</>
)}
- {!dotLinkClaimed && <FreeDotLinkBanner />}
+ {isProductionEnvironment(environment) && !dotLinkClaimed && (
+ <FreeDotLinkBanner />
+ )}
<div key={archived} className="animate-fade-in">
{!loading ? (
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/links/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/links/page-client.tsx
index 5d38b9a29c..a2069f4247 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/links/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/links/page-client.tsx
@@ -1,5 +1,6 @@
"use client";
+import { isProductionEnvironment } from "@/lib/sandbox/environment";
import useCurrentFolderId from "@/lib/swr/use-current-folder-id";
import {
useCheckFolderPermission,
@@ -122,6 +123,7 @@ export function WorkspaceLinksList() {
if (showedDotLinkModal) return;
// We show the .link offer modal if:
+ // - The workspace is production
// - The upgraded modal is not open
// - The user has a paid plan (and valid stripe ID)
// - The user is not in a billing trial (.link cannot be claimed until trial ends)
@@ -129,6 +131,7 @@ export function WorkspaceLinksList() {
// - The user has not claimed their .link domain
// - The user has not dismissed the .link offer modal
if (
+ isProductionEnvironment(workspace.environment) &&
!searchParams.has("upgraded") &&
workspace.stripeId &&
workspace.plan &&
diff --git a/apps/web/lib/api/domains/claim-dot-link-domain.ts b/apps/web/lib/api/domains/claim-dot-link-domain.ts
index 8083924df4..0ee203e42d 100644
--- a/apps/web/lib/api/domains/claim-dot-link-domain.ts
+++ b/apps/web/lib/api/domains/claim-dot-link-domain.ts
@@ -2,6 +2,7 @@ import { DubApiError } from "@/lib/api/errors";
import { createLink } from "@/lib/api/links";
import { registerDomain } from "@/lib/dynadot/register-domain";
import { prisma } from "@/lib/prisma";
+import { isProductionEnvironment } from "@/lib/sandbox/environment";
import { sendBatchEmail } from "@dub/email";
import DomainClaimed from "@dub/email/templates/domain-claimed";
import { DEFAULT_LINK_PROPS, isWorkspaceBillingTrialActive } from "@dub/utils";
@@ -21,11 +22,25 @@ export async function claimDotLinkDomain({
domain: string;
workspace: Pick<
Project,
- "id" | "slug" | "plan" | "stripeId" | "trialEndsAt" | "dotLinkClaimed"
+ | "id"
+ | "slug"
+ | "plan"
+ | "stripeId"
+ | "trialEndsAt"
+ | "dotLinkClaimed"
+ | "environment"
>;
userId: string;
skipWorkspaceChecks?: boolean; // when used in /api/domains/register
}) {
+ if (!isProductionEnvironment(workspace.environment)) {
+ throw new DubApiError({
+ code: "forbidden",
+ message:
+ "Free .link domains can only be claimed in production workspaces.",
+ });
+ }
+
if (!skipWorkspaceChecks) {
if (workspace.plan === "free")
throw new DubApiError({
diff --git a/apps/web/ui/domains/free-dot-link-banner.tsx b/apps/web/ui/domains/free-dot-link-banner.tsx
index c2cb4f0d74..05c3bd750d 100644
--- a/apps/web/ui/domains/free-dot-link-banner.tsx
+++ b/apps/web/ui/domains/free-dot-link-banner.tsx
@@ -1,3 +1,4 @@
+import { isProductionEnvironment } from "@/lib/sandbox/environment";
import useWorkspace from "@/lib/swr/use-workspace";
import { Grid, useLocalStorage } from "@dub/ui";
import { LinkBroken } from "@dub/ui/icons";
@@ -6,7 +7,7 @@ import { useRegisterDomainModal } from "../modals/register-domain-modal";
import { X } from "../shared/icons";
export function FreeDotLinkBanner() {
- const { id: workspaceId, trialEndsAt } = useWorkspace();
+ const { id: workspaceId, trialEndsAt, environment } = useWorkspace();
const [show, setShow] = useLocalStorage(
`show-free-dot-link-banner:${workspaceId}`,
true,
@@ -15,7 +16,10 @@ export function FreeDotLinkBanner() {
const { RegisterDomainModal, setShowRegisterDomainModal } =
useRegisterDomainModal();
- if (isWorkspaceBillingTrialActive(trialEndsAt)) {
+ if (
+ !isProductionEnvironment(environment) ||
+ isWorkspaceBillingTrialActive(trialEndsAt)
+ ) {
return null;
}
diff --git a/apps/web/ui/layout/page-nav-tabs.tsx b/apps/web/ui/layout/page-nav-tabs.tsx
index 832b3ffd0e..85d6e5bd93 100644
--- a/apps/web/ui/layout/page-nav-tabs.tsx
+++ b/apps/web/ui/layout/page-nav-tabs.tsx
@@ -19,6 +19,8 @@ export type PageNavTabsTab = {
badge?: string | number;
// Set when the tab is not at `${basePath}/${id}`
href?: string;
+ // Overrides path-based selection, for tabs that share a path and differ by query param
+ selected?: boolean;
};
export type PageNavTabsQuicklink = {
@@ -83,12 +85,13 @@ export function PageNavTabs({
layout
className={cn("relative z-0 inline-flex items-center gap-1")}
>
- {tabs.map(({ id, label, icon: Icon, badge, href }, idx) => {
+ {tabs.map(({ id, label, icon: Icon, badge, href, selected }, idx) => {
// if it's the base path, match the first tab
const isSelected =
- pathname.endsWith(basePath) && idx === 0
+ selected ??
+ (pathname.endsWith(basePath) && idx === 0
? true
- : pathname.endsWith(`/${id}`);
+ : pathname.endsWith(`/${id}`));
return (
<Link
key={id}
diff --git a/apps/web/ui/links/short-link-input.tsx b/apps/web/ui/links/short-link-input.tsx
index a7808bf959..644989576e 100644
--- a/apps/web/ui/links/short-link-input.tsx
+++ b/apps/web/ui/links/short-link-input.tsx
@@ -1,5 +1,6 @@
"use client";
+import { isProductionEnvironment } from "@/lib/sandbox/environment";
import useWorkspace from "@/lib/swr/use-workspace";
import { LinkProps } from "@/lib/types";
import { DOMAINS_MAX_PAGE_SIZE } from "@/lib/zod/schemas/domains";
@@ -88,6 +89,7 @@ export const ShortLinkInput = forwardRef<HTMLInputElement, ShortLinkInputProps>(
exceededAI,
nextPlan,
dotLinkClaimed,
+ environment,
} = useWorkspace();
const [lockKey, setLockKey] = useState(existingLink);
@@ -410,15 +412,17 @@ export const ShortLinkInput = forwardRef<HTMLInputElement, ShortLinkInputProps>(
onChange={(domain) => onChange({ domain })}
/>
)}
- {!onboarding && !dotLinkClaimed && (
- <AnimatedSizeContainer
- height
- transition={{ ease: "linear", duration: 0.1 }}
- className="mt-2"
- >
- <FreeDotLinkBanner />
- </AnimatedSizeContainer>
- )}
+ {!onboarding &&
+ !dotLinkClaimed &&
+ isProductionEnvironment(environment) && (
+ <AnimatedSizeContainer
+ height
+ transition={{ ease: "linear", duration: 0.1 }}
+ className="mt-2"
+ >
+ <FreeDotLinkBanner />
+ </AnimatedSizeContainer>
+ )}
</div>
);
},
diff --git a/apps/web/ui/modals/upgraded-modal.tsx b/apps/web/ui/modals/upgraded-modal.tsx
index 81b473b905..ecded4da0d 100644
--- a/apps/web/ui/modals/upgraded-modal.tsx
+++ b/apps/web/ui/modals/upgraded-modal.tsx
@@ -1,4 +1,5 @@
import { testIds } from "@/lib/e2e/test-ids";
+import { isProductionEnvironment } from "@/lib/sandbox/environment";
import useWorkspace from "@/lib/swr/use-workspace";
import { useWorkspaceStore } from "@/lib/swr/use-workspace-store";
import { Button, Modal, useRouterStuff, useScrollProgress } from "@dub/ui";
@@ -36,6 +37,7 @@ function UpgradedModal({
const {
dotLinkClaimed,
trialEndsAt,
+ environment,
loading: workspaceLoading,
mutate: mutateWorkspaceData,
} = useWorkspace();
@@ -66,6 +68,7 @@ function UpgradedModal({
const showDotLinkClaimUi =
checkoutWorkspaceSynced &&
!workspaceLoading &&
+ isProductionEnvironment(environment) &&
!dotLinkClaimed &&
!isWorkspaceBillingTrialActive(trialEndsAt);
diff --git a/apps/web/ui/partners/program-link-configuration.tsx b/apps/web/ui/partners/program-link-configuration.tsx
index 5f076f8e16..7d9f513a0a 100644
--- a/apps/web/ui/partners/program-link-configuration.tsx
+++ b/apps/web/ui/partners/program-link-configuration.tsx
@@ -1,4 +1,5 @@
import type { DomainConnectDiscovery } from "@/lib/domain-connect/types";
+import { isProductionEnvironment } from "@/lib/sandbox/environment";
import { getLinkStructureOptions } from "@/lib/partners/get-link-structure-options";
import { mutatePrefix } from "@/lib/swr/mutate";
import useDomains from "@/lib/swr/use-domains";
@@ -140,7 +141,7 @@ export function ProgramLinkConfiguration({
}
function DomainOnboarding({ domain, onDomainChange }: DomainProps) {
- const { slug, trialEndsAt } = useWorkspace();
+ const { slug, trialEndsAt, environment } = useWorkspace();
const { allWorkspaceDomains: domains, loading: isLoadingDomains } =
useDomains();
const trialActive = isWorkspaceBillingTrialActive(trialEndsAt);
@@ -182,29 +183,36 @@ function DomainOnboarding({ domain, onDomainChange }: DomainProps) {
},
loading: isLoadingDomains,
},
- trialActive
- ? {
- icon: <Wordmark className="h-3 text-neutral-900" />,
- title: "Use .dub.link subdomain",
- badge: "Instant setup",
- badgeClassName: "bg-bg-inverted/10 text-neutral-800",
- description:
- "A fast way to launch. Switch to a custom domain later.",
- onSelect: () => setShowSubdomainModal(true),
- }
- : {
- icon: "https://assets.dub.co/icons/crown.webp",
- title: "Claim a free .link domain",
- badge: "No setup",
- badgeClassName: "bg-green-100 text-green-800",
- description: "Free for one year with your paid account.",
- onSelect: () => setShowRegisterDomainModal(true),
- },
+ ...(trialActive
+ ? [
+ {
+ icon: <Wordmark className="h-3 text-neutral-900" />,
+ title: "Use .dub.link subdomain",
+ badge: "Instant setup",
+ badgeClassName: "bg-bg-inverted/10 text-neutral-800",
+ description:
+ "A fast way to launch. Switch to a custom domain later.",
+ onSelect: () => setShowSubdomainModal(true),
+ },
+ ]
+ : isProductionEnvironment(environment)
+ ? [
+ {
+ icon: "https://assets.dub.co/icons/crown.webp",
+ title: "Claim a free .link domain",
+ badge: "No setup",
+ badgeClassName: "bg-green-100 text-green-800",
+ description: "Free for one year with your paid account.",
+ onSelect: () => setShowRegisterDomainModal(true),
+ },
+ ]
+ : []),
],
[
domains,
isLoadingDomains,
trialActive,
+ environment,
setShowAddEditDomainModal,
setShowRegisterDomainModal,
setShowSubdomainModal,