The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add fields to onboarding
Tim Wilson7d9fad5f453e
diff --git a/apps/web/app/partners.dub.co/onboarding/onboarding-form.tsx b/apps/web/app/partners.dub.co/onboarding/onboarding-form.tsxindex 6c1d784f60..fb346c5b22 100644--- a/apps/web/app/partners.dub.co/onboarding/onboarding-form.tsx+++ b/apps/web/app/partners.dub.co/onboarding/onboarding-form.tsx@@ -1,10 +1,12 @@"use client";import { onboardPartner } from "@/lib/actions/partners/onboard-partner";-import { Button, useMediaQuery } from "@dub/ui";+import { Button, Combobox, FileUpload, useMediaQuery } from "@dub/ui";+import { COUNTRIES } from "@dub/utils";import { cn } from "@dub/utils/src/functions";import { useRouter } from "next/navigation";-import { useForm } from "react-hook-form";+import { useMemo } from "react";+import { Controller, useForm } from "react-hook-form";import { toast } from "sonner";export function OnboardingForm() {@@ -13,11 +15,15 @@ export function OnboardingForm() {const {register,+ control,handleSubmit,setError,formState: { errors, isSubmitting, isSubmitSuccessful },} = useForm<{name: string;+ logo: string;+ country: string;+ description: string;}>();return (@@ -35,10 +41,13 @@ export function OnboardingForm() {toast.error("Failed to create partner profile. Please try again.");}})}- className="flex w-full flex-col gap-6 text-left"+ className="flex w-full flex-col gap-4 text-left"><label>- <span className="text-sm font-medium text-gray-800">Name</span>+ <span className="text-sm font-medium text-gray-800">+ Name+ <span className="ml-0.5 text-red-600/60">*</span>+ </span><inputtype="text"className={cn(@@ -55,6 +64,51 @@ export function OnboardingForm() {/></label>+ <label>+ <span className="text-sm font-medium text-gray-800">Logo</span>+ <Controller+ control={control}+ name="logo"+ render={({ field }) => (+ <FileUpload+ accept="images"+ className="mt-2 h-14 w-full rounded-md border border-gray-300"+ iconClassName="w-5 h-5"+ previewClassName="size-10 rounded-full"+ variant="plain"+ imageSrc={field.value}+ readFile+ onChange={({ src }) => field.onChange(src)}+ content={null}+ maxFileSizeMB={2}+ />+ )}+ />+ </label>++ <label>+ <span className="text-sm font-medium text-gray-800">Country</span>+ <Controller+ control={control}+ name="country"+ render={({ field }) => <CountryCombobox {...field} />}+ />+ </label>++ <label>+ <span className="text-sm font-medium text-gray-800">Description</span>+ <textarea+ 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="Tell us about your business"+ {...register("description")}+ />+ </label>+<Buttontype="submit"text="Create partner account"@@ -64,3 +118,59 @@ export function OnboardingForm() {</form>);}++function CountryCombobox({+ value,+ onChange,+}: {+ value: string;+ onChange: (value: string) => void;+}) {+ const options = useMemo(+ () =>+ Object.entries(COUNTRIES).map(([key, value]) => ({+ icon: (+ <img+ alt={value}+ src={`https://flag.vercel.app/m/${key}.svg`}+ className="mr-1 h-2.5 w-4"+ />+ ),+ value: key,+ label: value,+ })),+ [],+ );++ return (+ <Combobox+ selected={options.find((o) => o.value === value) ?? null}+ setSelected={(option) => {+ if (!option) return;+ onChange(option.value);+ }}+ options={options}+ icon={+ value ? (+ <img+ alt={COUNTRIES[value]}+ src={`https://flag.vercel.app/m/${value}.svg`}+ className="h-2.5 w-4"+ />+ ) : undefined+ }+ caret={true}+ placeholder="Select country"+ searchPlaceholder="Search countries..."+ matchTriggerWidth+ buttonProps={{+ className: cn(+ "mt-2 w-full justify-start border-gray-300 px-3",+ "data-[state=open]:ring-1 data-[state=open]:ring-gray-500 data-[state=open]:border-gray-500",+ "focus:ring-1 focus:ring-gray-500 focus:border-gray-500 transition-none",+ !value && "text-gray-400",+ ),+ }}+ />+ );+}diff --git a/apps/web/app/partners.dub.co/onboarding/page.tsx b/apps/web/app/partners.dub.co/onboarding/page.tsxindex f1f59b8b7a..4332af7fee 100644--- a/apps/web/app/partners.dub.co/onboarding/page.tsx+++ b/apps/web/app/partners.dub.co/onboarding/page.tsx@@ -8,14 +8,14 @@ export default function Onboarding() {<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="my-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]">+ <div className="animate-slide-up-fade mt-8 w-full [--offset:10px] [animation-delay:500ms] [animation-duration:1s] [animation-fill-mode:both]"><OnboardingForm /></div></div>diff --git a/apps/web/lib/actions/partners/onboard-partner.ts b/apps/web/lib/actions/partners/onboard-partner.tsindex 8cd92e11b8..6da2dacdb0 100644--- a/apps/web/lib/actions/partners/onboard-partner.ts+++ b/apps/web/lib/actions/partners/onboard-partner.ts@@ -3,11 +3,16 @@import { createId } from "@/lib/api/utils";import { getFeatureFlags } from "@/lib/edge-config";import { prisma } from "@/lib/prisma";+import { storage } from "@/lib/storage";+import { nanoid } from "nanoid";import z from "../../zod";import { authUserActionClient } from "../safe-action";const onboardPartnerSchema = z.object({name: z.string(),+ logo: z.string().nullable(),+ country: z.string().nullable(),+ description: z.string().nullable(),});// Update the notification preference for a user in a workspace@@ -24,13 +29,15 @@ export const onboardPartner = authUserActionClient};}- const { name } = parsedInput;+ const { name, logo, country, description } = parsedInput;try {- const partner = await prisma.partner.create({+ let partner = await prisma.partner.create({data: {- id: createId({ prefix: "pn_" }),name,+ country,+ bio: description,+ id: createId({ prefix: "pn_" }),users: {create: {userId: user.id,@@ -39,8 +46,22 @@ export const onboardPartner = authUserActionClient},},});++ if (logo) {+ const { url } = await storage.upload(+ `logos/partners/${partner.id}_${nanoid(7)}`,+ logo,+ );++ partner = await prisma.partner.update({+ where: { id: partner.id },+ data: { logo: url },+ });+ }+return { ok: true, partnerId: partner.id };} catch (e) {+ console.error(e);return {ok: false,};diff --git a/packages/ui/src/file-upload.tsx b/packages/ui/src/file-upload.tsxindex 7fb0b21b55..cd2891dc50 100644--- a/packages/ui/src/file-upload.tsx+++ b/packages/ui/src/file-upload.tsx@@ -56,6 +56,7 @@ export type FileUploadProps = FileUploadReadFileProps & {className?: string;iconClassName?: string;+ previewClassName?: string;/*** Image to display (generally for image uploads)@@ -106,6 +107,7 @@ export function FileUpload({variant,className,iconClassName,+ previewClassName,accept = "any",imageSrc,loading = false,@@ -242,7 +244,10 @@ export function FileUpload({<imgsrc={imageSrc}alt="Preview"- className="h-full w-full rounded-[inherit] object-cover"+ className={cn(+ "h-full w-full rounded-[inherit] object-cover",+ previewClassName,+ )}/>)}{clickToUpload && (