apps/web: add withContext in Form component
This commit is contained in:
parent
23017b6205
commit
43b505c16d
@ -1,27 +1,40 @@
|
||||
/* eslint-disable react/forbid-component-props */
|
||||
'use client';
|
||||
import { Buttons } from './Buttons';
|
||||
import { FormContextProvider } from './context/form-context';
|
||||
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';
|
||||
|
||||
export function Form(props: Props) {
|
||||
const { pageUrlParams, title } = props;
|
||||
const createUrl = makeCreateUrl(pageUrlParams);
|
||||
function Content(props: Props) {
|
||||
const { title } = props;
|
||||
const { createUrl } = useContext(FormContext);
|
||||
|
||||
return (
|
||||
<Background className="lg:w-standard grid w-full gap-2 p-5">
|
||||
<FormContextProvider pageUrlParams={pageUrlParams} createUrl={createUrl}>
|
||||
<Header title={title} link={'/ius' + createUrl('/conditions')} />
|
||||
<Elements {...props} />
|
||||
<Divider />
|
||||
<Buttons />
|
||||
</FormContextProvider>
|
||||
<Header title={title} link={'/ius' + createUrl('/conditions')} />
|
||||
<Elements {...props} />
|
||||
<Divider />
|
||||
<Buttons />
|
||||
</Background>
|
||||
);
|
||||
}
|
||||
|
||||
export * from './Header';
|
||||
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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user