The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
WIP onboarding
Tim Wilson19a30b467da4
diff --git a/apps/web/app/partners.dub.co/(onboarding)/layout.tsx b/apps/web/app/partners.dub.co/(onboarding)/layout.tsxdeleted file mode 100644index 01b93ede4a..0000000000--- a/apps/web/app/partners.dub.co/(onboarding)/layout.tsx+++ /dev/null@@ -1,17 +0,0 @@-import { NewBackground } from "@/ui/shared/new-background";-import { SessionProvider } from "next-auth/react";--export default function AdminAuthLayout({- children,-}: {- children: React.ReactNode;-}) {- return (- <SessionProvider>- <div className="relative z-10 flex flex-col items-center justify-center">- {children}- </div>- <NewBackground />- </SessionProvider>- );-}diff --git a/apps/web/app/partners.dub.co/onboarding/layout.tsx b/apps/web/app/partners.dub.co/onboarding/layout.tsxnew file mode 100644index 0000000000..3742bf6849--- /dev/null+++ b/apps/web/app/partners.dub.co/onboarding/layout.tsx@@ -0,0 +1,22 @@+"use client";++import { Grid } from "@dub/ui";+import { SessionProvider } from "next-auth/react";++export default function AdminAuthLayout({+ children,+}: {+ children: React.ReactNode;+}) {+ return (+ <SessionProvider>+ <div className="fixed inset-0 [mask-image:radial-gradient(60%_60%_at_50%_0%,black,transparent)]">+ <Grid className="text-neutral-200" />+ <div className="absolute inset-0 -translate-y-1/2 -scale-x-100 bg-[conic-gradient(from_-32deg,#f00_0deg,#EAB308_99deg,#5CFF80_162deg,#00FFF9_216deg,#3A8BFD_288deg,#855AFC_360deg)] opacity-25 blur-[200px]" />+ </div>+ <div className="relative z-10 flex flex-col items-center justify-center">+ {children}+ </div>+ </SessionProvider>+ );+}diff --git a/apps/web/app/partners.dub.co/onboarding/onboarding-form.tsx b/apps/web/app/partners.dub.co/onboarding/onboarding-form.tsxnew file mode 100644index 0000000000..e70280e006--- /dev/null+++ b/apps/web/app/partners.dub.co/onboarding/onboarding-form.tsx@@ -0,0 +1,110 @@+"use client";++import { onboardPartner } from "@/lib/actions/partners/onboard-partner";+import { AlertCircleFill } from "@/ui/shared/icons";+import { Button, useMediaQuery } from "@dub/ui";+import { cn } from "@dub/utils/src/functions";+import { useRouter } from "next/navigation";+import { useForm } from "react-hook-form";+import { toast } from "sonner";++export function OnboardingForm() {+ const { isMobile } = useMediaQuery();+ const router = useRouter();++ const {+ register,+ handleSubmit,+ setError,+ formState: { errors, isSubmitting, isSubmitSuccessful },+ } = useForm<{+ name: string;+ slug: string;+ }>();++ return (+ <form+ onSubmit={handleSubmit(async (data) => {+ try {+ const result = await onboardPartner(data);+ if (!result?.data?.ok) {+ if (result?.data?.slugConflict)+ setError("slug", {+ message: `The slug "${data.slug}" is already in use.`,+ });+ else throw new Error("Failed to create partner");+ return;+ }+ router.push(`/${result?.data?.slug}`);+ } catch (error) {+ console.error(error);+ setError("root.serverError", {+ message: "Failed to create partner profile. Please try again.",+ });+ toast.error("Failed to create partner profile. Please try again.");+ }+ })}+ className="flex w-full flex-col gap-6 text-left"+ >+ <label>+ <span className="text-sm font-medium text-gray-800">Business name</span>+ <input+ type="text"+ className={cn(+ "mt-2 block w-full rounded-md focus:outline-none sm:text-sm",+ errors.name+ ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"+ : "border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:ring-gray-500",+ )}+ placeholder="Acme, Inc."+ {...register("name", {+ required: true,+ })}+ />+ </label>++ <label>+ <span className="text-sm font-medium text-gray-800">Partner slug</span>+ <div className="relative mt-2 flex rounded-md shadow-sm">+ <span className="inline-flex items-center rounded-l-md border border-r-0 border-gray-300 bg-gray-50 px-3 text-gray-500 sm:text-sm">+ partners.{process.env.NEXT_PUBLIC_APP_DOMAIN}+ </span>+ <input+ type="text"+ autoComplete="off"+ className={`${+ errors.slug+ ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"+ : "border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:ring-gray-500"+ } block w-full rounded-r-md focus:outline-none sm:text-sm`}+ placeholder="acme"+ {...register("slug", {+ required: true,+ minLength: 3,+ maxLength: 48,+ pattern: /^[a-zA-Z0-9\-]+$/,+ })}+ />+ {errors.slug && (+ <div className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3">+ <AlertCircleFill+ className="h-5 w-5 text-red-500"+ aria-hidden="true"+ />+ </div>+ )}+ </div>+ {errors.slug && (+ <span className="text-xs text-red-600">{errors.slug.message}</span>+ )}+ </label>++ <Button+ type="submit"+ text="Create partner account"+ className="mt-2"+ loading={isSubmitting || isSubmitSuccessful}+ />+ </form>+ );+}diff --git a/apps/web/app/partners.dub.co/onboarding/page.tsx b/apps/web/app/partners.dub.co/onboarding/page.tsxnew file mode 100644index 0000000000..f1f59b8b7a--- /dev/null+++ b/apps/web/app/partners.dub.co/onboarding/page.tsx@@ -0,0 +1,24 @@+import { Wordmark } from "@dub/ui";+import { ConnectedDots4 } from "@dub/ui/src/icons";+import { OnboardingForm } from "./onboarding-form";+export default function Onboarding() {+ return (+ <div className="relative mx-auto mt-10 flex w-full max-w-sm flex-col items-center px-3 text-center md:px-8">+ <div className="animate-slide-up-fade relative flex w-auto flex-col items-center [--offset:10px] [animation-duration:1.3s] [animation-fill-mode:both]">+ <Wordmark className="relative h-10" />+ <span className="text-sm font-medium text-neutral-700">Partner</span>+ </div>+ <div className="mt-10 flex w-full flex-col items-center md:mt-16 lg:mt-20">+ <div className="animate-slide-up-fade flex size-10 items-center justify-center rounded-full border border-neutral-200 backdrop-blur-sm [--offset:8px] [animation-delay:250ms] [animation-duration:1s] [animation-fill-mode:both]">+ <ConnectedDots4 className="size-5 text-neutral-900" />+ </div>+ <h1 className="animate-slide-up-fade mt-6 text-lg font-medium [--offset:8px] [animation-delay:250ms] [animation-duration:1s] [animation-fill-mode:both]">+ Create a Dub Partner profile+ </h1>+ <div className="animate-slide-up-fade mt-10 w-full [--offset:10px] [animation-delay:500ms] [animation-duration:1s] [animation-fill-mode:both]">+ <OnboardingForm />+ </div>+ </div>+ </div>+ );+}diff --git a/apps/web/lib/actions/partners/onboard-partner.ts b/apps/web/lib/actions/partners/onboard-partner.tsnew file mode 100644index 0000000000..49fea1025f--- /dev/null+++ b/apps/web/lib/actions/partners/onboard-partner.ts@@ -0,0 +1,42 @@+"use server";++import { prisma } from "@/lib/prisma";+import { Prisma } from "@prisma/client";+import z from "../../zod";+import { authUserActionClient } from "../safe-action";++const onboardPartnerSchema = z.object({+ name: z.string(),+ slug: z.string(),+});++// Update the notification preference for a user in a workspace+export const onboardPartner = authUserActionClient+ .schema(onboardPartnerSchema)+ .action(async ({ ctx, parsedInput }) => {+ const { user } = ctx;+ const { name, slug } = parsedInput;++ try {+ const partner = await prisma.partner.create({+ data: {+ name,+ slug,+ users: {+ create: {+ userId: user.id,+ role: "owner",+ },+ },+ },+ });+ return { ok: true, slug: partner.slug };+ } catch (e) {+ const slugConflict =+ e instanceof Prisma.PrismaClientKnownRequestError && e.code === "P2002";+ return {+ ok: false,+ slugConflict,+ };+ }+ });diff --git a/apps/web/prisma/schema/partner.prisma b/apps/web/prisma/schema/partner.prismaindex 0f9dba31b4..36ce2d06c2 100644--- a/apps/web/prisma/schema/partner.prisma+++ b/apps/web/prisma/schema/partner.prisma@@ -12,6 +12,7 @@ enum PartnerRole {model Partner {id String @id @default(cuid())name String+ slug String @uniquelogo String?bio String? @db.LongTextcountry String?diff --git a/packages/ui/src/icons/nucleo/connected-dots4.tsx b/packages/ui/src/icons/nucleo/connected-dots4.tsxnew file mode 100644index 0000000000..7df2107805--- /dev/null+++ b/packages/ui/src/icons/nucleo/connected-dots4.tsx@@ -0,0 +1,100 @@+import { SVGProps } from "react";++export function ConnectedDots4(props: SVGProps<SVGSVGElement>) {+ return (+ <svg+ height="18"+ width="18"+ viewBox="0 0 18 18"+ xmlns="http://www.w3.org/2000/svg"+ {...props}+ >+ <g fill="currentColor">+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="4.664"+ x2="7.586"+ y1="7.586"+ y2="4.664"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="10.414"+ x2="13.336"+ y1="4.664"+ y2="7.586"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="13.336"+ x2="10.414"+ y1="10.414"+ y2="13.336"+ />+ <line+ fill="none"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ x1="7.586"+ x2="4.664"+ y1="13.336"+ y2="10.414"+ />+ <circle+ cx="9"+ cy="3.25"+ fill="none"+ r="2"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ <circle+ cx="3.25"+ cy="9"+ fill="none"+ r="2"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ <circle+ cx="9"+ cy="14.75"+ fill="none"+ r="2"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ <circle+ cx="14.75"+ cy="9"+ fill="none"+ r="2"+ stroke="currentColor"+ strokeLinecap="round"+ strokeLinejoin="round"+ strokeWidth="1.5"+ />+ </g>+ </svg>+ );+}diff --git a/packages/ui/src/icons/nucleo/index.ts b/packages/ui/src/icons/nucleo/index.tsindex 832ba62e4d..66b0a59821 100644--- a/packages/ui/src/icons/nucleo/index.ts+++ b/packages/ui/src/icons/nucleo/index.ts@@ -32,6 +32,7 @@ export * from "./circles3";export * from "./cloud-upload";export * from "./code";export * from "./connected-dots";+export * from "./connected-dots4";export * from "./crosshairs3";export * from "./cube";export * from "./cube-settings";