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 { useState } from "react";
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { z } from "zod";
|
import { createLeadSchema, LEAD_STAGES, type CreateLeadInput } from "@/lib/lead-validators";
|
||||||
import { createLeadSchema, LEAD_STAGES } from "@/lib/lead-validators";
|
|
||||||
import { Lead } from "@/db/schema";
|
import { Lead } from "@/db/schema";
|
||||||
import { createLead, updateLead } from "@/app/admin/leads/actions";
|
import { createLead, updateLead } from "@/app/admin/leads/actions";
|
||||||
import {
|
import {
|
||||||
@@ -33,12 +32,10 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { Textarea } from "@/components/ui/textarea";
|
import { Textarea } from "@/components/ui/textarea";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
|
|
||||||
type CreateLeadInput = z.infer<typeof createLeadSchema>;
|
|
||||||
|
|
||||||
export function CreateLeadModal() {
|
export function CreateLeadModal() {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const form = useForm<any>({
|
const form = useForm<CreateLeadInput>({
|
||||||
resolver: zodResolver(createLeadSchema),
|
resolver: zodResolver(createLeadSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
name: "",
|
name: "",
|
||||||
@@ -202,14 +199,14 @@ export function CreateLeadModal() {
|
|||||||
export function EditLeadModal({ lead }: { lead: Lead }) {
|
export function EditLeadModal({ lead }: { lead: Lead }) {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const form = useForm<any>({
|
const form = useForm<CreateLeadInput>({
|
||||||
resolver: zodResolver(createLeadSchema),
|
resolver: zodResolver(createLeadSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
name: lead.name,
|
name: lead.name,
|
||||||
email: lead.email || "",
|
email: lead.email || "",
|
||||||
phone: lead.phone || "",
|
phone: lead.phone || "",
|
||||||
company: lead.company || "",
|
company: lead.company || "",
|
||||||
status: lead.status as any,
|
status: lead.status as CreateLeadInput["status"],
|
||||||
notes: lead.notes || "",
|
notes: lead.notes || "",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -27,15 +27,16 @@ const FormFieldContext = React.createContext<FormFieldContextValue>(
|
|||||||
{} as FormFieldContextValue
|
{} as FormFieldContextValue
|
||||||
)
|
)
|
||||||
|
|
||||||
const FormField = React.forwardRef<
|
const FormField = <
|
||||||
any,
|
TFieldValues extends FieldValues = FieldValues,
|
||||||
ControllerProps<any, any>
|
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
|
||||||
>(({ ...props }, ref) => (
|
>({
|
||||||
|
...props
|
||||||
|
}: ControllerProps<TFieldValues, TName>) => (
|
||||||
<FormFieldContext.Provider value={{ name: props.name }}>
|
<FormFieldContext.Provider value={{ name: props.name }}>
|
||||||
<Controller {...props} />
|
<Controller {...props} />
|
||||||
</FormFieldContext.Provider>
|
</FormFieldContext.Provider>
|
||||||
))
|
)
|
||||||
FormField.displayName = "FormField"
|
|
||||||
|
|
||||||
const useFormField = () => {
|
const useFormField = () => {
|
||||||
const fieldContext = React.useContext(FormFieldContext)
|
const fieldContext = React.useContext(FormFieldContext)
|
||||||
|
|||||||
Reference in New Issue
Block a user