2021-08-09 15:27:13 +00:00
|
|
|
import { stringifyQs } from "@saleor/utils/urls";
|
2019-08-09 10:26:22 +00:00
|
|
|
import urlJoin from "url-join";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-09-11 12:59:41 +00:00
|
|
|
import {
|
|
|
|
ActiveTab,
|
|
|
|
BulkAction,
|
|
|
|
Dialog,
|
|
|
|
Filters,
|
|
|
|
Pagination,
|
2020-05-14 09:30:32 +00:00
|
|
|
Sort,
|
|
|
|
TabActionDialog
|
2019-09-11 12:59:41 +00:00
|
|
|
} from "../types";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
const categorySectionUrl = "/categories/";
|
|
|
|
|
|
|
|
export const categoryListPath = categorySectionUrl;
|
2019-09-11 12:59:41 +00:00
|
|
|
export enum CategoryListUrlFiltersEnum {
|
|
|
|
query = "query"
|
|
|
|
}
|
|
|
|
export type CategoryListUrlFilters = Filters<CategoryListUrlFiltersEnum>;
|
|
|
|
export type CategoryListUrlDialog = "delete" | TabActionDialog;
|
2019-12-17 17:13:56 +00:00
|
|
|
export enum CategoryListUrlSortField {
|
|
|
|
name = "name",
|
|
|
|
productCount = "products",
|
|
|
|
subcategoryCount = "subcategories"
|
|
|
|
}
|
|
|
|
export type CategoryListUrlSort = Sort<CategoryListUrlSortField>;
|
2019-09-11 12:59:41 +00:00
|
|
|
export type CategoryListUrlQueryParams = ActiveTab &
|
|
|
|
BulkAction &
|
|
|
|
CategoryListUrlFilters &
|
2019-12-17 17:13:56 +00:00
|
|
|
CategoryListUrlSort &
|
2019-06-19 14:40:52 +00:00
|
|
|
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";
|
2021-12-06 14:41:18 +00:00
|
|
|
export type CategoryUrlQueryParams = BulkAction & Dialog<CategoryUrlDialog>;
|
2019-06-19 14:40:52 +00:00
|
|
|
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);
|