The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Adds form validation
Ian MacCallum8f6356abeb43
diff --git a/apps/web/ui/partners/groups/design/fields/multiple-choice-field.tsx b/apps/web/ui/partners/groups/design/fields/multiple-choice-field.tsxindex 67d719ff5b..e5ff098a93 100644--- a/apps/web/ui/partners/groups/design/fields/multiple-choice-field.tsx+++ b/apps/web/ui/partners/groups/design/fields/multiple-choice-field.tsx@@ -59,6 +59,7 @@ export function MultipleChoiceField({ field, keyPath: keyPathProp, preview }: Mureturn (<label+ key={option.id}className="w-full flex items-center gap-2.5 text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"><Checkbox@@ -97,7 +98,7 @@ export function MultipleChoiceField({ field, keyPath: keyPathProp, preview }: MuclassName="space-y-2">{field.data.options.map((option) => (- <label className="flex items-center gap-2.5 leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70">+ <label key={option.id} className="flex items-center gap-2.5 leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"><RadioGroupItem value={option.value} id={option.id} className="focus:border-[var(--brand)] focus:ring-[var(--brand)]" /><span className="text-sm text-content-emphasis">diff --git a/apps/web/ui/partners/groups/design/modals/long-text-field-modal.tsx b/apps/web/ui/partners/groups/design/modals/long-text-field-modal.tsxindex 928e4e3772..f005dcadf0 100644--- a/apps/web/ui/partners/groups/design/modals/long-text-field-modal.tsx+++ b/apps/web/ui/partners/groups/design/modals/long-text-field-modal.tsx@@ -5,7 +5,6 @@ import {Button,Modal,Switch,- useEnterSubmit,useMediaQuery,} from "@dub/ui";import { Dispatch, SetStateAction, useId } from "react";@@ -13,6 +12,7 @@ import { Controller, useForm } from "react-hook-form";import { z } from "zod";import { v4 as uuid } from "uuid";import { motion } from "motion/react";+import { cn } from "@dub/utils";type LongTextFieldData = z.infer<typeof programApplicationFormLongTextFieldSchema>@@ -56,8 +56,6 @@ function LongTextFieldModalInner({},});- const { handleKeyDown } = useEnterSubmit();-return (<><div className="p-4 pt-3">@@ -89,7 +87,10 @@ function LongTextFieldModalInner({type="text"placeholder=""autoFocus={!isMobile}- className="block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 text-sm"+ className={cn(+ "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",+ !!errors.label && "border-red-600 focus:border-red-500 focus:ring-red-600",+ )}{...register("label", { required: true })}/></div>@@ -109,7 +110,10 @@ function LongTextFieldModalInner({type="text"placeholder=""autoFocus={!isMobile}- className="block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 text-sm"+ className={cn(+ "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",+ !!errors.data?.placeholder && "border-red-600 focus:border-red-500 focus:ring-red-600",+ )}{...register("data.placeholder")}/></div>diff --git a/apps/web/ui/partners/groups/design/modals/multiple-choice-field-modal.tsx b/apps/web/ui/partners/groups/design/modals/multiple-choice-field-modal.tsxindex f3811911ec..d83df39c8d 100644--- a/apps/web/ui/partners/groups/design/modals/multiple-choice-field-modal.tsx+++ b/apps/web/ui/partners/groups/design/modals/multiple-choice-field-modal.tsx@@ -64,6 +64,8 @@ function MultipleChoiceFieldModalInner({register,watch,setValue,+ setError,+ clearErrors,formState: { errors },control,} = form;@@ -84,6 +86,14 @@ function MultipleChoiceFieldModalInner({onSubmit={(e) => {e.stopPropagation();handleSubmit(async (data) => {+ if (data.data.options.length < 2) {+ setError("data.options", {+ type: "manual",+ message: "Requires minimum of 2 options"+ })+ return+ }+setShowModal(false);onSubmit(data);})(e);@@ -103,7 +113,10 @@ function MultipleChoiceFieldModalInner({type="text"placeholder=""autoFocus={!isMobile}- className="block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"+ className={cn(+ "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",+ !!errors.label && "border-red-600 focus:border-red-500 focus:ring-red-600",+ )}{...register("label", { required: true })}/></div>@@ -175,18 +188,24 @@ function MultipleChoiceFieldModalInner({onAdd={() => {const id = uuid();+ const newOptions = [+ ...fields,+ {+ id,+ value: "",+ },+ ]+setValue("data.options",- [- ...fields,- {- id,- value: "",- },- ],+ newOptions,{ shouldDirty: true },);+ if (newOptions.length >= 2) {+ clearErrors("data.options")+ }+return id;}}onReorder={(updated) =>@@ -244,19 +263,28 @@ function MultipleChoiceFieldModalInner({</div>- <div className="flex items-center justify-end gap-2">- <Button- onClick={() => setShowModal(false)}- variant="secondary"- text="Cancel"- className="h-8 w-fit px-3"- />- <Button- type="submit"- variant="primary"- text={defaultValues ? "Update" : "Add"}- className="h-8 w-fit px-3"- />+ <div className="flex items-center justify-between gap-2">+ <div>+ {errors.data?.options?.message && (+ <span className="text-xs text-red-600 dark:text-red-400">+ {errors.data?.options?.message}+ </span>+ )}+ </div>+ <div className="flex items-center gap-2">+ <Button+ onClick={() => setShowModal(false)}+ variant="secondary"+ text="Cancel"+ className="h-8 w-fit px-3"+ />+ <Button+ type="submit"+ variant="primary"+ text={defaultValues ? "Update" : "Add"}+ className="h-8 w-fit px-3"+ />+ </div></div></form></div>diff --git a/apps/web/ui/partners/groups/design/modals/select-field-modal.tsx b/apps/web/ui/partners/groups/design/modals/select-field-modal.tsxindex c51cba952c..e920c90853 100644--- a/apps/web/ui/partners/groups/design/modals/select-field-modal.tsx+++ b/apps/web/ui/partners/groups/design/modals/select-field-modal.tsx@@ -64,6 +64,9 @@ function SelectFieldModalInner({register,watch,setValue,+ setError,+ clearErrors,+ getValues,formState: { errors },control,} = form;@@ -84,6 +87,14 @@ function SelectFieldModalInner({onSubmit={(e) => {e.stopPropagation();handleSubmit(async (data) => {+ if (data.data.options.length < 2) {+ setError("data.options", {+ type: "manual",+ message: "Requires minimum of 2 options"+ })+ return+ }+setShowModal(false);onSubmit(data);})(e);@@ -103,7 +114,10 @@ function SelectFieldModalInner({type="text"placeholder=""autoFocus={!isMobile}- className="block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"+ className={cn(+ "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",+ !!errors.label && "border-red-600 focus:border-red-500 focus:ring-red-600",+ )}{...register("label", { required: true })}/></div>@@ -152,18 +166,24 @@ function SelectFieldModalInner({onAdd={() => {const id = uuid();+ const newOptions = [+ ...fields,+ {+ id,+ value: "",+ },+ ]+setValue("data.options",- [- ...fields,- {- id,- value: "",- },- ],+ newOptions,{ shouldDirty: true },);+ if (newOptions.length >= 2) {+ clearErrors("data.options")+ }+return id;}}onReorder={(updated) =>@@ -177,7 +197,6 @@ function SelectFieldModalInner({{fields.map((field, index) => {const fieldErrors = errors.data?.options?.[index];-return (<EditListItemkey={field.id}@@ -220,20 +239,28 @@ function SelectFieldModalInner({</div></div>-- <div className="flex items-center justify-end gap-2">- <Button- onClick={() => setShowModal(false)}- variant="secondary"- text="Cancel"- className="h-8 w-fit px-3"- />- <Button- type="submit"- variant="primary"- text={defaultValues ? "Update" : "Add"}- className="h-8 w-fit px-3"- />+ <div className="flex items-center justify-between gap-2">+ <div>+ {errors.data?.options?.message && (+ <span className="text-xs text-red-600 dark:text-red-400">+ {errors.data?.options?.message}+ </span>+ )}+ </div>+ <div className="flex items-center gap-2">+ <Button+ onClick={() => setShowModal(false)}+ variant="secondary"+ text="Cancel"+ className="h-8 w-fit px-3"+ />+ <Button+ type="submit"+ variant="primary"+ text={defaultValues ? "Update" : "Add"}+ className="h-8 w-fit px-3"+ />+ </div></div></form></div>diff --git a/apps/web/ui/partners/groups/design/modals/short-text-field-modal.tsx b/apps/web/ui/partners/groups/design/modals/short-text-field-modal.tsxindex 0b961159a9..f57e9d09ed 100644--- a/apps/web/ui/partners/groups/design/modals/short-text-field-modal.tsx+++ b/apps/web/ui/partners/groups/design/modals/short-text-field-modal.tsx@@ -12,6 +12,7 @@ import { Controller, useForm } from "react-hook-form";import { z } from "zod";import { v4 as uuid } from "uuid";import { motion } from "motion/react";+import { cn } from "@dub/utils";type ShortTextFieldData = z.infer<typeof programApplicationFormShortTextFieldSchema>@@ -41,6 +42,7 @@ function ShortTextFieldModalInner({control,handleSubmit,register,+ formState: { errors }} = useForm<ShortTextFieldData>({defaultValues: defaultValues ?? {id: uuid(),@@ -85,7 +87,10 @@ function ShortTextFieldModalInner({type="text"placeholder=""autoFocus={!isMobile}- className="block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"+ className={cn(+ "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",+ !!errors.label && "border-red-600 focus:border-red-500 focus:ring-red-600",+ )}{...register("label", { required: true })}/></div>@@ -105,7 +110,10 @@ function ShortTextFieldModalInner({type="text"placeholder=""autoFocus={!isMobile}- className="block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm"+ className={cn(+ "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",+ !!errors.data?.placeholder && "border-red-600 focus:border-red-500 focus:ring-red-600",+ )}{...register("data.placeholder")}/></div>