diff --git a/src/app/create-guild/components/CreateGuildForm.tsx b/src/app/create-guild/components/CreateGuildForm.tsx index fc7566c6f8..c3d1aeeb4b 100644 --- a/src/app/create-guild/components/CreateGuildForm.tsx +++ b/src/app/create-guild/components/CreateGuildForm.tsx @@ -2,7 +2,7 @@ import { useFormContext } from "react-hook-form"; -import { ControlledImageUploader } from "@/components/ImageUploader"; +import { ImageUploader } from "@/components/ImageUploader"; import { FormControl, FormErrorMessage, @@ -14,24 +14,20 @@ import { Input } from "@/components/ui/Input"; import type { CreateGuildForm as CreateGuildFormType } from "@/lib/schemas/guild"; export const CreateGuildForm = () => { - const { control } = useFormContext(); + const { control, setValue } = useFormContext(); return ( <> - ( - -
- -
- -
- )} - /> +
+ + setValue("imageUrl", imageUrl, { + shouldDirty: true, + }) + } + className="size-32" + /> +
& { @@ -49,6 +48,11 @@ export const ImageUploader = ({ } }, onError: (error) => { + toast("Upload error", { + description: error.message, + icon: , + }); + if (typeof onError === "function") { onError(error.message); } @@ -111,41 +115,3 @@ export const ImageUploader = ({ ); }; - -type ControlledProps = Omit< - Props, - "onSuccess" | "onError" | "onFileInputChange" -> & { - fieldName: Path; -}; - -export const ControlledImageUploader = < - TFieldValues extends FieldValues, - TContext, ->({ - fieldName, - ...imageUploaderProps -}: ControlledProps) => { - const { control, setError, clearErrors } = useFormContext(); - - const { - field: { onChange }, - } = useController({ - control, - name: fieldName, - }); - - return ( - onChange(imageUrl)} - onError={(errorMessage) => - setError(fieldName, { - type: "custom", - message: errorMessage, - }) - } - onFileInputChange={() => clearErrors(fieldName)} - /> - ); -}; diff --git a/src/components/ui/Form.tsx b/src/components/ui/Form.tsx index 2d25d97a5e..0168c3c754 100644 --- a/src/components/ui/Form.tsx +++ b/src/components/ui/Form.tsx @@ -1,4 +1,3 @@ -import { XCircle } from "@phosphor-icons/react/dist/ssr"; import type * as LabelPrimitive from "@radix-ui/react-label"; import { Slot } from "@radix-ui/react-slot"; import { useDebouncedState } from "foxact/use-debounced-state"; @@ -19,7 +18,6 @@ import { type FieldValues, useFormContext, } from "react-hook-form"; -import { toast } from "sonner"; import { Collapsible, CollapsibleContent } from "./Collapsible"; import { Label } from "./Label"; @@ -156,20 +154,12 @@ FormDescription.displayName = "FormDescription"; const FormErrorMessage = forwardRef< HTMLParagraphElement, - HTMLAttributes & { useToast?: boolean } ->(({ useToast, className, children, ...props }, ref) => { + HTMLAttributes +>(({ className, children, ...props }, ref) => { const { error, formMessageId } = useFormField(); const body = error ? String(error?.message) : children; const [debouncedBody] = useDebouncedState(body, 200); - if (useToast && body) { - toast("An error occurred", { - icon: , - description: body ?? debouncedBody, - }); - return null; - } - return (