diff --git a/apps/web/api/ius/query.ts b/apps/web/api/ius/query.ts index aab99f4..776fb34 100644 --- a/apps/web/api/ius/query.ts +++ b/apps/web/api/ius/query.ts @@ -1,17 +1,20 @@ 'use server'; import type * as t from './types'; import { getUrls } from '@/config/urls'; -import type { CreateUrl } from '@/utils/url'; +import { createUrl, type PageUrlParams } from '@/utils/url'; import type { WretchError } from 'wretch'; import wretch from 'wretch'; const urls = getUrls(); const api = wretch(urls.URL_UIS).errorType('json'); -type Input = { createUrl: CreateUrl; payload?: unknown }; +type Input = { pageUrlParams: PageUrlParams; payload?: unknown }; -export async function getData({ createUrl }: Input) { - const url = createUrl(''); +export async function getData({ pageUrlParams }: Input) { + const url = createUrl({ + ...pageUrlParams, + route: '', + }); return api .get(url) @@ -19,8 +22,8 @@ export async function getData({ createUrl }: Input) { .then((res) => res); } -export async function getMetaData({ createUrl }: Input) { - const url = createUrl('/meta'); +export async function getMetaData({ pageUrlParams }: Input) { + const url = createUrl({ ...pageUrlParams, route: '/meta' }); return api .get(url) @@ -28,8 +31,8 @@ export async function getMetaData({ createUrl }: Input) { .then((res) => res); } -export async function getConfig({ createUrl }: Input) { - const url = createUrl('/config'); +export async function getConfig({ pageUrlParams }: Input) { + const url = createUrl({ ...pageUrlParams, route: '/config' }); return api .get(url) @@ -37,8 +40,8 @@ export async function getConfig({ createUrl }: Input) { .then((res) => res); } -export async function getConditions({ createUrl }: Input) { - const url = createUrl('/conditions'); +export async function getConditions({ pageUrlParams }: Input) { + const url = createUrl({ ...pageUrlParams, route: '/conditions' }); return api .get(url) @@ -46,8 +49,8 @@ export async function getConditions({ createUrl }: Input) { .then((res) => res); } -export async function validate({ createUrl, payload }: Input) { - const url = createUrl('/validate'); +export async function validate({ pageUrlParams, payload }: Input) { + const url = createUrl({ ...pageUrlParams, route: '/validate' }); return api .post(payload, url) diff --git a/apps/web/app/ius/[slug]/conditions/page.tsx b/apps/web/app/ius/[slug]/conditions/page.tsx index e94bf69..a3da207 100644 --- a/apps/web/app/ius/[slug]/conditions/page.tsx +++ b/apps/web/app/ius/[slug]/conditions/page.tsx @@ -2,13 +2,12 @@ import * as apiIUS from '@/api/ius/query'; import { Conditions } from '@/components/Conditions'; import type { PageProps } from '@/types/page'; import { withError } from '@/utils/error'; -import { getPageUrlParams, makeCreateUrl } from '@/utils/url'; +import { getPageUrlParams } from '@/utils/url'; import type { Metadata } from 'next'; export async function generateMetadata(pageProps: PageProps): Promise { const pageUrlParams = getPageUrlParams(pageProps); - const createUrl = makeCreateUrl(pageUrlParams); - const { title } = await apiIUS.getConfig({ createUrl }); + const { title } = await apiIUS.getConfig({ pageUrlParams }); const text = `Условия: ${title} | Эволюция`; return { @@ -25,8 +24,7 @@ export default async function Page(pageProps: PageProps) { return withError({ render: async () => { const pageUrlParams = getPageUrlParams(pageProps); - const createUrl = makeCreateUrl(pageUrlParams); - const conditions = await apiIUS.getConditions({ createUrl }); + const conditions = await apiIUS.getConditions({ pageUrlParams }); return ; }, diff --git a/apps/web/app/ius/[slug]/page.tsx b/apps/web/app/ius/[slug]/page.tsx index 80acfae..75460db 100644 --- a/apps/web/app/ius/[slug]/page.tsx +++ b/apps/web/app/ius/[slug]/page.tsx @@ -2,13 +2,12 @@ import * as apiIUS from '@/api/ius/query'; import { Form } from '@/components/Form'; import type { PageProps } from '@/types/page'; import { withError } from '@/utils/error'; -import { getPageUrlParams, makeCreateUrl } from '@/utils/url'; +import { getPageUrlParams } from '@/utils/url'; import type { Metadata } from 'next'; export async function generateMetadata(pageProps: PageProps): Promise { const pageUrlParams = getPageUrlParams(pageProps); - const createUrl = makeCreateUrl(pageUrlParams); - const { title } = await apiIUS.getConfig({ createUrl }); + const { title } = await apiIUS.getConfig({ pageUrlParams }); const text = `${title} | Эволюция`; return { @@ -25,12 +24,11 @@ export default async function Page(pageProps: PageProps) { return withError({ render: async () => { const pageUrlParams = getPageUrlParams(pageProps); - const createUrl = makeCreateUrl(pageUrlParams); return Promise.all([ - apiIUS.getData({ createUrl }), - apiIUS.getMetaData({ createUrl }), - apiIUS.getConfig({ createUrl }), + apiIUS.getData({ pageUrlParams }), + apiIUS.getMetaData({ pageUrlParams }), + apiIUS.getConfig({ pageUrlParams }), ]).then(([data, metaData, { title }]) => { const props = { data, metaData, pageUrlParams, title }; diff --git a/apps/web/components/Form/Buttons.tsx b/apps/web/components/Form/Buttons.tsx index b3f7ebb..882588a 100644 --- a/apps/web/components/Form/Buttons.tsx +++ b/apps/web/components/Form/Buttons.tsx @@ -6,7 +6,7 @@ import { Button } from 'ui'; export function Buttons() { const { reset, setValidation, values } = useFormStore(); - const { createUrl, setFormStatus } = useContext(FormContext); + const { pageUrlParams, setFormStatus } = useContext(FormContext); return (
@@ -28,7 +28,7 @@ export function Buttons() {