import { FormikForm } from "@shared/nej-react-utils/Form/FormikForm"; import { useApiClient, useProject } from "@utils/NejManager/NejProvider"; import useMethod from "../macros/useMethod.macro"; import useQuery from "../macros/useQuery.macro"; import { CancelablePromise, PortalApiClient, ProjectResponse } from "@services/portal-api"; type FormProps = { refresh: () => void; afterSubmit?: (values: T) => void; initialData?: T; }; export type WithFormProps = P & FormProps; export function withForm>(WrappedForm: React.ComponentType, method: (client: PortalApiClient, project: ProjectResponse, props: P) => (body: T) => CancelablePromise, submitText: string) { return function GameFormWrapper({ refresh, afterSubmit, initialData, ...props }: P) { const client = useApiClient(); const company = useProject(); const fnc = method(client, company, { ...props, initialData } as P); console.log(fnc); const [submit, { }] = useMethod( fnc, () => refresh() ); return ( {submit(values); afterSubmit && afterSubmit(values)}} submitText={submitText} > ); }; }