saleor-dashboard/src/categories/urls.ts

37 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import { stringify as stringifyQs } from "qs";
import * as urlJoin from "url-join";
import { ActiveTab, BulkAction, Dialog, Pagination } from "../types";
import { CategoryPageTab } from "./components/CategoryUpdatePage";
const categorySectionUrl = "/categories/";
export const categoryListPath = categorySectionUrl;
export type CategoryListUrlDialog = "delete";
export type CategoryListUrlQueryParams = BulkAction &
Dialog<CategoryListUrlDialog> &
Pagination;
export const categoryListUrl = (params?: CategoryListUrlQueryParams) =>
categorySectionUrl + "?" + stringifyQs(params);
export const categoryPath = (id: string) => urlJoin(categorySectionUrl, id);
export type CategoryUrlDialog =
| "delete"
| "delete-categories"
| "delete-products";
export type CategoryUrlQueryParams = BulkAction &
Dialog<CategoryUrlDialog> &
Pagination &
ActiveTab<CategoryPageTab>;
export const categoryUrl = (id: string, params?: CategoryUrlQueryParams) =>
categoryPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
export const categoryAddPath = (parentId?: string) => {
if (parentId) {
return urlJoin(categoryPath(parentId), "add");
}
return urlJoin(categorySectionUrl, "add");
};
export const categoryAddUrl = (parentId?: string) =>
categoryAddPath(parentId ? encodeURIComponent(parentId) : undefined);