90a42b9fc5
continuous-integration/drone/push Build is passing
- Introduced DynamicFormBuilder component to streamline form creation for admin and company categories. - Refactored CreateAdmin and CreateCompany components to utilize the new dynamic form structure. - Added createAdminFormSections and createCompanyFormSections functions to define form fields and validation rules. - Enhanced form handling with improved error management and dynamic field rendering. This update enhances maintainability and scalability of forms across the application.
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
"use client";
|
|
|
|
import DynamicFormBuilder from "@/components/forms/DynamicFormBuilder";
|
|
import FormFooter from "@/components/ui/FormFooter";
|
|
import type { CreateCustomerCredentials } from "@/lib/api";
|
|
import { createCustomerFormSections } from "./customerFormSections";
|
|
import useCreateCustomerPresenter from "./useCreateCustomerPresenter";
|
|
|
|
interface IProps {
|
|
editMode?: boolean;
|
|
defaultValues?: CreateCustomerCredentials;
|
|
id?: string;
|
|
}
|
|
|
|
const CreateCustomer = ({ defaultValues, editMode, id }: IProps) => {
|
|
const {
|
|
errors,
|
|
handleSubmit,
|
|
register,
|
|
watch,
|
|
control,
|
|
onSubmit,
|
|
companies,
|
|
showPassword,
|
|
setShowPassword,
|
|
} = useCreateCustomerPresenter({ defaultValues, editMode, id });
|
|
|
|
const companyItems =
|
|
companies?.map((company) => ({
|
|
value: company.id,
|
|
label: company.name,
|
|
})) ?? [];
|
|
|
|
return (
|
|
<DynamicFormBuilder<CreateCustomerCredentials>
|
|
sections={createCustomerFormSections({
|
|
editMode,
|
|
companyItems,
|
|
watch,
|
|
showPassword,
|
|
setShowPassword,
|
|
})}
|
|
register={register}
|
|
control={control}
|
|
errors={errors}
|
|
handleSubmit={handleSubmit}
|
|
onSubmit={onSubmit}
|
|
footer={<FormFooter />}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default CreateCustomer;
|