From 489db4ad28b394682b48850af1fbdf6659803964 Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Thu, 16 Nov 2023 20:12:25 +0300 Subject: [PATCH] apps/web: make Header server component (again) --- apps/web/app/ius/[slug]/page.tsx | 25 ++++++++++++++----------- apps/web/components/Form/Header.tsx | 17 ++++------------- apps/web/components/Form/index.tsx | 4 ++-- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/apps/web/app/ius/[slug]/page.tsx b/apps/web/app/ius/[slug]/page.tsx index 5584f2e..a1aa462 100644 --- a/apps/web/app/ius/[slug]/page.tsx +++ b/apps/web/app/ius/[slug]/page.tsx @@ -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 ( - -
- - ); - } - ); + return ( + +
+ + + ); + }); }, }); } diff --git a/apps/web/components/Form/Header.tsx b/apps/web/components/Form/Header.tsx index c377b51..0bdf7ea 100644 --- a/apps/web/components/Form/Header.tsx +++ b/apps/web/components/Form/Header.tsx @@ -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 (
{title} - + Посмотреть условия
- )); + ); } diff --git a/apps/web/components/Form/index.tsx b/apps/web/components/Form/index.tsx index 4bd4c4b..d730281 100644 --- a/apps/web/components/Form/index.tsx +++ b/apps/web/components/Form/index.tsx @@ -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 ( -
); } + +export * from './Header';