fix(14-03): type LeadForm useForm with CreateLeadInput (CRM-11)
- CreateLeadModal and EditLeadModal use useForm<CreateLeadInput>() instead of useForm<any>() - Import CreateLeadInput from lead-validators, remove local z.infer redeclaration - Narrow EditLeadModal status default value to CreateLeadInput["status"], remove 'as any' - Fix FormField generic signature in shared ui/form.tsx (was ControllerProps<any, any>, broke Control<T> assignability once useForm<T> became concrete) - Rule 3 blocking issue
This commit is contained in:
@@ -3,8 +3,7 @@
|
||||
import { useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
import { createLeadSchema, LEAD_STAGES } from "@/lib/lead-validators";
|
||||
import { createLeadSchema, LEAD_STAGES, type CreateLeadInput } from "@/lib/lead-validators";
|
||||
import { Lead } from "@/db/schema";
|
||||
import { createLead, updateLead } from "@/app/admin/leads/actions";
|
||||
import {
|
||||
@@ -33,12 +32,10 @@ import { Input } from "@/components/ui/input";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { Button } from "@/components/ui/button";
|
||||
|
||||
type CreateLeadInput = z.infer<typeof createLeadSchema>;
|
||||
|
||||
export function CreateLeadModal() {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const form = useForm<any>({
|
||||
const form = useForm<CreateLeadInput>({
|
||||
resolver: zodResolver(createLeadSchema),
|
||||
defaultValues: {
|
||||
name: "",
|
||||
@@ -202,14 +199,14 @@ export function CreateLeadModal() {
|
||||
export function EditLeadModal({ lead }: { lead: Lead }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const form = useForm<any>({
|
||||
const form = useForm<CreateLeadInput>({
|
||||
resolver: zodResolver(createLeadSchema),
|
||||
defaultValues: {
|
||||
name: lead.name,
|
||||
email: lead.email || "",
|
||||
phone: lead.phone || "",
|
||||
company: lead.company || "",
|
||||
status: lead.status as any,
|
||||
status: lead.status as CreateLeadInput["status"],
|
||||
notes: lead.notes || "",
|
||||
},
|
||||
});
|
||||
|
||||
@@ -27,15 +27,16 @@ const FormFieldContext = React.createContext<FormFieldContextValue>(
|
||||
{} as FormFieldContextValue
|
||||
)
|
||||
|
||||
const FormField = React.forwardRef<
|
||||
any,
|
||||
ControllerProps<any, any>
|
||||
>(({ ...props }, ref) => (
|
||||
const FormField = <
|
||||
TFieldValues extends FieldValues = FieldValues,
|
||||
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||
>({
|
||||
...props
|
||||
}: ControllerProps<TFieldValues, TName>) => (
|
||||
<FormFieldContext.Provider value={{ name: props.name }}>
|
||||
<Controller {...props} />
|
||||
</FormFieldContext.Provider>
|
||||
))
|
||||
FormField.displayName = "FormField"
|
||||
)
|
||||
|
||||
const useFormField = () => {
|
||||
const fieldContext = React.useContext(FormFieldContext)
|
||||
|
||||
Reference in New Issue
Block a user