import { useTranslation } from "react-i18next"; import { Form, Formik, FormikConfig, FormikErrors, FormikProps } from "formik"; import { Button, Divider } from "@mantine/core"; import { cleanEmptyStrings } from "./cleanEmptyStrings"; //formik is defined as //export declare function Formik(props: FormikConfig & ExtraProps): React.JSX.Element; //we just want to proxy it basically export function FormikForm({ data = {} as Values, onSubmit, submitText = "Submit", schema, onDelete = null, closeModal = null, createForm = null, sendEmptyKeys = null, children, ...props }: Omit, "initialValues"> & { data?: Values; submitText?: string; schema?: any; onDelete?: () => void; closeModal?: () => void; createForm?: (values, handleChange, errors, touched) => React.ReactNode; sendEmptyKeys?: Set | string[]; children?: React.ReactNode; }): JSX.Element { const { t } = useTranslation(); const handleCleanSubmit = (values: Values, formikHelpers: any) => { const cleaned = cleanEmptyStrings(values, sendEmptyKeys); return onSubmit(cleaned, formikHelpers); }; return initialValues={data} onSubmit={handleCleanSubmit} validationSchema={schema} {...props} > {({ values, handleChange, errors, touched, ...other }) => (
{createForm && createForm(values, handleChange, errors, touched)} {children}
{onDelete && } {closeModal && }
)} ; }