diff --git a/apps/web/app/ius/[slug]/conditions/page.tsx b/apps/web/app/ius/[slug]/conditions/page.tsx index 76bf231..e5622bf 100644 --- a/apps/web/app/ius/[slug]/conditions/page.tsx +++ b/apps/web/app/ius/[slug]/conditions/page.tsx @@ -1,16 +1,12 @@ /* eslint-disable react/forbid-component-props */ import * as apiIUS from '@/api/ius/query'; import { Conditions } from '@/components/Conditions'; +import type { PageProps } from '@/types/page'; import { makeCreateUrl } from '@/utils/url'; import type { Metadata } from 'next'; import { Background } from 'ui'; -type Props = { - params: { slug: string }; - searchParams: string | string[][] | Record; -}; - -export async function generateMetadata({ params, searchParams }: Props): Promise { +export async function generateMetadata({ params, searchParams }: PageProps): Promise { const createUrl = makeCreateUrl(`/${params.slug}`, searchParams); const { title } = await apiIUS.getConfig(createUrl); const text = `Условия: ${title} | Эволюция`; @@ -25,7 +21,7 @@ export async function generateMetadata({ params, searchParams }: Props): Promise }; } -export default async function Page({ params, searchParams }: Props) { +export default async function Page({ params, searchParams }: PageProps) { const createUrl = makeCreateUrl(`/${params.slug}`, searchParams); const conditions = await apiIUS.getConditions(createUrl); diff --git a/apps/web/app/ius/[slug]/page.tsx b/apps/web/app/ius/[slug]/page.tsx index 83c9c5c..3fe9459 100644 --- a/apps/web/app/ius/[slug]/page.tsx +++ b/apps/web/app/ius/[slug]/page.tsx @@ -1,15 +1,11 @@ import * as apiIUS from '@/api/ius/query'; -import { FormButtons, FormElements, FormHeader } from '@/components/Form'; +import * as Form from '@/components/Form'; +import type { PageProps } from '@/types/page'; import { makeCreateUrl } from '@/utils/url'; import type { Metadata } from 'next'; import { Background, Divider } from 'ui'; -type Props = { - params: { slug: string }; - searchParams: string | string[][] | Record; -}; - -export async function generateMetadata({ params, searchParams }: Props): Promise { +export async function generateMetadata({ params, searchParams }: PageProps): Promise { const createUrl = makeCreateUrl(`/${params.slug}`, searchParams); const { title } = await apiIUS.getConfig(createUrl); const text = `${title} | Эволюция`; @@ -24,7 +20,7 @@ export async function generateMetadata({ params, searchParams }: Props): Promise }; } -export default async function Page({ params, searchParams }: Props) { +export default async function Page({ params, searchParams }: PageProps) { const createUrl = makeCreateUrl(`/${params.slug}`, searchParams); const data = await apiIUS.getData(createUrl); @@ -35,10 +31,10 @@ export default async function Page({ params, searchParams }: Props) { return ( - - + + - + ); } diff --git a/apps/web/components/Form.tsx b/apps/web/components/Form.tsx deleted file mode 100644 index 2685bdc..0000000 --- a/apps/web/components/Form.tsx +++ /dev/null @@ -1,65 +0,0 @@ -/* eslint-disable react/forbid-component-props */ -/* eslint-disable react/no-unused-prop-types */ -'use client'; -import type { ResponseGetData, ResponseMetaData } from '@/api/ius/types'; -import { mapFieldTypeElement } from '@/config/elements'; -import Link from 'next/link'; -import { Button, ElementContainer, Heading } from 'ui'; - -type Props = { - readonly data: ResponseGetData; - readonly metaData: ResponseMetaData; - readonly title: string; -}; - -export function FormHeader({ title, url }: Props & { readonly url: string }) { - return ( -
- {title} - - Посмотреть условия - -
- ); -} - -export function FormButtons() { - return ( -
- - - -
- ); -} - -export function FormElements({ data, metaData }: Props) { - return ( -
- {Object.keys(metaData).map((name) => { - const { fieldType, label, max, min = 0, visible, ...props } = metaData[name]; - - if (!visible) return false; - - const Element = mapFieldTypeElement[fieldType]; - - return ( - - - - ); - })} -
- ); -} diff --git a/apps/web/components/Form/Buttons.tsx b/apps/web/components/Form/Buttons.tsx new file mode 100644 index 0000000..31bc0e5 --- /dev/null +++ b/apps/web/components/Form/Buttons.tsx @@ -0,0 +1,11 @@ +import { Button } from 'ui'; + +export function Buttons() { + return ( +
+ + + +
+ ); +} diff --git a/apps/web/components/Form/Elements.tsx b/apps/web/components/Form/Elements.tsx new file mode 100644 index 0000000..ba7d337 --- /dev/null +++ b/apps/web/components/Form/Elements.tsx @@ -0,0 +1,34 @@ +import type { Props } from './types'; +import { mapFieldTypeElement } from '@/config/elements'; +import { ElementContainer } from 'ui'; + +export function Elements({ data, metaData }: Props) { + return ( +
+ {Object.keys(metaData).map((name) => { + const { fieldType, label, max, min = 0, visible, ...props } = metaData[name]; + + if (!visible) return false; + + const Element = mapFieldTypeElement[fieldType]; + + return ( + + + + ); + })} +
+ ); +} diff --git a/apps/web/components/Form/Header.tsx b/apps/web/components/Form/Header.tsx new file mode 100644 index 0000000..6bb0363 --- /dev/null +++ b/apps/web/components/Form/Header.tsx @@ -0,0 +1,15 @@ +/* eslint-disable react/forbid-component-props */ +import type { Props } from './types'; +import Link from 'next/link'; +import { Heading } from 'ui'; + +export function Header({ title, url }: Props & { readonly url: string }) { + return ( +
+ {title} + + Посмотреть условия + +
+ ); +} diff --git a/apps/web/components/Form/index.ts b/apps/web/components/Form/index.ts new file mode 100644 index 0000000..0ba8dd2 --- /dev/null +++ b/apps/web/components/Form/index.ts @@ -0,0 +1,3 @@ +export * from './Buttons'; +export * from './Elements'; +export * from './Header'; diff --git a/apps/web/components/Form/types.ts b/apps/web/components/Form/types.ts new file mode 100644 index 0000000..9f13076 --- /dev/null +++ b/apps/web/components/Form/types.ts @@ -0,0 +1,7 @@ +import type { ResponseGetData, ResponseMetaData } from '@/api/ius/types'; + +export type Props = { + readonly data: ResponseGetData; + readonly metaData: ResponseMetaData; + readonly title: string; +}; diff --git a/apps/web/types/page.ts b/apps/web/types/page.ts new file mode 100644 index 0000000..40d21f5 --- /dev/null +++ b/apps/web/types/page.ts @@ -0,0 +1,4 @@ +export type PageProps = { + params: { slug: string }; + searchParams: string | string[][] | Record; +}; diff --git a/apps/web/utils/url.ts b/apps/web/utils/url.ts index 3da9a40..cf7aaa6 100644 --- a/apps/web/utils/url.ts +++ b/apps/web/utils/url.ts @@ -1,7 +1,6 @@ -export function makeCreateUrl( - path: string, - searchParams?: string | string[][] | Record -) { +import type { PageProps } from '@/types/page'; + +export function makeCreateUrl(path: string, searchParams?: PageProps['searchParams']) { return function (route: string) { if (searchParams) return `${path}${route}?${new URLSearchParams(searchParams)}`;