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-11 14:39:52 +00:00
|
|
|
import {
|
|
|
|
ActiveTab,
|
|
|
|
BulkAction,
|
|
|
|
Dialog,
|
|
|
|
Filters,
|
|
|
|
Pagination,
|
|
|
|
SingleAction,
|
2020-05-14 09:30:32 +00:00
|
|
|
Sort,
|
|
|
|
TabActionDialog
|
2019-09-11 14:39:52 +00:00
|
|
|
} from "../types";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
export const customerSection = "/customers/";
|
|
|
|
|
|
|
|
export const customerListPath = customerSection;
|
2019-09-11 14:39:52 +00:00
|
|
|
export enum CustomerListUrlFiltersEnum {
|
2020-01-02 12:22:12 +00:00
|
|
|
joinedFrom = "joinedFrom",
|
|
|
|
joinedTo = "joinedTo",
|
|
|
|
moneySpentFrom = "moneySpentFrom",
|
|
|
|
moneySpentTo = "moneySpentTo",
|
|
|
|
numberOfOrdersFrom = "numberOfOrdersFrom",
|
|
|
|
numberOfOrdersTo = "numberOfOrdersTo",
|
2019-09-11 14:39:52 +00:00
|
|
|
query = "query"
|
|
|
|
}
|
|
|
|
export type CustomerListUrlFilters = Filters<CustomerListUrlFiltersEnum>;
|
|
|
|
export type CustomerListUrlDialog = "remove" | TabActionDialog;
|
2019-12-17 17:13:56 +00:00
|
|
|
export enum CustomerListUrlSortField {
|
|
|
|
name = "name",
|
|
|
|
email = "email",
|
|
|
|
orders = "orders"
|
|
|
|
}
|
|
|
|
export type CustomerListUrlSort = Sort<CustomerListUrlSortField>;
|
2019-09-11 14:39:52 +00:00
|
|
|
export type CustomerListUrlQueryParams = ActiveTab &
|
|
|
|
BulkAction &
|
|
|
|
CustomerListUrlFilters &
|
2019-12-17 17:13:56 +00:00
|
|
|
CustomerListUrlSort &
|
2019-06-19 14:40:52 +00:00
|
|
|
Dialog<CustomerListUrlDialog> &
|
|
|
|
Pagination;
|
|
|
|
export const customerListUrl = (params?: CustomerListUrlQueryParams) =>
|
|
|
|
customerListPath + "?" + stringifyQs(params);
|
|
|
|
|
|
|
|
export const customerPath = (id: string) => urlJoin(customerSection, id);
|
|
|
|
export type CustomerUrlDialog = "remove";
|
|
|
|
export type CustomerUrlQueryParams = Dialog<CustomerUrlDialog>;
|
|
|
|
export const customerUrl = (id: string, params?: CustomerUrlQueryParams) =>
|
|
|
|
customerPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
|
|
|
|
|
|
|
export const customerAddPath = urlJoin(customerSection, "add");
|
|
|
|
export const customerAddUrl = customerAddPath;
|
|
|
|
|
|
|
|
export const customerAddressesPath = (id: string) =>
|
|
|
|
urlJoin(customerPath(id), "addresses");
|
|
|
|
export type CustomerAddressesUrlDialog = "add" | "edit" | "remove";
|
|
|
|
export type CustomerAddressesUrlQueryParams = Dialog<
|
|
|
|
CustomerAddressesUrlDialog
|
|
|
|
> &
|
|
|
|
SingleAction;
|
|
|
|
export const customerAddressesUrl = (
|
|
|
|
id: string,
|
|
|
|
params?: CustomerAddressesUrlQueryParams
|
|
|
|
) => customerAddressesPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|