import { FormikForm } from "@shared/nej-react-utils/Form/FormikForm"; import { useApiClient } from "@utils/NejManager/NejProvider"; import useMethod from "../macros/useMethod.macro"; import useQuery from "../macros/useQuery.macro"; import { CancelablePromise, ApiClient, OwnerResponse, useOwner } from "@services/api"; type FormProps = { refresh: () => void; afterSubmit?: (values: T) => void; initialData?: T; }; export type WithFormProps = P & FormProps; type CleanedFormProps

= Omit; export function withForm>(WrappedForm: React.ComponentType>, method: (client: ApiClient, project: OwnerResponse, props: P) => (body: T) => CancelablePromise, submitText: string, trMethod?: (initialData: T, props: CleanedFormProps

) => T) { return function GameFormWrapper({ refresh, afterSubmit, initialData, ...props }: P) { const client = useApiClient(); const company = useOwner(); if (trMethod) initialData = trMethod(initialData, props); 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} > ); }; }