apps/web: add type CreateUrl to utils/url

This commit is contained in:
vchikalkin 2023-11-16 14:38:15 +03:00
parent c7559a0adc
commit 5d8aecfeb0
2 changed files with 5 additions and 2 deletions

View File

@ -1,12 +1,11 @@
import type * as t from './types';
import { urls } from '@/config/urls';
import type { makeCreateUrl } from '@/utils/url';
import type { CreateUrl } from '@/utils/url';
import type { WretchError } from 'wretch';
import wretch from 'wretch';
const api = wretch(urls.URL_UIS).errorType('json');
type CreateUrl = ReturnType<typeof makeCreateUrl>;
type Input = { createUrl: CreateUrl; payload?: unknown };
export async function getData({ createUrl }: Input) {

View File

@ -4,6 +4,8 @@ export function getPageUrlParams({ params, searchParams }: PageProps) {
return { path: `/${params.slug}`, urlSearchParams: new URLSearchParams(searchParams) };
}
export type PageUrlParams = ReturnType<typeof getPageUrlParams>;
export function makeCreateUrl({ path, urlSearchParams }: ReturnType<typeof getPageUrlParams>) {
return function (route: string) {
if (urlSearchParams) return `${path}${route}?${urlSearchParams}`;
@ -11,3 +13,5 @@ export function makeCreateUrl({ path, urlSearchParams }: ReturnType<typeof getPa
return path + route;
};
}
export type CreateUrl = ReturnType<typeof makeCreateUrl>;