The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Improve onboarding
Steven Tey35a9edd3d852
diff --git a/apps/web/app/api/workspaces/route.ts b/apps/web/app/api/workspaces/route.tsindex 1c2b4d4e14..ababa3b0a6 100644--- a/apps/web/app/api/workspaces/route.ts+++ b/apps/web/app/api/workspaces/route.ts@@ -2,9 +2,10 @@ import { DubApiError } from "@/lib/api/errors";import { createWorkspaceId, prefixWorkspaceId } from "@/lib/api/workspace-id";import { withSession } from "@/lib/auth";import { checkIfUserExists } from "@/lib/planetscale";+import { storage } from "@/lib/storage";import {- WorkspaceSchema,createWorkspaceSchema,+ WorkspaceSchema,} from "@/lib/zod/schemas/workspaces";import { subscribe } from "@dub/email/resend/subscribe";import { prisma } from "@dub/prisma";@@ -13,6 +14,7 @@ import {FREE_WORKSPACES_LIMIT,generateRandomString,nanoid,+ R2_URL,} from "@dub/utils";import { waitUntil } from "@vercel/functions";import { NextResponse } from "next/server";@@ -61,7 +63,7 @@ export const GET = withSession(async ({ session }) => {});export const POST = withSession(async ({ req, session }) => {- const { name, slug } = await createWorkspaceSchema.parseAsync(+ const { name, slug, logo } = await createWorkspaceSchema.parseAsync(await req.json(),);@@ -75,6 +77,8 @@ export const POST = withSession(async ({ req, session }) => {}try {+ let uploadedImageUrl: string | undefined;+const workspace = await prisma.$transaction(async (tx) => {const freeWorkspaces = await tx.project.count({@@ -96,11 +100,17 @@ export const POST = withSession(async ({ req, session }) => {});}+ const workspaceId = createWorkspaceId();+ uploadedImageUrl = logo+ ? `${R2_URL}/workspaces/${workspaceId}/logo_${nanoid(7)}`+ : undefined;+return await tx.project.create({data: {- id: createWorkspaceId(),+ id: workspaceId,name,slug,+ logo: uploadedImageUrl,users: {create: {userId: session.user.id,@@ -161,6 +171,10 @@ export const POST = withSession(async ({ req, session }) => {name: session.user.name || undefined,audience: "app.dub.co",}),+ // Upload logo to R2 if uploaded+ logo &&+ uploadedImageUrl &&+ storage.upload(uploadedImageUrl.replace(`${R2_URL}/`, ""), logo),]),);diff --git a/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/workspace/page.tsx b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/workspace/page.tsxindex a17d630291..aad9c80eae 100644--- a/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/workspace/page.tsx+++ b/apps/web/app/app.dub.co/(onboarding)/onboarding/(steps)/workspace/page.tsx@@ -6,13 +6,16 @@ export default function Workspace() {<StepPagetitle="Create your workspace"description={- <a- href="https://dub.co/help/article/what-is-a-workspace"- target="_blank"- className="underline transition-colors hover:text-neutral-700"- >- What is a workspace?- </a>+ <>+ Set up a common space to manage your links with your team.{" "}+ <a+ href="https://dub.co/help/article/what-is-a-workspace"+ target="_blank"+ className="cursor-help font-medium underline decoration-dotted underline-offset-2 transition-colors hover:text-neutral-700"+ >+ Learn more.+ </a>+ </>}><Form />diff --git a/apps/web/lib/actions/send-otp.ts b/apps/web/lib/actions/send-otp.tsindex 0a96b3ba7a..a032aea2fa 100644--- a/apps/web/lib/actions/send-otp.ts+++ b/apps/web/lib/actions/send-otp.ts@@ -9,6 +9,7 @@ import { flattenValidationErrors } from "next-safe-action";import { getIP } from "../api/utils";import { generateOTP } from "../auth";import { EMAIL_OTP_EXPIRY_IN } from "../auth/constants";+import { isGenericEmail } from "../emails";import z from "../zod";import { emailSchema, passwordSchema } from "../zod/schemas/auth";import { throwIfAuthenticated } from "./auth/throw-if-authenticated";@@ -35,7 +36,7 @@ export const sendOtpAction = actionClientthrow new Error("Too many requests. Please try again later.");}- if (email.includes("+") && email.endsWith("@gmail.com")) {+ if (email.includes("+") && isGenericEmail(email)) {throw new Error("Email addresses with + are not allowed. Please use your work email instead.",);diff --git a/apps/web/lib/emails.ts b/apps/web/lib/emails.tsnew file mode 100644index 0000000000..28997b0d86--- /dev/null+++ b/apps/web/lib/emails.ts@@ -0,0 +1,13 @@+export const isGenericEmail = (email: string) => {+ return (+ email.endsWith("@gmail.com") ||+ email.endsWith("@yahoo.com") ||+ email.endsWith("@hotmail.com") ||+ email.endsWith("@outlook.com") ||+ email.endsWith("@icloud.com") ||+ email.endsWith("@aol.com") ||+ email.endsWith("@comcast.net") ||+ email.endsWith("@verizon.net") ||+ email.endsWith("@att.net")+ );+};diff --git a/apps/web/lib/zod/schemas/misc.ts b/apps/web/lib/zod/schemas/misc.tsindex ca663ada22..2947f8a224 100644--- a/apps/web/lib/zod/schemas/misc.ts+++ b/apps/web/lib/zod/schemas/misc.ts@@ -108,11 +108,19 @@ export const uploadedImageUrlSchema = zmessage: `URL must start with ${R2_URL}`,});+export const publicHostedImageSchema = z+ .string()+ .url()+ .trim()+ .refine((url) => url.startsWith("http://") || url.startsWith("https://"), {+ message: "Image URL must start with http:// or https://",+ });+// Base64 encoded image or R2_URL// This schema contains an async refinement check for base64 image validation,// which requires using parseAsync() instead of parse() when validatingexport const uploadedImageSchema = z- .union([base64ImageSchema, uploadedImageUrlSchema])+ .union([base64ImageSchema, uploadedImageUrlSchema, publicHostedImageSchema]).transform((v) => v || null);// Base64 encoded image/SVG or R2_URL@@ -121,11 +129,3 @@ export const uploadedImageSchema = zexport const uploadedImageAllowSVGSchema = z.union([base64ImageAllowSVGSchema, uploadedImageUrlSchema]).transform((v) => v || null);--export const publicHostedImageSchema = z- .string()- .url()- .trim()- .refine((url) => url.startsWith("http://") || url.startsWith("https://"), {- message: "Image URL must start with http:// or https://",- });diff --git a/apps/web/ui/workspaces/create-workspace-form.tsx b/apps/web/ui/workspaces/create-workspace-form.tsxindex b00389c965..c79d54b7dc 100644--- a/apps/web/ui/workspaces/create-workspace-form.tsx+++ b/apps/web/ui/workspaces/create-workspace-form.tsx@@ -1,19 +1,22 @@"use client";+import { isGenericEmail } from "@/lib/emails";import { AlertCircleFill } from "@/ui/shared/icons";-import { Button, InfoTooltip, useMediaQuery } from "@dub/ui";-import { cn } from "@dub/utils";+import { Button, buttonVariants, FileUpload, useMediaQuery } from "@dub/ui";+import { cn, GOOGLE_FAVICON_URL } from "@dub/utils";import slugify from "@sindresorhus/slugify";import { useSession } from "next-auth/react";import { usePlausible } from "next-plausible";import posthog from "posthog-js";-import { useForm } from "react-hook-form";+import { useEffect } from "react";+import { Controller, useForm } from "react-hook-form";import { toast } from "sonner";import { mutate } from "swr";type FormData = {name: string;slug: string;+ logo?: string;};export function CreateWorkspaceForm({@@ -23,7 +26,7 @@ export function CreateWorkspaceForm({onSuccess?: (data: FormData) => void;className?: string;}) {- const { update } = useSession();+ const { data: session, update } = useSession();const plausible = usePlausible();const {@@ -33,11 +36,21 @@ export function CreateWorkspaceForm({setValue,setError,clearErrors,+ control,formState: { isSubmitting, isSubmitSuccessful, errors },} = useForm<FormData>();const slug = watch("slug");+ useEffect(() => {+ if (session?.user?.email && !isGenericEmail(session.user.email)) {+ const emailDomain = session.user.email.split("@")[1];+ setValue("logo", `${GOOGLE_FAVICON_URL}${emailDomain}`);+ } else if (session?.user?.image) {+ setValue("logo", session.user.image);+ }+ }, [session?.user]);+const { isMobile } = useMediaQuery();return (@@ -89,9 +102,6 @@ export function CreateWorkspaceForm({<p className="block text-sm font-medium text-neutral-700">Workspace Name</p>- <InfoTooltip- content={`This is the name of your workspace on ${process.env.NEXT_PUBLIC_APP_NAME}.`}- /></label><div className="mt-2 flex rounded-md shadow-sm"><input@@ -114,9 +124,6 @@ export function CreateWorkspaceForm({<p className="block text-sm font-medium text-neutral-700">Workspace Slug</p>- <InfoTooltip- content={`This is your workspace's unique slug on ${process.env.NEXT_PUBLIC_APP_NAME}.`}- /></label><div className="relative mt-2 flex rounded-md shadow-sm"><span className="inline-flex items-center rounded-l-md border border-r-0 border-neutral-300 bg-neutral-50 px-5 text-neutral-500 sm:text-sm">@@ -162,13 +169,65 @@ export function CreateWorkspaceForm({</div>)}</div>- {errors.slug && (- <p className="mt-2 text-sm text-red-600" id="slug-error">+ {errors.slug ? (+ <p+ className="mt-1.5 text-xs font-medium text-red-600"+ id="slug-error"+ >{errors.slug.message}</p>+ ) : (+ <p className="mt-1.5 text-xs text-neutral-500">+ You can always change this later in your workspace settings.+ </p>)}</div>+ <div>+ <label>+ <p className="block text-sm font-medium text-neutral-700">+ Workspace Logo+ </p>+ <div className="mt-1.5 flex items-center gap-5">+ <Controller+ control={control}+ name="logo"+ render={({ field }) => (+ <FileUpload+ accept="images"+ className={cn(+ "size-20 rounded-full border border-neutral-300",+ errors.logo && "border-0 ring-2 ring-red-500",+ )}+ iconClassName="size-5"+ previewClassName="size-10 rounded-full"+ variant="plain"+ imageSrc={field.value}+ readFile+ onChange={({ src }) => field.onChange(src)}+ content={null}+ maxFileSizeMB={2}+ targetResolution={{ width: 160, height: 160 }}+ />+ )}+ />+ <div>+ <div+ className={cn(+ buttonVariants({ variant: "secondary" }),+ "flex h-7 w-fit cursor-pointer items-center rounded-md border px-2 text-xs",+ )}+ >+ Upload image+ </div>+ <p className="mt-1.5 text-xs text-neutral-500">+ Recommended size: 160x160px+ </p>+ </div>+ </div>+ </label>+ </div>+<Buttonloading={isSubmitting || isSubmitSuccessful}text="Create workspace"