The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update profile info page
Tim Wilson06b26586a866
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsxindex 1e2ec470a7..bc31711e70 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page-client.tsx@@ -4,11 +4,13 @@ import { updatePartnerProfileAction } from "@/lib/actions/partners/update-partneimport usePartnerPayoutsCount from "@/lib/swr/use-partner-payouts-count";import usePartnerProfile from "@/lib/swr/use-partner-profile";import { PartnerProps, PayoutsCount } from "@/lib/types";+import { PageContent } from "@/ui/layout/page-content";import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";import { CountryCombobox } from "@/ui/partners/country-combobox";import {Button,buttonVariants,+ DotsPattern,FileUpload,LoadingSpinner,ToggleGroup,@@ -18,58 +20,86 @@ import { cn, OG_AVATAR_URL } from "@dub/utils";import { PartnerProfileType } from "@prisma/client";import { AnimatePresence, LayoutGroup, motion } from "framer-motion";import { useAction } from "next-safe-action/hooks";-import { PropsWithChildren, useRef } from "react";-import { Controller, useForm } from "react-hook-form";+import { PropsWithChildren, RefObject, useRef } from "react";+import {+ Controller,+ FormProvider as FormContextProvider,+ useForm,+ useFormContext,+} from "react-hook-form";import ReactTextareaAutosize from "react-textarea-autosize";import { toast } from "sonner";export function ProfileSettingsPageClient() {const { partner, error } = usePartnerProfile();+ const formRef = useRef<HTMLFormElement>(null);+return (- <PageWidthWrapper className="mb-20 flex flex-col gap-8">- <div className="max-w-screen-md rounded-lg border border-neutral-200 bg-white">- <div className="border-b border-neutral-200 p-6">- <div className="flex items-center gap-2">- <h2 className="text-xl font-medium text-neutral-800">About you</h2>+ <FormWrapper partner={partner}>+ <PageContent+ title="Profile info"+ controls={<Controls formRef={formRef} />}+ >+ <PageWidthWrapper className="mb-20 flex flex-col gap-8">+ <div className="relative m-1 mb-8">+ <div+ className="pointer-events-none absolute inset-0 rounded-2xl bg-neutral-100/50 [mask-image:linear-gradient(black,transparent_60%)]"+ aria-hidden+ >+ <div className="absolute inset-4 overflow-hidden">+ <div className="absolute inset-y-0 left-1/2 w-[1200px] -translate-x-1/2">+ <DotsPattern className="text-neutral-200/80" />+ </div>+ </div>+ </div>+ <div className="relative mx-auto my-12 w-full max-w-[400px]">+ {partner ? (+ <ProfileForm partner={partner} formRef={formRef} />+ ) : (+ <div className="flex h-32 w-full items-center justify-center">+ {error ? (+ <span className="text-sm text-neutral-500">+ Failed to load profile data+ </span>+ ) : (+ <LoadingSpinner />+ )}+ </div>+ )}+ </div></div>- </div>+ </PageWidthWrapper>+ </PageContent>+ </FormWrapper>+ );+}- {partner ? (- <ProfileForm partner={partner} />- ) : (- <div className="flex h-32 w-full items-center justify-center">- {error ? (- <span className="text-sm text-neutral-500">- Failed to load profile data- </span>- ) : (- <LoadingSpinner />- )}- </div>- )}- </div>- </PageWidthWrapper>+function FormWrapper({+ partner,+ children,+}: PropsWithChildren<{ partner?: PartnerProps }>) {+ return partner ? (+ <FormProvider partner={partner}>{children}</FormProvider>+ ) : (+ children);}-function ProfileForm({ partner }: { partner: PartnerProps }) {- const {- register,- control,- handleSubmit,- setError,- watch,- setValue,- formState: { errors, isSubmitting },- } = useForm<{- name: string;- image: string | null;- description: string | null;- country: string;- profileType: PartnerProfileType;- companyName: string | null;- }>({+type ProfileFormData = {+ name: string;+ image: string | null;+ description: string | null;+ country: string;+ profileType: PartnerProfileType;+ companyName: string | null;+};++function FormProvider({+ partner,+ children,+}: PropsWithChildren<{ partner: PartnerProps }>) {+ const form = useForm<ProfileFormData>({defaultValues: {name: partner.name,image: partner.image,@@ -80,6 +110,41 @@ function ProfileForm({ partner }: { partner: PartnerProps }) {},});+ return <FormContextProvider {...form}>{children}</FormContextProvider>;+}++function Controls({ formRef }: { formRef: RefObject<HTMLFormElement> }) {+ const {+ formState: { isSubmitting },+ } = useFormContext();++ return (+ <Button+ text="Save changes"+ className="h-8 w-fit px-2.5"+ loading={isSubmitting}+ onClick={() => formRef.current?.requestSubmit()}+ />+ );+}++function ProfileForm({+ partner,+ formRef,+}: {+ partner: PartnerProps;+ formRef: RefObject<HTMLFormElement>;+}) {+ const {+ register,+ control,+ handleSubmit,+ setError,+ watch,+ setValue,+ formState: { errors },+ } = useFormContext<ProfileFormData>();+const { profileType } = watch();const { payoutsCount } = usePartnerPayoutsCount<PayoutsCount[]>({@@ -89,10 +154,9 @@ function ProfileForm({ partner }: { partner: PartnerProps }) {const completedPayoutsCount =payoutsCount?.find((payout) => payout.status === "completed")?.count ?? 0;- const formRef = useRef<HTMLFormElement>(null);- const { handleKeyDown } = useEnterSubmit(formRef);+ const { handleKeyDown } = useEnterSubmit();- const { executeAsync, isPending } = useAction(updatePartnerProfileAction, {+ const { executeAsync } = useAction(updatePartnerProfileAction, {onSuccess: async () => {toast.success("Profile updated successfully.");},@@ -118,164 +182,147 @@ function ProfileForm({ partner }: { partner: PartnerProps }) {})}><div className="px-5">- <div className="grid grid-cols-1 items-center sm:grid-cols-2">- <FormRow>- <label className="contents">- <span className="text-sm font-medium text-neutral-800">- Display Image- </span>- <div className="flex items-center gap-5">- <Controller- control={control}- name="image"- render={({ field }) => (- <FileUpload- accept="images"- className="mt-2 size-14 shrink-0 rounded-full border border-neutral-300"- iconClassName="w-5 h-5"- previewClassName="size-14 rounded-full"- variant="plain"- imageSrc={- field.value || `${OG_AVATAR_URL}${partner?.name}`- }- 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>- </FormRow>-- <FormRow>- <label className="contents">- <span className="text-sm font-medium text-neutral-800">- Full Name- </span>+ <div className="flex flex-col gap-6">+ <label>+ <div className="flex items-center gap-5">+ <Controller+ control={control}+ name="image"+ render={({ field }) => (+ <FileUpload+ accept="images"+ className="size-20 shrink-0 rounded-full border border-neutral-300 sm:size-32"+ iconClassName="w-5 h-5"+ previewClassName="size-20 sm:size-32 rounded-full"+ variant="plain"+ imageSrc={field.value || `${OG_AVATAR_URL}${partner?.name}`}+ readFile+ onChange={({ src }) => field.onChange(src)}+ content={null}+ maxFileSizeMB={2}+ targetResolution={{ width: 160, height: 160 }}+ />+ )}+ /><div>- <input- type="text"+ <divclassName={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-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",- )}- placeholder="Acme, Inc."- {...register("name", {- required: true,- })}- />- </div>- </label>- </FormRow>-- <FormRow>- <label className="contents">- <span className="text-sm font-medium text-neutral-800">- Country- </span>- <div>- <Controller- control={control}- name="country"- rules={{ required: true }}- render={({ field }) => (- <CountryCombobox- value={field.value || ""}- onChange={field.onChange}- error={errors.country ? true : false}- disabledTooltip={- completedPayoutsCount > 0- ? "Since you've already received payouts on Dub, you cannot change your country. If you need to update your country, please contact support."- : undefined- }- />+ buttonVariants({ variant: "secondary" }),+ "flex h-8 w-fit cursor-pointer items-center rounded-md border px-2.5 text-xs",)}- />+ >+ Upload image+ </div>+ <p className="mt-1.5 text-xs text-neutral-500">+ Recommended size: 160x160px+ </p></div>- </label>- </FormRow>+ </div>+ </label>+ <label className="flex flex-col gap-1.5">+ <span className="text-sm font-medium text-neutral-800">+ Full name+ </span>+ <div>+ <input+ type="text"+ className={cn(+ "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-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",+ )}+ placeholder="Acme, Inc."+ {...register("name", {+ required: true,+ })}+ />+ </div>+ </label>+ <label className="flex flex-col">+ <span className="text-sm font-medium text-neutral-800">+ Country+ </span>+ <div>+ <Controller+ control={control}+ name="country"+ rules={{ required: true }}+ render={({ field }) => (+ <CountryCombobox+ value={field.value || ""}+ onChange={field.onChange}+ error={errors.country ? true : false}+ disabledTooltip={+ completedPayoutsCount > 0+ ? "Since you've already received payouts on Dub, you cannot change your country. If you need to update your country, please contact support."+ : undefined+ }+ />+ )}+ />+ </div>+ </label>- <FormRow>- <label className="contents">- <span className="text-sm font-medium text-neutral-800">- Description- </span>- <div>- <ReactTextareaAutosize- 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-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",- )}- placeholder="Tell us about the kind of content you create – e.g. tech, travel, fashion, etc."- minRows={3}- maxRows={10}- onKeyDown={handleKeyDown}- {...register("description")}- />- </div>- </label>- </FormRow>+ <label className="flex flex-col gap-1.5">+ <span className="text-sm font-medium text-neutral-800">+ About yourself+ </span>+ <div>+ <ReactTextareaAutosize+ className={cn(+ "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-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",+ )}+ placeholder="Tell us about the kind of content you create – e.g. tech, travel, fashion, etc."+ minRows={3}+ maxRows={10}+ onKeyDown={handleKeyDown}+ {...register("description")}+ />+ </div>+ </label>- <FormRow>- <label className="contents">- <span className="text-sm font-medium text-neutral-800">- Profile Type- </span>- <div className="w-full">- <LayoutGroup>- <div className="w-full">- <ToggleGroup- options={[- {- value: "individual",- label: "Individual",- },- {- value: "company",- label: "Company",- },- ]}- selected={profileType}- selectAction={(option: "individual" | "company") => {- if (completedPayoutsCount === 0) {- setValue("profileType", option);- }- }}- className={cn(- "flex w-full items-center gap-0.5 rounded-lg border-neutral-300 bg-neutral-100 p-0.5",- completedPayoutsCount > 0 && "cursor-not-allowed",- )}- optionClassName={cn(- "h-9 flex items-center justify-center rounded-lg flex-1",- completedPayoutsCount > 0 && "pointer-events-none",- )}- indicatorClassName="bg-white"- />- </div>- </LayoutGroup>- </div>- </label>- </FormRow>+ <label className="flex flex-col gap-1.5">+ <span className="text-sm font-medium text-neutral-800">+ Profile type+ </span>+ <div className="w-full">+ <LayoutGroup>+ <div className="w-full">+ <ToggleGroup+ options={[+ {+ value: "individual",+ label: "Individual",+ },+ {+ value: "company",+ label: "Company",+ },+ ]}+ selected={profileType}+ selectAction={(option: "individual" | "company") => {+ if (completedPayoutsCount === 0) {+ setValue("profileType", option);+ }+ }}+ className={cn(+ "flex w-full items-center gap-0.5 rounded-lg border-neutral-300 bg-neutral-100 p-0.5",+ completedPayoutsCount > 0 && "cursor-not-allowed",+ )}+ optionClassName={cn(+ "h-9 flex items-center justify-center rounded-lg flex-1",+ completedPayoutsCount > 0 && "pointer-events-none",+ )}+ indicatorClassName="bg-white"+ />+ </div>+ </LayoutGroup>+ </div>+ </label><AnimatePresence mode="popLayout">{profileType === "company" && (@@ -293,49 +340,39 @@ function ProfileForm({ partner }: { partner: PartnerProps }) {}}className="contents">- <FormRow>- <label className="contents">- <span className="text-sm font-medium text-neutral-800">- Legal company name- </span>- <div>- <input- type="text"- className={cn(- "mt-2 block w-full rounded-md focus:outline-none sm:text-sm",- errors.companyName- ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"- : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",- )}- disabled={completedPayoutsCount > 0}- {...register("companyName", {- required: profileType === "company",- })}- />- </div>- </label>- </FormRow>+ <label className="flex flex-col gap-1.5">+ <span className="text-sm font-medium text-neutral-800">+ Legal company name+ </span>+ <div>+ <input+ type="text"+ className={cn(+ "block w-full rounded-md focus:outline-none sm:text-sm",+ errors.companyName+ ? "border-red-300 pr-10 text-red-900 placeholder-red-300 focus:border-red-500 focus:ring-red-500"+ : "border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:ring-neutral-500",+ )}+ disabled={completedPayoutsCount > 0}+ {...register("companyName", {+ required: profileType === "company",+ })}+ />+ </div>+ </label></motion.div>)}</AnimatePresence></div></div>- <div className="flex justify-end rounded-b-lg border-t border-neutral-200 bg-neutral-100 px-5 py-3.5">+ {/* <div className="flex justify-end rounded-b-lg border-t border-neutral-200 bg-neutral-100 px-5 py-3.5"><Buttontype="submit"text="Save changes"className="h-8 w-fit px-2.5"loading={isSubmitting || isPending}/>- </div>+ </div> */}</form>);}--function FormRow({ children }: PropsWithChildren) {- return (- <div className="contents [&:not(:last-child)>label>*:nth-child(even)]:border-b sm:[&:not(:last-child)>label>*]:border-b [&>label>*:first-child]:pt-5 [&>label>*:last-child]:pb-6 [&>label>*]:flex [&>label>*]:h-full [&>label>*]:items-center [&>label>*]:border-neutral-200 sm:[&>label>*]:py-5">- {children}- </div>- );-}diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page.tsxindex 627c6fe530..efa6be99b2 100644--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page.tsx+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/page.tsx@@ -1,10 +1,5 @@-import { PageContent } from "@/ui/layout/page-content";import { ProfileSettingsPageClient } from "./page-client";export default function ProfileSettingsPage() {- return (- <PageContent title="Profile">- <ProfileSettingsPageClient />- </PageContent>- );+ return <ProfileSettingsPageClient />;}