Files
tm_panel/src/app/marketing/_components/useContactsStepPresenter.ts
T
AmirReza Jamali bd79b7ed14 refactor(marketing): Standardize marketing wizard steps with initial data support
- Add support for initial data in all marketing wizard step components
- Update step presenters to accept and handle initial data
- Modify forwardRef implementations to include initialData prop
- Add TypeScript interfaces for step component props
- Improve type safety and data handling across marketing wizard steps
- Prepare components for edit and create workflows with consistent data management
2025-11-11 10:43:32 +03:30

70 lines
1.3 KiB
TypeScript

"use client";
import { useFieldArray, useForm } from "react-hook-form";
export interface IContactsStepFields {
title: string;
description: string;
submitButtonText: string;
fields: {
name: string;
label: string;
placeholder: string;
required: boolean;
}[];
}
const useContactsStepPresenter = (initialData?: IContactsStepFields) => {
const {
register,
handleSubmit,
control,
getValues,
formState: { errors },
} = useForm<IContactsStepFields>({
defaultValues: initialData || {
fields: [
{
name: "first_name",
label: "",
placeholder: "",
required: false,
},
{
name: "last_name",
label: "",
placeholder: "",
required: false,
},
{ name: "email", label: "", placeholder: "", required: false },
{ name: "phone", label: "", placeholder: "", required: false },
],
},
});
const { fields } = useFieldArray({
control,
name: "fields",
});
const onSubmit = (data: IContactsStepFields) => {
console.log(data);
};
const collectData = async () => {
return getValues();
};
return {
register,
handleSubmit,
errors,
onSubmit,
fields,
control,
collectData,
getValues,
};
};
export default useContactsStepPresenter;