The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
WIP about you section
Tim Wilson512b332c929e
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/about-you-form.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/about-you-form.tsxnew file mode 100644index 0000000000..bb78e9701b--- /dev/null+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/profile/about-you-form.tsx@@ -0,0 +1,108 @@+import { updatePartnerProfileAction } from "@/lib/actions/partners/update-partner-profile";+import { PartnerProps } from "@/lib/types";+import { MAX_PARTNER_DESCRIPTION_LENGTH } from "@/lib/zod/schemas/partners";+import { MaxCharactersCounter } from "@/ui/shared/max-characters-counter";+import { Button, useEnterSubmit } from "@dub/ui";+import { cn } from "@dub/utils";+import { useAction } from "next-safe-action/hooks";+import { useEffect } from "react";+import { useForm } from "react-hook-form";+import ReactTextareaAutosize from "react-textarea-autosize";+import { toast } from "sonner";+import { SettingsRow } from "./settings-row";++type AboutYouFormData = {+ description: string;+};++export function AboutYouForm({ partner }: { partner?: PartnerProps }) {+ const {+ register,+ control,+ handleSubmit,+ setError,+ getValues,+ reset,+ formState: { errors, isSubmitting, isSubmitSuccessful },+ } = useForm<AboutYouFormData>({+ defaultValues: {+ description: partner?.description ?? undefined,+ },+ });++ // Reset form dirty state after submit+ useEffect(() => {+ if (isSubmitSuccessful)+ reset(getValues(), { keepValues: true, keepDirty: false });+ }, [isSubmitSuccessful, reset, getValues]);++ const { handleKeyDown } = useEnterSubmit();++ const { executeAsync } = useAction(updatePartnerProfileAction, {+ onSuccess: () => {+ toast.success("Your profile has been updated.");+ },+ onError({ error }) {+ setError("root.serverError", {+ message: error.serverError,+ });++ toast.error(error.serverError);+ },+ });++ return (+ <div className="border-border-subtle divide-border-subtle flex flex-col divide-y rounded-lg border">+ <div className="px-6 py-8">+ <h3 className="text-content-emphasis text-lg font-semibold leading-7">+ About you and your expertise+ </h3>+ <p className="text-content-subtle text-sm font-normal leading-5">+ Help programs get to know you, your background, interests, and what+ makes you a great partner.+ </p>+ </div>++ <form+ onSubmit={handleSubmit(async (data) => {+ await executeAsync(data);+ })}+ >+ <SettingsRow+ heading="About you"+ description="Share who you are, what you do, and who your audience is. A strong bio helps you stand out and get accepted into more programs."+ >+ <div>+ <ReactTextareaAutosize+ className={cn(+ "block w-full rounded-md focus:outline-none sm:text-sm",+ errors.description+ ? "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}+ maxLength={MAX_PARTNER_DESCRIPTION_LENGTH}+ onKeyDown={handleKeyDown}+ {...register("description")}+ />+ <MaxCharactersCounter+ name="description"+ maxLength={MAX_PARTNER_DESCRIPTION_LENGTH}+ control={control}+ />+ </div>+ </SettingsRow>++ <div className="flex items-center justify-end rounded-b-lg border-t border-neutral-200 bg-neutral-50 px-6 py-4">+ <Button+ text="Save changes"+ className="h-8 w-fit px-2.5"+ loading={isSubmitting}+ />+ </div>+ </form>+ </div>+ );+}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 516add1a95..0614f546d4 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@@ -5,6 +5,7 @@ import { PageContent } from "@/ui/layout/page-content";import { PageWidthWrapper } from "@/ui/layout/page-width-wrapper";import { useMergePartnerAccountsModal } from "@/ui/partners/merge-accounts/merge-partner-accounts-modal";import { Button } from "@dub/ui";+import { AboutYouForm } from "./about-you-form";import { ProfileDetailsForm } from "./profile-details-form";export function ProfileSettingsPageClient() {@@ -22,6 +23,7 @@ export function ProfileSettingsPageClient() {><PageWidthWrapper className="mb-20 flex flex-col gap-6"><ProfileDetailsForm partner={partner} />+ <AboutYouForm partner={partner} /></PageWidthWrapper></PageContent>);diff --git a/apps/web/lib/actions/partners/update-partner-profile.ts b/apps/web/lib/actions/partners/update-partner-profile.tsindex d10a50d0bb..501aeeb9bf 100644--- a/apps/web/lib/actions/partners/update-partner-profile.ts+++ b/apps/web/lib/actions/partners/update-partner-profile.ts@@ -3,7 +3,10 @@import { confirmEmailChange } from "@/lib/auth/confirm-email-change";import { qstash } from "@/lib/cron";import { storage } from "@/lib/storage";-import { PartnerProfileSchema } from "@/lib/zod/schemas/partners";+import {+ MAX_PARTNER_DESCRIPTION_LENGTH,+ PartnerProfileSchema,+} from "@/lib/zod/schemas/partners";import { prisma } from "@dub/prisma";import {APP_DOMAIN_WITH_NGROK,@@ -21,28 +24,15 @@ import { authPartnerActionClient } from "../safe-action";const updatePartnerProfileSchema = z.object({- name: z.string(),- email: z.string().email(),+ name: z.string().optional(),+ email: z.string().email().optional(),image: uploadedImageSchema.nullish(),- description: z.string().nullish(),- country: z.enum(Object.keys(COUNTRIES) as [string, ...string[]]).nullable(),- profileType: z.nativeEnum(PartnerProfileType),- companyName: z.string().nullable(),+ description: z.string().max(MAX_PARTNER_DESCRIPTION_LENGTH).nullish(),+ country: z.enum(Object.keys(COUNTRIES) as [string, ...string[]]).nullish(),+ profileType: z.nativeEnum(PartnerProfileType).optional(),+ companyName: z.string().nullish(),}).merge(PartnerProfileSchema.partial())- .refine(- (data) => {- if (data.profileType === "company") {- return !!data.companyName;- }-- return true;- },- {- message: "Legal company name is required.",- path: ["companyName"],- },- ).transform((data) => ({...data,companyName: data.profileType === "individual" ? null : data.companyName,@@ -63,6 +53,9 @@ export const updatePartnerProfileAction = authPartnerActionClientcompanyName,} = parsedInput;+ if (profileType === "company" && !companyName)+ throw new Error("Legal company name is required.");+// Delete the Stripe Express account if neededawait deleteStripeAccountIfRequired({partner,@@ -71,7 +64,7 @@ export const updatePartnerProfileAction = authPartnerActionClientlet imageUrl: string | null = null;let needsEmailVerification = false;- const emailChanged = partner.email !== newEmail;+ const emailChanged = newEmail !== undefined && partner.email !== newEmail;// Upload the new imageif (image) {@@ -164,9 +157,11 @@ const deleteStripeAccountIfRequired = async ({input: z.infer<typeof updatePartnerProfileSchema>;}) => {const countryChanged =+ input.country !== undefined &&partner.country?.toLowerCase() !== input.country?.toLowerCase();const profileTypeChanged =+ input.profileType !== undefined &&partner.profileType.toLowerCase() !== input.profileType.toLowerCase();const companyNameChanged =diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.tsindex 78f1a3dbcc..5d749dfcab 100644--- a/apps/web/lib/zod/schemas/partners.ts+++ b/apps/web/lib/zod/schemas/partners.ts@@ -255,6 +255,8 @@ export const PartnerProfileSchema = z.object({.describe("The partner's sales channels."),});+export const MAX_PARTNER_DESCRIPTION_LENGTH = 500;+export const PartnerSchema = z.object({id: z.string().describe("The partner's unique ID on Dub."),@@ -279,7 +281,7 @@ export const PartnerSchema = zimage: z.string().nullable().describe("The partner's avatar image."),description: z.string()- .max(5000)+ .max(5000) // Left at 5000 instead of MAX_PARTNER_DESCRIPTION_LENGTH to avoid breaking changes.nullish().describe("A brief description of the partner and their background."),country: zdiff --git a/apps/web/ui/shared/max-characters-counter.tsx b/apps/web/ui/shared/max-characters-counter.tsxnew file mode 100644index 0000000000..6999717c9f--- /dev/null+++ b/apps/web/ui/shared/max-characters-counter.tsx@@ -0,0 +1,22 @@+import { cn } from "@dub/utils";+import { Control, useWatch } from "react-hook-form";++export function MaxCharactersCounter({+ name,+ maxLength,+ control,+ className,+}: {+ name: string;+ maxLength: number;+ control?: Control<any, any>;+ className?: string;+}) {+ const value = useWatch({ control, name });++ return (+ <span className={cn("text-content-subtle text-xs", className)}>+ {value?.toString().length || 0}/{maxLength}+ </span>+ );+}