apps/web: add /conditions route

This commit is contained in:
vchikalkin 2023-11-13 23:28:20 +03:00
parent 980a4009a8
commit 1c16fc2ec0
5 changed files with 81 additions and 12 deletions

View File

@ -2,24 +2,40 @@ import type * as t from './types';
import { urls } from '@/config/urls';
import wretch from 'wretch';
const api = wretch(urls.URL_UIS)
.errorType('json')
.resolve(({ json }) => json());
const api = wretch(urls.URL_UIS).errorType('json');
export async function getData(params: t.Request) {
const url = `/${params.slug}?${new URLSearchParams(params.searchParams)}`;
return api.get(url).then((res) => res as t.ResponseGetData);
return api
.get(url)
.res<t.ResponseGetData>((cb) => cb.json())
.then((res) => res);
}
export async function getMetaData(params: t.Request) {
const url = `/${params.slug}/meta?${new URLSearchParams(params.searchParams)}`;
return api.get(url).then((res) => res as t.ResponseMetaData);
return api
.get(url)
.res<t.ResponseMetaData>((res) => res.json())
.then((res) => res);
}
export async function getConfig(params: t.Request) {
const url = `/${params.slug}/config`;
return api.get(url).then((res) => res as t.ResponseConfig);
return api
.get(url)
.res<t.ResponseConfig>((res) => res.json())
.then((res) => res);
}
export async function getConditions(params: t.Request) {
const url = `/${params.slug}/conditions?${new URLSearchParams(params.searchParams)}`;
return api
.get(url)
.res<t.ResponseConditions>((res) => res.text())
.then((res) => res);
}

View File

@ -13,3 +13,4 @@ export type Request = { searchParams: any; slug: string };
export type ResponseGetData = Record<string, any>;
export type ResponseMetaData = Record<string, MetaObject>;
export type ResponseConfig = { title: string };
export type ResponseConditions = string;

View File

@ -0,0 +1,28 @@
import * as apiIUS from '@/api/ius/query';
import { Conditions } from '@/components/Conditions';
import type { Metadata } from 'next';
type Props = {
params: { slug: string };
searchParams: { [key: string]: string | string[] | undefined };
};
export async function generateMetadata({ params, searchParams }: Props): Promise<Metadata> {
const { title } = await apiIUS.getConfig({ searchParams, ...params });
const text = `Условия: ${title} | Эволюция`;
return {
description: text,
openGraph: {
description: text,
title: text,
},
title: text,
};
}
export default async function Page({ params, searchParams }: Props) {
const conditions = await apiIUS.getConditions({ searchParams, ...params });
return <Conditions html={conditions} />;
}

View File

@ -0,0 +1,15 @@
/* eslint-disable react/no-danger */
/* eslint-disable react/forbid-component-props */
import { Background } from 'ui';
type Props = {
readonly html: string;
};
export function Conditions({ html }: Props) {
return (
<Background className="justify-center">
<div dangerouslySetInnerHTML={{ __html: html }} className="justify-center" />
</Background>
);
}

View File

@ -1,9 +1,18 @@
import type { PropsWithChildren } from 'react';
import { cn } from './utils';
import type { VariantProps } from 'class-variance-authority';
import { cva } from 'class-variance-authority';
import { forwardRef, type HTMLAttributes } from 'react';
export function Background({ children }: PropsWithChildren) {
return (
<div className="grid w-full gap-2 rounded-sm border border-slate-100 bg-white p-5 lg:w-[1104px] ">
const variants = cva(
'grid w-full gap-2 rounded-sm border border-slate-100 bg-white p-5 lg:w-[1104px]'
);
export type BackgroundProps = HTMLAttributes<HTMLDivElement> & VariantProps<typeof variants>;
export const Background = forwardRef<HTMLDivElement, BackgroundProps>(
({ children, className, ...props }, ref) => (
<div className={cn(variants({ className }))} ref={ref} {...props}>
{children}
</div>
);
}
)
);