apps/web: make Header server component (again)
This commit is contained in:
parent
1e29f598f8
commit
489db4ad28
@ -1,5 +1,5 @@
|
||||
import * as apiIUS from '@/api/ius/query';
|
||||
import { Form } from '@/components/Form';
|
||||
import { Form, Header } from '@/components/Form';
|
||||
import type { PageProps } from '@/types/page';
|
||||
import { withError } from '@/utils/error';
|
||||
import { getPageUrlParams, makeCreateUrl } from '@/utils/url';
|
||||
@ -28,17 +28,20 @@ export default async function Page(pageProps: PageProps) {
|
||||
const pageUrlParams = getPageUrlParams(pageProps);
|
||||
const createUrl = makeCreateUrl(pageUrlParams);
|
||||
|
||||
return Promise.all([apiIUS.getData({ createUrl }), apiIUS.getMetaData({ createUrl })]).then(
|
||||
([data, metaData]) => {
|
||||
const props = { data, metaData, pageUrlParams };
|
||||
return Promise.all([
|
||||
apiIUS.getData({ createUrl }),
|
||||
apiIUS.getMetaData({ createUrl }),
|
||||
apiIUS.getConfig({ createUrl }),
|
||||
]).then(([data, metaData, { title }]) => {
|
||||
const props = { data, metaData, pageUrlParams };
|
||||
|
||||
return (
|
||||
<Background>
|
||||
<Form {...props} />
|
||||
</Background>
|
||||
);
|
||||
}
|
||||
);
|
||||
return (
|
||||
<Background>
|
||||
<Header title={title} link={'/ius' + createUrl('/conditions')} />
|
||||
<Form {...props} />
|
||||
</Background>
|
||||
);
|
||||
});
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,23 +1,14 @@
|
||||
/* eslint-disable react/forbid-component-props */
|
||||
import { FormContext } from './context/form-context';
|
||||
import * as apiIUS from '@/api/ius/query';
|
||||
import Link from 'next/link';
|
||||
import { useContext } from 'react';
|
||||
import { Heading } from 'ui';
|
||||
|
||||
export function Header() {
|
||||
const { createUrl } = useContext(FormContext);
|
||||
|
||||
return apiIUS.getConfig({ createUrl }).then(({ title }) => (
|
||||
export function Header({ link, title }: { readonly link: string; readonly title: string }) {
|
||||
return (
|
||||
<div className="flex justify-between">
|
||||
<Heading size={2}>{title}</Heading>
|
||||
<Link
|
||||
href={'/ius' + createUrl('/conditions')}
|
||||
className="text-primary-600 text-sm font-medium hover:underline"
|
||||
prefetch
|
||||
>
|
||||
<Link href={link} className="text-primary-600 text-sm font-medium hover:underline" prefetch>
|
||||
Посмотреть условия
|
||||
</Link>
|
||||
</div>
|
||||
));
|
||||
);
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
import { Buttons } from './Buttons';
|
||||
import { FormContextProvider } from './context/form-context';
|
||||
import { Elements } from './Elements';
|
||||
import { Header } from './Header';
|
||||
import type { Props } from './types';
|
||||
import { makeCreateUrl } from '@/utils/url';
|
||||
import { Divider } from 'ui';
|
||||
@ -12,10 +11,11 @@ export function Form(props: Props) {
|
||||
|
||||
return (
|
||||
<FormContextProvider pageUrlParams={pageUrlParams} createUrl={makeCreateUrl(pageUrlParams)}>
|
||||
<Header />
|
||||
<Elements {...props} />
|
||||
<Divider />
|
||||
<Buttons />
|
||||
</FormContextProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export * from './Header';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user