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.

Improve onboarding flow (#4331)

Steven Teyb7e34fa2f9ab
diff --git a/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/overview/page-client.tsx b/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/overview/page-client.tsx
index 797964531c..b8c1cb2eda 100644
--- a/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/overview/page-client.tsx
+++ b/apps/web/app/(ee)/app.dub.co/(new-program)/[slug]/program/new/overview/page-client.tsx
@@ -131,6 +131,7 @@ export function PageClient() {
title="You can only create a partner program on a Business plan and above."
cta="Upgrade to Business"
href={`/${workspaceSlug}/settings/billing/upgrade?plan=business`}
+ target="_blank"
/>
) : undefined
}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/upgrade/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/upgrade/page.tsx
index f0f1218eb2..3f45176b4e 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/upgrade/page.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/settings/billing/upgrade/page.tsx
@@ -20,6 +20,7 @@ import {
Plug2,
ToggleGroup,
useMediaQuery,
+ useRouterStuff,
Users2,
} from "@dub/ui";
import {
@@ -39,7 +40,6 @@ import { ChevronLeft, ChevronRight } from "lucide-react";
import { motion } from "motion/react";
import { useSession } from "next-auth/react";
import Link from "next/link";
-import { useSearchParams } from "next/navigation";
import { CSSProperties, useEffect, useMemo, useState } from "react";
import { AdjustUsageRow } from "./adjust-usage-row";
@@ -57,7 +57,7 @@ const COMPARE_FEATURE_ICONS: Record<
};
export default function WorkspaceBillingUpgradePage() {
- const searchParams = useSearchParams();
+ const { searchParams, queryParams } = useRouterStuff();
const { data: session } = useSession();
const workspace = useWorkspace();
const {
@@ -79,14 +79,14 @@ export default function WorkspaceBillingUpgradePage() {
const [mobilePlanIndex, setMobilePlanIndex] = useState(0);
- const planPeriod = searchParams.get("planPeriod") ?? "";
- const [period, setPeriod] = useState<"monthly" | "yearly">(
- ["monthly", "yearly"].includes(planPeriod)
- ? (planPeriod as "monthly" | "yearly")
- : currentPlanPeriod === "yearly"
- ? "yearly"
- : "monthly",
- );
+ const planPeriodParam = searchParams.get("planPeriod") ?? "";
+ const period: "monthly" | "yearly" = ["monthly", "yearly"].includes(
+ planPeriodParam,
+ )
+ ? (planPeriodParam as "monthly" | "yearly")
+ : currentPlanPeriod === "yearly"
+ ? "yearly"
+ : "monthly";
const { advancedUpsellModal, setShowAdvancedUpsellModal } =
useAdvancedUpsellModal();
@@ -109,6 +109,9 @@ export default function WorkspaceBillingUpgradePage() {
});
}, [linksUsage, eventsUsage]);
+ const planQueryParam = searchParams.get("plan");
+ const showRecommendedHighlight = Boolean(planQueryParam && recommendedPlan);
+
const hideProPlan = Boolean(defaultProgramId && currentPlan !== "pro");
const plans: { plan: PlanDetails; planTier: number }[] = useMemo(
@@ -128,6 +131,24 @@ export default function WorkspaceBillingUpgradePage() {
[recommendedPlan, hideProPlan],
);
+ const recommendedPlanIndex = useMemo(() => {
+ if (!recommendedPlan) return null;
+
+ const index = plans.findIndex(
+ ({ plan, planTier }) =>
+ plan.name === recommendedPlan.plan.name &&
+ planTier === recommendedPlan.planTier,
+ );
+
+ return index >= 0 ? index : null;
+ }, [plans, recommendedPlan]);
+
+ useEffect(() => {
+ if (planQueryParam && recommendedPlanIndex !== null) {
+ setMobilePlanIndex(recommendedPlanIndex);
+ }
+ }, [planQueryParam, recommendedPlanIndex]);
+
useEffect(() => {
if (mobilePlanIndex >= plans.length) {
setMobilePlanIndex(Math.max(0, plans.length - 1));
@@ -166,7 +187,12 @@ export default function WorkspaceBillingUpgradePage() {
},
]}
selected={period}
- selectAction={(option) => setPeriod(option as "monthly" | "yearly")}
+ selectAction={(option) => {
+ queryParams({
+ set: { planPeriod: option },
+ replace: true,
+ });
+ }}
className="rounded-lg border-neutral-300 bg-neutral-100 p-0.5"
optionClassName="text-xs normal-case text-neutral-800 data-[selected=true]:text-neutral-800 px-3 h-8 leading-none"
indicatorClassName="bg-white border-neutral-200 rounded-md"
@@ -193,6 +219,12 @@ export default function WorkspaceBillingUpgradePage() {
}
>
{plans.map(({ plan, planTier }, idx) => {
+ const isRecommended = Boolean(
+ showRecommendedHighlight &&
+ plan.name === recommendedPlan!.plan.name &&
+ planTier === recommendedPlan!.planTier,
+ );
+
// disable upgrade button if user has a Stripe ID and is on the current plan
// (trialing subscriptions still use Checkout in some edge cases; portal handles plan changes)
// edge case:
@@ -225,9 +257,10 @@ export default function WorkspaceBillingUpgradePage() {
<div
key={plan.name}
className={cn(
- "relative top-0 flex h-full flex-col gap-6 bg-white p-5 lg:p-3 xl:p-5",
+ "relative top-0 flex h-full flex-col gap-6 bg-white p-5 transition-[background-color,box-shadow] lg:p-3 xl:p-5",
"max-lg:rounded-xl max-lg:border max-lg:border-neutral-200",
-
+ isRecommended &&
+ "lg:z-10 lg:bg-blue-50 lg:shadow-sm lg:ring-2 lg:ring-blue-500",
idx !== mobilePlanIndex && "max-lg:opacity-0",
)}
>
@@ -236,15 +269,11 @@ export default function WorkspaceBillingUpgradePage() {
<h3 className="py-1 text-base font-semibold leading-none text-neutral-800">
{plan.name}
</h3>
- {recommendedPlan &&
- !isDowngrade &&
- plan.name === recommendedPlan.plan.name &&
- planTier === recommendedPlan.planTier &&
- !isCurrentPlan && (
- <div className="animate-fade-in flex h-6 min-w-0 items-center rounded-lg border border-blue-100 bg-blue-50 px-1.5 text-xs font-medium text-blue-600">
- <span className="truncate">Recommended</span>
- </div>
- )}
+ {isRecommended && !isDowngrade && !isCurrentPlan && (
+ <div className="animate-fade-in flex h-6 min-w-0 items-center rounded-lg border border-blue-100 bg-blue-50 px-1.5 text-xs font-medium text-blue-600">
+ <span className="truncate">Recommended</span>
+ </div>
+ )}
</div>
<div className="relative mt-0.5 flex items-center gap-1">
{plan.name === "Enterprise" ? (
@@ -368,6 +397,9 @@ export default function WorkspaceBillingUpgradePage() {
mobilePlanIndex={mobilePlanIndex}
plans={plans}
planPeriod={period}
+ recommendedPlan={
+ showRecommendedHighlight ? recommendedPlan : null
+ }
/>
))}
</div>
@@ -432,10 +464,12 @@ function BillingCompareSection({
mobilePlanIndex,
plans,
planPeriod,
+ recommendedPlan,
}: (typeof PRICING_PLAN_COMPARE_FEATURES)[number] & {
mobilePlanIndex: number;
plans: { plan: PlanDetails; planTier: number }[];
planPeriod: "monthly" | "yearly";
+ recommendedPlan: ReturnType<typeof getSuggestedPlan> | null;
}) {
const [isExpanded, setIsExpanded] = useState(true);
const { defaultProgramId } = useWorkspace();
@@ -517,8 +551,13 @@ function BillingCompareSection({
return (
<tr key={idx} className="contents bg-white">
- {plans.map(({ plan }) => {
+ {plans.map(({ plan, planTier }) => {
const id = plan.name.toLowerCase();
+ const isRecommended = Boolean(
+ recommendedPlan &&
+ plan.name === recommendedPlan.plan.name &&
+ planTier === recommendedPlan.planTier,
+ );
const isChecked =
typeof check === "boolean"
? check
@@ -529,8 +568,9 @@ function BillingCompareSection({
<td
key={id}
className={cn(
- "flex items-center gap-2 border-b border-neutral-200 bg-white px-5 py-4",
+ "flex items-center gap-2 border-b border-neutral-200 bg-white px-5 py-4 transition-colors",
!isChecked && "text-neutral-300",
+ isRecommended && recommendedPlan && "lg:bg-blue-50",
)}
>
{isChecked ? (
diff --git a/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/program/form.tsx b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/program/form.tsx
index 276b736b68..98b13212df 100644
--- a/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/program/form.tsx
+++ b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/program/form.tsx
@@ -26,9 +26,17 @@ export function Form() {
handleSubmit,
control,
setValue,
+ watch,
formState: { isSubmitting, errors },
} = useFormContext<ProgramData>();
+ const [name, logo, url, supportEmail] = watch([
+ "name",
+ "logo",
+ "url",
+ "supportEmail",
+ ]);
+
const plausible = usePlausible();
const { executeAsync, isPending } = useAction(onboardProgramAction, {
@@ -99,11 +107,23 @@ export function Form() {
}
};
+ const isLoading = isSubmitting || isPending || hasSubmitted;
+
+ const disabledTooltip = !name
+ ? "Please enter a company name."
+ : !logo
+ ? "Please upload a logo."
+ : !url
+ ? "Please enter a valid destination URL."
+ : !supportEmail
+ ? "Please enter a valid support email."
+ : undefined;
+
return (
<form onSubmit={handleSubmit(onSubmit)} className="flex flex-col gap-6">
<label className="space-y-2">
<span className="text-content-emphasis block text-sm font-semibold">
- Company name
+ Company name <span className="text-red-800">*</span>
</span>
<Input
@@ -121,7 +141,7 @@ export function Form() {
<label className="space-y-2">
<span className="text-content-emphasis block text-sm font-semibold">
- Logo
+ Logo <span className="text-red-800">*</span>
</span>
<div className="flex w-full items-center justify-center gap-2 rounded-lg border border-neutral-200 p-1">
@@ -154,7 +174,7 @@ export function Form() {
<label className="space-y-2">
<span className="text-content-emphasis block text-sm font-semibold">
- Destination URL
+ Destination URL <span className="text-red-800">*</span>
</span>
<Controller
@@ -181,7 +201,7 @@ export function Form() {
<label className="space-y-2">
<span className="text-content-emphasis block text-sm font-semibold">
- Support email
+ Support email <span className="text-red-800">*</span>
</span>
<Controller
@@ -207,7 +227,8 @@ export function Form() {
<Button
type="submit"
- loading={isSubmitting || isPending || hasSubmitted}
+ loading={isLoading}
+ disabledTooltip={!isLoading ? disabledTooltip : undefined}
text="Continue"
className="w-full"
/>
diff --git a/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/program/reward/form.tsx b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/program/reward/form.tsx
index e087d85332..bd97460612 100644
--- a/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/program/reward/form.tsx
+++ b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/program/reward/form.tsx
@@ -134,6 +134,16 @@ export function Form() {
});
};
+ const isLoading = isSubmitting || isPending || hasSubmitted;
+
+ const rewardAmount = type === "flat" ? amountInCents : amountInPercentage;
+ const isRewardAmountMissing =
+ rewardAmount == null || Number.isNaN(rewardAmount);
+
+ const disabledTooltip = isRewardAmountMissing
+ ? `Please enter a valid ${type === "percentage" ? "percentage" : "amount"} per ${defaultRewardType}.`
+ : undefined;
+
return (
<form
onSubmit={handleSubmit(onSubmit)}
@@ -141,7 +151,7 @@ export function Form() {
>
<div className="grid grid-cols-1 gap-2">
<h2 className="text-content-emphasis text-sm font-semibold">
- Reward type
+ Reward type <span className="text-red-800">*</span>
</h2>
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
@@ -235,7 +245,7 @@ export function Form() {
{defaultRewardType === "sale" && (
<div className="space-y-2">
<h2 className="text-content-emphasis text-sm font-semibold">
- Commission structure
+ Commission structure <span className="text-red-800">*</span>
</h2>
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
@@ -316,7 +326,7 @@ export function Form() {
commissionStructure === "recurring" && (
<label className="space-y-2">
<span className="block text-sm font-medium text-neutral-800">
- Duration
+ Duration <span className="text-red-800">*</span>
</span>
<select
{...register("maxDuration", {
@@ -345,7 +355,7 @@ export function Form() {
{defaultRewardType === "sale" && (
<div className="space-y-2">
<h2 className="text-content-emphasis text-sm font-semibold">
- Payout model
+ Payout model <span className="text-red-800">*</span>
</h2>
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2">
{PAYOUT_MODELS.map(
@@ -415,7 +425,7 @@ export function Form() {
className="text-content-emphasis block text-sm font-semibold"
>
{type === "percentage" ? "Percentage" : "Amount"} per{" "}
- {defaultRewardType}
+ {defaultRewardType} <span className="text-red-800">*</span>
</label>
<RewardQualityFieldIndicator
event={defaultRewardType as EventType}
@@ -465,8 +475,8 @@ export function Form() {
<Button
text="Continue"
className="w-full"
- loading={isSubmitting || isPending}
- disabled={hasSubmitted}
+ loading={isLoading}
+ disabledTooltip={!isLoading ? disabledTooltip : undefined}
type="submit"
/>
</form>
diff --git a/apps/web/lib/storage.ts b/apps/web/lib/storage.ts
index 44d9b9a44a..6958d38b7d 100644
--- a/apps/web/lib/storage.ts
+++ b/apps/web/lib/storage.ts
@@ -257,6 +257,38 @@ class StorageClient {
}
}
+ private async safeFetch(url: string): Promise<Response> {
+ const maxRedirects = 5;
+ let currentUrl = url;
+
+ for (let redirectCount = 0; redirectCount <= maxRedirects; redirectCount++) {
+ await this.assertSafeUrl(currentUrl);
+
+ const response = await fetchWithTimeout(currentUrl, {
+ redirect: "manual",
+ });
+
+ if (response.ok) {
+ return response;
+ }
+
+ if (response.status >= 300 && response.status < 400) {
+ const location = response.headers.get("location");
+ if (!location) {
+ throw new Error("Redirect response missing location header");
+ }
+ currentUrl = new URL(location, currentUrl).href;
+ continue;
+ }
+
+ throw new Error(
+ `Failed to fetch URL: ${response.status} ${response.statusText}`,
+ );
+ }
+
+ throw new Error("Too many redirects");
+ }
+
private async urlToBlob(url: string, opts?: imageOptions): Promise<Blob> {
let response: Response;
if (opts?.height || opts?.width) {
@@ -268,12 +300,10 @@ class StorageClient {
proxyUrl.searchParams.set("fit", "cover");
response = await fetchWithTimeout(proxyUrl.toString());
} catch (error) {
- await this.assertSafeUrl(url);
- response = await fetch(url, { redirect: "error" });
+ response = await this.safeFetch(url);
}
} else {
- await this.assertSafeUrl(url);
- response = await fetch(url, { redirect: "error" });
+ response = await this.safeFetch(url);
}
if (!response.ok) {
throw new Error(`Failed to fetch URL: ${response.statusText}`);
diff --git a/packages/ui/src/file-upload.tsx b/packages/ui/src/file-upload.tsx
index a217b11315..693d559dcb 100644
--- a/packages/ui/src/file-upload.tsx
+++ b/packages/ui/src/file-upload.tsx
@@ -1,6 +1,6 @@
import { cn, resizeImage } from "@dub/utils";
import { VariantProps, cva } from "class-variance-authority";
-import { DragEvent, ReactNode, useState } from "react";
+import { DragEvent, ReactNode, useEffect, useState } from "react";
import { toast } from "sonner";
import { CloudUpload, Icon, LoadingCircle } from "./icons";
@@ -168,6 +168,11 @@ export function FileUpload({
}: FileUploadProps) {
const [dragActive, setDragActive] = useState(false);
const [fileName, setFileName] = useState<string | null>(null);
+ const [imageError, setImageError] = useState(false);
+
+ useEffect(() => {
+ setImageError(false);
+ }, [imageSrc]);
const onFileChange = async (
e: React.ChangeEvent<HTMLInputElement> | DragEvent,
@@ -266,7 +271,7 @@ export function FileUpload({
dragActive &&
!disabled &&
"cursor-copy border-black bg-neutral-50 opacity-100",
- imageSrc
+ imageSrc && !imageError
? cn(
"opacity-0",
showHoverOverlay && !disabled && "group-hover:opacity-100",
@@ -303,10 +308,13 @@ export function FileUpload({
<span className="sr-only">{accessibilityLabel}</span>
</div>
{imageSrc &&
+ !imageError &&
(customPreview ?? (
<img
src={imageSrc}
alt="Preview"
+ referrerPolicy="no-referrer"
+ onError={() => setImageError(true)}
className={cn(
"h-full w-full rounded-[inherit] object-cover",
previewClassName,