apps/web: add getPageUrlParams
remove title from Form components props type
This commit is contained in:
parent
239dcab5b3
commit
bc27e6fd33
@ -1,11 +1,12 @@
|
||||
import type * as t from './types';
|
||||
import { urls } from '@/config/urls';
|
||||
import type { makeCreateUrl } from '@/utils/url';
|
||||
import type { WretchError } from 'wretch';
|
||||
import wretch from 'wretch';
|
||||
|
||||
const api = wretch(urls.URL_UIS).errorType('json');
|
||||
|
||||
type CreateUrl = (path: string) => string;
|
||||
type CreateUrl = ReturnType<typeof makeCreateUrl>;
|
||||
|
||||
export async function getData(createUrl: CreateUrl) {
|
||||
const url = createUrl('');
|
||||
|
||||
@ -3,12 +3,13 @@ import * as apiIUS from '@/api/ius/query';
|
||||
import { Conditions } from '@/components/Conditions';
|
||||
import type { PageProps } from '@/types/page';
|
||||
import { withError } from '@/utils/error';
|
||||
import { makeCreateUrl } from '@/utils/url';
|
||||
import { getPageUrlParams, makeCreateUrl } from '@/utils/url';
|
||||
import type { Metadata } from 'next';
|
||||
import { Background } from 'ui';
|
||||
|
||||
export async function generateMetadata({ params, searchParams }: PageProps): Promise<Metadata> {
|
||||
const createUrl = makeCreateUrl(`/${params.slug}`, searchParams);
|
||||
export async function generateMetadata(pageProps: PageProps): Promise<Metadata> {
|
||||
const pageUrlParams = getPageUrlParams(pageProps);
|
||||
const createUrl = makeCreateUrl(pageUrlParams);
|
||||
const { title } = await apiIUS.getConfig(createUrl);
|
||||
const text = `Условия: ${title} | Эволюция`;
|
||||
|
||||
@ -22,10 +23,11 @@ export async function generateMetadata({ params, searchParams }: PageProps): Pro
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Page({ params, searchParams }: PageProps) {
|
||||
export default async function Page(pageProps: PageProps) {
|
||||
return withError({
|
||||
render: async () => {
|
||||
const createUrl = makeCreateUrl(`/${params.slug}`, searchParams);
|
||||
const pageUrlParams = getPageUrlParams(pageProps);
|
||||
const createUrl = makeCreateUrl(pageUrlParams);
|
||||
const conditions = await apiIUS.getConditions(createUrl);
|
||||
|
||||
return (
|
||||
|
||||
@ -2,12 +2,13 @@ import * as apiIUS from '@/api/ius/query';
|
||||
import * as Form from '@/components/Form';
|
||||
import type { PageProps } from '@/types/page';
|
||||
import { withError } from '@/utils/error';
|
||||
import { makeCreateUrl } from '@/utils/url';
|
||||
import { getPageUrlParams, makeCreateUrl } from '@/utils/url';
|
||||
import type { Metadata } from 'next';
|
||||
import { Background, Divider } from 'ui';
|
||||
|
||||
export async function generateMetadata({ params, searchParams }: PageProps): Promise<Metadata> {
|
||||
const createUrl = makeCreateUrl(`/${params.slug}`, searchParams);
|
||||
export async function generateMetadata(pageProps: PageProps): Promise<Metadata> {
|
||||
const pageUrlParams = getPageUrlParams(pageProps);
|
||||
const createUrl = makeCreateUrl(pageUrlParams);
|
||||
const { title } = await apiIUS.getConfig(createUrl);
|
||||
const text = `${title} | Эволюция`;
|
||||
|
||||
@ -21,21 +22,22 @@ export async function generateMetadata({ params, searchParams }: PageProps): Pro
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Page({ params, searchParams }: PageProps) {
|
||||
export default async function Page(pageProps: PageProps) {
|
||||
return withError({
|
||||
render: async () => {
|
||||
const createUrl = makeCreateUrl(`/${params.slug}`, searchParams);
|
||||
const pageUrlParams = getPageUrlParams(pageProps);
|
||||
const createUrl = makeCreateUrl(pageUrlParams);
|
||||
|
||||
return Promise.all([
|
||||
apiIUS.getData(createUrl),
|
||||
apiIUS.getMetaData(createUrl),
|
||||
apiIUS.getConfig(createUrl),
|
||||
]).then(([data, metaData, { title }]) => {
|
||||
const props = { data, metaData, title };
|
||||
const props = { data, metaData };
|
||||
|
||||
return (
|
||||
<Background>
|
||||
<Form.Header {...props} url={'/ius' + createUrl('/conditions')} />
|
||||
<Form.Header {...props} url={'/ius' + createUrl('/conditions')} title={title} />
|
||||
<Form.Elements {...props} />
|
||||
<Divider />
|
||||
<Form.Buttons />
|
||||
|
||||
@ -3,7 +3,7 @@ import type { Props } from './types';
|
||||
import Link from 'next/link';
|
||||
import { Heading } from 'ui';
|
||||
|
||||
export function Header({ title, url }: Props & { readonly url: string }) {
|
||||
export function Header({ title, url }: Props & { readonly title: string; readonly url: string }) {
|
||||
return (
|
||||
<div className="flex justify-between">
|
||||
<Heading size={2}>{title}</Heading>
|
||||
|
||||
@ -3,5 +3,4 @@ import type { ResponseGetData, ResponseMetaData } from '@/api/ius/types';
|
||||
export type Props = {
|
||||
readonly data: ResponseGetData;
|
||||
readonly metaData: ResponseMetaData;
|
||||
readonly title: string;
|
||||
};
|
||||
|
||||
@ -1,8 +1,12 @@
|
||||
import type { PageProps } from '@/types/page';
|
||||
|
||||
export function makeCreateUrl(path: string, searchParams?: PageProps['searchParams']) {
|
||||
export function getPageUrlParams({ params, searchParams }: PageProps) {
|
||||
return { path: `/${params.slug}`, urlSearchParams: new URLSearchParams(searchParams) };
|
||||
}
|
||||
|
||||
export function makeCreateUrl({ path, urlSearchParams }: ReturnType<typeof getPageUrlParams>) {
|
||||
return function (route: string) {
|
||||
if (searchParams) return `${path}${route}?${new URLSearchParams(searchParams)}`;
|
||||
if (urlSearchParams) return `${path}${route}?${urlSearchParams}`;
|
||||
|
||||
return path + route;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user