2019-06-19 14:40:52 +00:00
|
|
|
import { stringify as stringifyQs } from "qs";
|
2019-08-09 10:26:22 +00:00
|
|
|
import urlJoin from "url-join";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-09-10 15:14:11 +00:00
|
|
|
import {
|
|
|
|
ActiveTab,
|
|
|
|
BulkAction,
|
|
|
|
Dialog,
|
|
|
|
Filters,
|
|
|
|
Pagination,
|
2019-09-13 11:33:42 +00:00
|
|
|
Sort,
|
2019-09-10 15:14:11 +00:00
|
|
|
TabActionDialog
|
|
|
|
} from "../types";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
const productSection = "/products/";
|
|
|
|
|
|
|
|
export const productAddPath = urlJoin(productSection, "add");
|
|
|
|
export const productAddUrl = productAddPath;
|
|
|
|
|
|
|
|
export const productListPath = productSection;
|
|
|
|
export type ProductListUrlDialog =
|
|
|
|
| "publish"
|
|
|
|
| "unpublish"
|
|
|
|
| "delete"
|
2019-09-10 15:14:11 +00:00
|
|
|
| TabActionDialog;
|
2019-06-19 14:40:52 +00:00
|
|
|
export enum ProductListUrlFiltersEnum {
|
|
|
|
isPublished = "isPublished",
|
|
|
|
priceFrom = "priceFrom",
|
|
|
|
priceTo = "priceTo",
|
|
|
|
status = "status",
|
|
|
|
query = "query"
|
|
|
|
}
|
|
|
|
export type ProductListUrlFilters = Filters<ProductListUrlFiltersEnum>;
|
2019-09-13 14:17:12 +00:00
|
|
|
export enum ProductListUrlSortField {
|
2019-09-13 11:33:42 +00:00
|
|
|
name = "name",
|
2019-09-13 14:17:12 +00:00
|
|
|
productType = "productType",
|
2019-09-13 11:33:42 +00:00
|
|
|
status = "status",
|
|
|
|
price = "price"
|
|
|
|
}
|
2019-09-13 14:17:12 +00:00
|
|
|
export type ProductListUrlSort = Sort<ProductListUrlSortField>;
|
2019-06-19 14:40:52 +00:00
|
|
|
export type ProductListUrlQueryParams = BulkAction &
|
|
|
|
Dialog<ProductListUrlDialog> &
|
|
|
|
ProductListUrlFilters &
|
2019-09-13 11:33:42 +00:00
|
|
|
ProductListUrlSort &
|
2019-06-19 14:40:52 +00:00
|
|
|
Pagination &
|
|
|
|
ActiveTab;
|
|
|
|
export const productListUrl = (params?: ProductListUrlQueryParams): string =>
|
|
|
|
productListPath + "?" + stringifyQs(params);
|
|
|
|
|
|
|
|
export const productPath = (id: string) => urlJoin(productSection + id);
|
|
|
|
export type ProductUrlDialog = "remove";
|
|
|
|
export type ProductUrlQueryParams = BulkAction &
|
|
|
|
Dialog<"remove" | "remove-variants">;
|
|
|
|
export const productUrl = (id: string, params?: ProductUrlQueryParams) =>
|
|
|
|
productPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
|
|
|
|
|
|
|
export const productVariantEditPath = (productId: string, variantId: string) =>
|
|
|
|
urlJoin(productSection, productId, "variant", variantId);
|
|
|
|
export type ProductVariantEditUrlDialog = "remove";
|
|
|
|
export type ProductVariantEditUrlQueryParams = Dialog<"remove">;
|
|
|
|
export const productVariantEditUrl = (
|
|
|
|
productId: string,
|
|
|
|
variantId: string,
|
|
|
|
params?: ProductVariantEditUrlQueryParams
|
|
|
|
) =>
|
|
|
|
productVariantEditPath(
|
|
|
|
encodeURIComponent(productId),
|
|
|
|
encodeURIComponent(variantId)
|
|
|
|
) +
|
|
|
|
"?" +
|
|
|
|
stringifyQs(params);
|
|
|
|
|
|
|
|
export const productVariantAddPath = (productId: string) =>
|
|
|
|
urlJoin(productSection, productId, "variant/add");
|
|
|
|
export const productVariantAddUrl = (productId: string) =>
|
|
|
|
productVariantAddPath(encodeURIComponent(productId));
|
|
|
|
|
|
|
|
export const productImagePath = (productId: string, imageId: string) =>
|
|
|
|
urlJoin(productSection, productId, "image", imageId);
|
|
|
|
export type ProductImageUrlDialog = "remove";
|
|
|
|
export type ProductImageUrlQueryParams = Dialog<"remove">;
|
|
|
|
export const productImageUrl = (
|
|
|
|
productId: string,
|
|
|
|
imageId: string,
|
|
|
|
params?: ProductImageUrlQueryParams
|
|
|
|
) =>
|
|
|
|
productImagePath(encodeURIComponent(productId), encodeURIComponent(imageId)) +
|
|
|
|
"?" +
|
|
|
|
stringifyQs(params);
|