apps/web: extract content to Form component
add mobile layout
This commit is contained in:
parent
2b0989e706
commit
8be08d2441
@ -1,7 +1,6 @@
|
|||||||
import * as apiIUS from '@/api/ius/query';
|
import * as apiIUS from '@/api/ius/query';
|
||||||
import type { Request } from '@/api/ius/types';
|
import type { Request } from '@/api/ius/types';
|
||||||
import { mapFieldTypeElement } from '@/config/elements';
|
import { Form } from '@/components/Form';
|
||||||
import { Background, Button, Content, ElementContainer } from 'ui';
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
params: { slug: string };
|
params: { slug: string };
|
||||||
@ -9,47 +8,12 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function Page(props: Props) {
|
export default async function Page(props: Props) {
|
||||||
const { data, metaData } = await getData({
|
const data = await getData({
|
||||||
searchParams: props.searchParams,
|
searchParams: props.searchParams,
|
||||||
slug: props.params.slug,
|
slug: props.params.slug,
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return <Form {...data} />;
|
||||||
<Content>
|
|
||||||
<Background>
|
|
||||||
<div className="grid auto-rows-auto grid-cols-2 gap-2 ">
|
|
||||||
{Object.keys(metaData).map((name) => {
|
|
||||||
const { fieldType, visible } = metaData[name];
|
|
||||||
|
|
||||||
if (!visible) return false;
|
|
||||||
|
|
||||||
const Element = mapFieldTypeElement[fieldType];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ElementContainer
|
|
||||||
key={name}
|
|
||||||
id={name}
|
|
||||||
title={fieldType === 'CHECKBOX' ? '' : metaData[name].label}
|
|
||||||
>
|
|
||||||
<Element
|
|
||||||
id={name}
|
|
||||||
required={metaData[name].required}
|
|
||||||
defaultValue={data[name]}
|
|
||||||
disabled={metaData[name].disabled}
|
|
||||||
title={metaData[name].label}
|
|
||||||
/>
|
|
||||||
</ElementContainer>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
<div className="grid grid-cols-3 gap-5 pt-3">
|
|
||||||
<Button>Сохранить</Button>
|
|
||||||
<Button>Возврат на доработку</Button>
|
|
||||||
<Button color="danger">Отмена</Button>
|
|
||||||
</div>
|
|
||||||
</Background>
|
|
||||||
</Content>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getData(params: Request) {
|
async function getData(params: Request) {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import './globals.css';
|
|||||||
import { Auth, Logo } from '@/components/layout';
|
import { Auth, Logo } from '@/components/layout';
|
||||||
import type { Metadata } from 'next';
|
import type { Metadata } from 'next';
|
||||||
import { Inter } from 'next/font/google';
|
import { Inter } from 'next/font/google';
|
||||||
import { Header } from 'ui';
|
import { Content, Header } from 'ui';
|
||||||
|
|
||||||
const inter = Inter({ subsets: ['latin'] });
|
const inter = Inter({ subsets: ['latin'] });
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ export default function RootLayout({ children }: { readonly children: React.Reac
|
|||||||
<Logo />
|
<Logo />
|
||||||
<Auth />
|
<Auth />
|
||||||
</Header>
|
</Header>
|
||||||
{children}
|
<Content>{children}</Content>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
|
|||||||
45
apps/web/components/Form.tsx
Normal file
45
apps/web/components/Form.tsx
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
import type { ResponseGetData, ResponseMetaData } from '@/api/ius/types';
|
||||||
|
import { mapFieldTypeElement } from '@/config/elements';
|
||||||
|
import { Background, Button, ElementContainer } from 'ui';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
readonly data: ResponseGetData;
|
||||||
|
readonly metaData: ResponseMetaData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function Form({ data, metaData }: Props) {
|
||||||
|
return (
|
||||||
|
<Background>
|
||||||
|
<div className="grid auto-rows-auto grid-cols-1 gap-2 md:grid-cols-2 lg:grid-cols-3 ">
|
||||||
|
{Object.keys(metaData).map((name) => {
|
||||||
|
const { fieldType, visible } = metaData[name];
|
||||||
|
|
||||||
|
if (!visible) return false;
|
||||||
|
|
||||||
|
const Element = mapFieldTypeElement[fieldType];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ElementContainer
|
||||||
|
key={name}
|
||||||
|
id={name}
|
||||||
|
title={fieldType === 'CHECKBOX' ? '' : metaData[name].label}
|
||||||
|
>
|
||||||
|
<Element
|
||||||
|
id={name}
|
||||||
|
required={metaData[name].required}
|
||||||
|
defaultValue={data[name]}
|
||||||
|
disabled={metaData[name].disabled}
|
||||||
|
title={metaData[name].label}
|
||||||
|
/>
|
||||||
|
</ElementContainer>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-1 gap-5 pt-3 lg:grid-cols-3">
|
||||||
|
<Button>Сохранить</Button>
|
||||||
|
<Button>Возврат на доработку</Button>
|
||||||
|
<Button color="danger">Отмена</Button>
|
||||||
|
</div>
|
||||||
|
</Background>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -1,5 +1,9 @@
|
|||||||
import type { PropsWithChildren } from 'react';
|
import type { PropsWithChildren } from 'react';
|
||||||
|
|
||||||
export function Background({ children }: PropsWithChildren) {
|
export function Background({ children }: PropsWithChildren) {
|
||||||
return <div className="rounded-sm border border-slate-100 bg-white p-5 ">{children}</div>;
|
return (
|
||||||
|
<div className="w-full rounded-sm border border-slate-100 bg-white p-5 md:w-auto">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@ export type ContainerProps = HTMLAttributes<HTMLDivElement> & PropsWithChildren;
|
|||||||
|
|
||||||
export function ElementContainer({ children, id, title, ...props }: ContainerProps) {
|
export function ElementContainer({ children, id, title, ...props }: ContainerProps) {
|
||||||
return (
|
return (
|
||||||
<div {...props} className="flex flex-col">
|
<div {...props} className="flex flex-col justify-center">
|
||||||
<label
|
<label
|
||||||
htmlFor={id}
|
htmlFor={id}
|
||||||
className="mb-1 block overflow-hidden overflow-ellipsis whitespace-nowrap text-sm font-medium text-black text-opacity-90"
|
className="mb-1 block overflow-hidden overflow-ellipsis whitespace-nowrap text-sm font-medium text-black text-opacity-90"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user