Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions apps/web/app/(ee)/api/admin/links/count/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { withAdmin } from "@/lib/auth";
import { prisma } from "@dub/prisma";
import { DUB_DOMAINS_ARRAY, LEGAL_USER_ID } from "@dub/utils";
import { LEGAL_USER_ID } from "@dub/utils";
import { NextResponse } from "next/server";

// GET /api/admin/links/count
Expand All @@ -18,15 +18,10 @@ export const GET = withAdmin(async ({ searchParams }) => {

const linksWhere = {
// when filtering by domain, only filter by domain if the filter group is not "Domains"
...(domain && groupBy !== "domain"
? {
domain,
}
: {
domain: {
in: DUB_DOMAINS_ARRAY,
},
}),
...(domain &&
groupBy !== "domain" && {
domain,
}),
userId: {
not: LEGAL_USER_ID,
},
Expand Down
10 changes: 2 additions & 8 deletions apps/web/app/(ee)/api/admin/links/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { transformLink } from "@/lib/api/links";
import { withAdmin } from "@/lib/auth";
import { prisma } from "@dub/prisma";
import { DUB_DOMAINS_ARRAY, LEGAL_USER_ID } from "@dub/utils";
import { LEGAL_USER_ID } from "@dub/utils";
import { NextResponse } from "next/server";

// GET /api/admin/links
Expand All @@ -20,13 +20,7 @@ export const GET = withAdmin(async ({ searchParams }) => {

const response = await prisma.link.findMany({
where: {
...(domain
? { domain }
: {
domain: {
in: DUB_DOMAINS_ARRAY,
},
}),
...(domain && { domain }),
...(!search && {
createdAt: {
gte: new Date(Date.now() - 1000 * 60 * 60 * 24 * 30), // 30 days ago
Expand Down
14 changes: 6 additions & 8 deletions apps/web/app/api/workspaces/[idOrSlug]/billing/upgrade/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ const upgradePlanSchema = z.object({
message: "Invalid baseUrl.",
}),
onboarding: booleanQuerySchema.nullish(),
isTrialVariant: booleanQuerySchema.nullish(),
});

// POST /api/workspaces/[idOrSlug]/billing/upgrade
export const POST = withWorkspace(
async ({ req, workspace, session }) => {
let { plan, period, tier, baseUrl, onboarding, isTrialVariant } =
upgradePlanSchema.parse(await req.json());
let { plan, period, tier, baseUrl, onboarding } = upgradePlanSchema.parse(
await req.json(),
);

const lookupKey =
tier > 1 ? `${plan}${tier}_${period}` : `${plan}_${period}`;
Expand Down Expand Up @@ -105,15 +105,13 @@ export const POST = withWorkspace(
const customer = await getDubCustomer(session.user.id);

// Only apply trial if the customer is a:
// - on the free plan
// - new Stripe customer
// - no prior/existing trial on workspace
// - is coming from onboarding
// - is trial variant
const shouldApplyCheckoutTrial =
workspace.plan === "free" &&
workspace.stripeId == null &&
workspace.trialEndsAt == null &&
onboarding &&
isTrialVariant;
workspace.trialEndsAt == null;

const stripeSession = await stripe.checkout.sessions.create({
...(workspace.stripeId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import useWorkspace from "@/lib/swr/use-workspace";
import { Button, Grid, Slider } from "@dub/ui";
import {
BUSINESS_PLAN,
ENTERPRISE_PLAN,
SELF_SERVE_PAID_PLANS,
cn,
Expand All @@ -12,11 +13,11 @@ import { useSearchParams } from "next/navigation";
import { useEffect, useMemo, useState } from "react";

export function AdjustUsageRow({
onLinksUsageChange,
onEventsUsageChange,
onLinksUsageChange,
}: {
onLinksUsageChange: (value: number) => void;
onEventsUsageChange: (value: number) => void;
onLinksUsageChange: (value: number) => void;
}) {
const [isExpanded, setIsExpanded] = useState(false);

Expand Down Expand Up @@ -101,6 +102,11 @@ function UsageSlider({
return planDetails.limits[limitKey];
}
}

if (workspace.plan === "free") {
return BUSINESS_PLAN.limits[limitKey];
}

const currentLimit = workspace[workspaceLimitKey];
return usageSteps.reduce((prev, curr) =>
Math.abs(curr - currentLimit) < Math.abs(prev - currentLimit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import {
Users2,
} from "@dub/ui";
import {
capitalize,
cn,
DUB_TRIAL_PERIOD_DAYS,
getSuggestedPlan,
isDowngradePlan,
isLegacyBusinessPlan,
Expand Down Expand Up @@ -185,6 +187,11 @@ export default function WorkspaceBillingUpgradePage() {
}),
);

const isEligibleForTrial =
currentPlan === "free" &&
stripeId == null &&
trialEndsAt == null;

return (
<div
key={plan.name}
Expand Down Expand Up @@ -275,12 +282,14 @@ export default function WorkspaceBillingUpgradePage() {
? "Activate plan"
: "Current plan"
: isCurrentPlan
? `Switch to ${period}`
? `Switch to ${plan.name} ${capitalize(period)}`
: isDowngrade
? "Downgrade"
: isWorkspaceBillingTrialActive(trialEndsAt)
? "Switch trial"
: "Upgrade"
: isEligibleForTrial
? `Start ${DUB_TRIAL_PERIOD_DAYS}-day trial`
: `Upgrade to ${plan.name} ${capitalize(period)}`
}
variant={isDowngrade ? "secondary" : "primary"}
className="h-8 shadow-sm"
Expand All @@ -305,8 +314,8 @@ export default function WorkspaceBillingUpgradePage() {
<div className="bg-bg-muted border-subtle absolute inset-x-0 -top-2.5 bottom-0 rounded-b-[12px] border" />

<AdjustUsageRow
onLinksUsageChange={(value) => setLinksUsage(value)}
onEventsUsageChange={(value) => setEventsUsage(value)}
onLinksUsageChange={(value) => setLinksUsage(value)}
/>
</div>

Expand Down

This file was deleted.

12 changes: 1 addition & 11 deletions apps/web/app/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,11 @@ import { KeyboardShortcutProvider, TooltipProvider } from "@dub/ui";
import PlausibleProvider from "next-plausible";
import { ReactNode } from "react";
import { Toaster } from "sonner";
import { useOnboardingTrialVariant } from "./app.dub.co/(onboarding)/onboarding/use-onboarding-trial-variant";

export default function RootProviders({ children }: { children: ReactNode }) {
const { isTrialVariant } = useOnboardingTrialVariant();

return (
<TooltipProvider>
<PlausibleProvider
enabled
init={{
customProperties: {
trialVariant: isTrialVariant ? "Trial" : "Control",
},
}}
>
<PlausibleProvider enabled>
<KeyboardShortcutProvider>
<Toaster className="pointer-events-auto" closeButton />
{children}
Expand Down
25 changes: 15 additions & 10 deletions apps/web/lib/actions/send-otp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,28 @@ export const sendOtpAction = actionClient

const isGenericEmailWithPlus = email.includes("+") && isGenericEmail(email);

const emailDomain = email.split("@")[1];
const emailDomain = (email.split("@")[1] ?? "").trim().toLowerCase();

const [isDisposable, emailDomainTerms] = await Promise.all([
redis.sismember("disposableEmailDomains", emailDomain),
process.env.EDGE_CONFIG ? get("emailDomainTerms") : [],
]);

// Only build the regex if we have at least one term; otherwise set to null
const blacklistedEmailDomainTermsRegex =
const escapedDomainTerms =
emailDomainTerms && Array.isArray(emailDomainTerms)
? new RegExp(
emailDomainTerms
.map((term: string) =>
term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),
) // replace special characters with escape sequences
.join("|"),
)
? emailDomainTerms
.map((term: string) =>
String(term)
.trim()
.toLowerCase()
.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),
)
.filter((term) => term.length > 0)
: [];

const blacklistedEmailDomainTermsRegex =
escapedDomainTerms.length > 0
? new RegExp(escapedDomainTerms.join("|"))
: null;

// if any of the flags match, run one final edge case check, before throwing an error
Expand Down
2 changes: 1 addition & 1 deletion apps/web/lib/zod/schemas/opens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const trackOpenResponseSchema = z.object({
.string()
.nullable()
.describe(
"The click ID of the associated open event (or the prior click that led the user to the app store for probabilistic tracking). This will be `null` if the open event was not associated with a deep link (e.g. a direct download from the app store), or if the open event was performed by a bot (no click recorded). Learn more: https://d.to/ddl",
"The click ID of the associated open event (or the prior click that led the user to the app store for probabilistic tracking). Learn more: https://d.to/ddl",
),
link: z
.object({
Expand Down
26 changes: 21 additions & 5 deletions apps/web/ui/modals/manage-usage-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { clientAccessCheck } from "@/lib/client-access-check";
import useWorkspace from "@/lib/swr/use-workspace";
import { CursorRays, Hyperlink, Modal, Slider, ToggleGroup } from "@dub/ui";
import {
DUB_TRIAL_PERIOD_DAYS,
ENTERPRISE_PLAN,
SELF_SERVE_PAID_PLANS,
capitalize,
cn,
getSuggestedPlan,
isDowngradePlan,
Expand All @@ -27,8 +29,17 @@ type ManageUsageModalProps = {

function ManageUsageModalContent({ type }: ManageUsageModalProps) {
const workspace = useWorkspace();
const { slug, role, plan, planPeriod, planTier, usageLimit, linksLimit } =
workspace;
const {
slug,
role,
stripeId,
plan,
planPeriod,
planTier,
trialEndsAt,
usageLimit,
linksLimit,
} = workspace;

const { error: permissionsError } = clientAccessCheck({
action: "billing.write",
Expand Down Expand Up @@ -85,6 +96,9 @@ function ManageUsageModalContent({ type }: ManageUsageModalProps) {
newTier: suggestedPlanTier,
});

const isEligibleForTrial =
plan === "free" && stripeId == null && trialEndsAt == null;

if (usageSteps.length < 2) return null;

return (
Expand Down Expand Up @@ -185,9 +199,11 @@ function ManageUsageModalContent({ type }: ManageUsageModalProps) {
? "Current plan"
: isDowngradeSuggested
? "Downgrade"
: planPeriod !== period
? `Switch to ${period}`
: "Upgrade"
: planPeriod && planPeriod !== period
? `Switch to ${suggestedPlan.name} ${capitalize(period)}`
: isEligibleForTrial
? `Start ${DUB_TRIAL_PERIOD_DAYS}-day trial`
: `Upgrade to ${suggestedPlan.name} ${capitalize(period)}`
}
variant={isDowngradeSuggested ? "secondary" : "primary"}
className="h-8 rounded-lg shadow-sm"
Expand Down
4 changes: 2 additions & 2 deletions apps/web/ui/partners/partners-upgrade-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Tooltip,
useRouterStuff,
} from "@dub/ui";
import { cn, INFINITY_NUMBER, nFormatter, PLANS } from "@dub/utils";
import { capitalize, cn, INFINITY_NUMBER, nFormatter, PLANS } from "@dub/utils";
import NumberFlow from "@number-flow/react";
import Link from "next/link";
import { Dispatch, ReactNode, SetStateAction, useMemo, useState } from "react";
Expand Down Expand Up @@ -263,7 +263,7 @@ export function PartnersUpgradeModal({
<UpgradePlanButton
plan={plan.name.toLowerCase()}
period={period}
text={`Continue with ${plan.name}`}
text={`Continue with ${plan.name} ${capitalize(period)}`}
variant="primary"
/>
) : (
Expand Down
2 changes: 1 addition & 1 deletion apps/web/ui/partners/program-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function rejectedApplicationTooltipContent(
}

return (
<div className="flex w-full min-w-0 max-w-[min(100vw-2rem,17.5rem)] flex-col gap-2 p-3 pb-4 text-left">
<div className="flex w-full min-w-0 max-w-[min(100vw-2rem,17.5rem)] flex-col gap-2 p-3 text-left">
{reviewedAt ? (
<RejectionTooltipRow
icon={<CalendarIcon className="size-4 shrink-0" aria-hidden />}
Expand Down
10 changes: 3 additions & 7 deletions apps/web/ui/workspaces/upgrade-plan-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
isWorkspaceBillingTrialActive,
SELF_SERVE_PAID_PLANS,
} from "@dub/utils";
import { useOnboardingTrialVariant } from "app/app.dub.co/(onboarding)/onboarding/use-onboarding-trial-variant";
import { usePlausible } from "next-plausible";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { useMemo, useState } from "react";
Expand Down Expand Up @@ -44,7 +43,6 @@ export function UpgradePlanButton({

const plausible = usePlausible();
const product = searchParams.get("product");
const { isTrialVariant } = useOnboardingTrialVariant();
const isTrialActive = isWorkspaceBillingTrialActive(trialEndsAt);

const selectedPlan =
Expand Down Expand Up @@ -96,7 +94,6 @@ export function UpgradePlanButton({
period,
baseUrl: `${APP_DOMAIN}${pathname}${queryString.length > 0 ? `?${queryString}` : ""}`,
onboarding: searchParams.get("workspace") ? "true" : "false",
isTrialVariant: isTrialVariant ? "true" : "false",
}),
},
);
Expand Down Expand Up @@ -178,17 +175,16 @@ export function UpgradePlanButton({
<StartPaidPlanModal />
<SwitchTrialPlanModal />
<Button
// these are the default text for onboarding plan selector
text={
!currentPlan
? "Loading..."
: isCurrentPlan
? isTrialActive
? "Activate plan"
: "Your current plan"
: "Current plan"
: currentPlan === "free"
? isTrialVariant
? `Start ${DUB_TRIAL_PERIOD_DAYS}-day trial · ${selectedPlan.name} ${capitalize(period)}`
: `Upgrade to ${selectedPlan.name} ${capitalize(period)}`
? `Start ${DUB_TRIAL_PERIOD_DAYS}-day trial · ${selectedPlan.name} ${capitalize(period)}`
: isTrialActive
? `Switch trial to ${selectedPlan.name} ${capitalize(period)}`
: `Switch to ${selectedPlan.name} ${capitalize(period)}`
Expand Down
Loading
Loading