55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import * as apiIUS from '@/api/ius/query';
|
|
import { combineDocuments } from '@/api/ius/tools';
|
|
import { Form } from '@/components/Form';
|
|
import type { FormComponentProps } from '@/components/Form/types';
|
|
import type { PageProps } from '@/types/page';
|
|
import { withError } from '@/utils/error';
|
|
import { getPageUrlParams } from '@/utils/url';
|
|
import type { Metadata } from 'next';
|
|
import { headers } from 'next/headers';
|
|
|
|
export async function generateMetadata(pageProps: PageProps): Promise<Metadata> {
|
|
const pageUrlParams = getPageUrlParams(pageProps);
|
|
const { title } = await apiIUS.getConfig({ pageUrlParams });
|
|
const text = `${title} | Эволюция`;
|
|
|
|
return {
|
|
description: text,
|
|
openGraph: {
|
|
description: text,
|
|
title: text,
|
|
},
|
|
title: text,
|
|
};
|
|
}
|
|
|
|
export default async function Page(pageProps: PageProps) {
|
|
return withError({
|
|
render: async () => {
|
|
const pageUrlParams = getPageUrlParams(pageProps);
|
|
|
|
const headersList = headers();
|
|
const cookie = headersList.get('cookie') ?? '';
|
|
|
|
return Promise.all([
|
|
apiIUS.getData({ cookie, pageUrlParams }),
|
|
apiIUS.getMetaData({ cookie, pageUrlParams }),
|
|
apiIUS.getConfig({ cookie, pageUrlParams }),
|
|
apiIUS.getDocumentTypes({ cookie, pageUrlParams }),
|
|
apiIUS.getDocuments({ cookie, pageUrlParams }),
|
|
]).then(([data, metaData, { title }, documentTypes, documents]) => {
|
|
const combinedDocuments = combineDocuments({ documentTypes, documents });
|
|
const props: FormComponentProps = {
|
|
combinedDocuments,
|
|
data,
|
|
metaData,
|
|
pageUrlParams,
|
|
title,
|
|
};
|
|
|
|
return <Form {...props} />;
|
|
});
|
|
},
|
|
});
|
|
}
|