40 lines
1.1 KiB
TypeScript

'use client';
import { Buttons } from './Buttons';
import { FormContext, FormContextProvider } from './context/form-context';
import { Elements } from './Elements';
import { Header } from './Header';
import type { Props } from './types';
import { makeCreateUrl } from '@/utils/url';
import type { FC } from 'react';
import { useContext } from 'react';
import { Background, Divider } from 'ui';
function Content(props: Props) {
const { title } = props;
const { createUrl } = useContext(FormContext);
return (
<Background className="lg:w-standard grid w-full gap-2 p-5">
<Header title={title} link={'/ius' + createUrl('/conditions')} />
<Elements {...props} />
<Divider />
<Buttons />
</Background>
);
}
function withContext<T extends Props>(Component: FC<T>) {
return (props: T) => {
const { pageUrlParams } = props;
const createUrl = makeCreateUrl(pageUrlParams);
return (
<FormContextProvider pageUrlParams={pageUrlParams} createUrl={createUrl}>
<Component {...props} />
</FormContextProvider>
);
};
}
export const Form = withContext(Content);