
* Clean up stories * Add missing props * Add zip codes section (#861) * Add zip code listing * Add list wrapping * Update snapshots * Set up API data * Fix lgtm warning * Update snapshots * Run Actions on all PR * Checks on PR * Test envs on PR * Cleanup action on PR * Update messages Co-authored-by: Krzysztof Wolski <krzysztof.k.wolski@gmail.com> * Add zip code range dialog * Fix path management * Use query params to handle modal actions * Allow zip codes to be assigned to shipping method * Make params optional * Fix types * Add zip code deletion (#871) * Add zip code range dialog * Fix path management * Use query params to handle modal actions * Allow zip codes to be assigned to shipping method * Make params optional * Fix types * Clean up urls * Add zip code range delete action * Update snapshots and messages * Update testing and changelog * Update schema * Simplify code * Refresh zip code list after assigning them * Update view after zip code deletion * Update types and snapshots * Update snapshots * Fix error message, checkbox default value (#880) * Fix error message, checkbox default value * Update snapshots * Use price instead of weight variant * Update schema and types * Hide exclude/include zip codes section * Update stories Co-authored-by: Krzysztof Wolski <krzysztof.k.wolski@gmail.com> Co-authored-by: Tomasz Szymański <lime129@gmail.com>
93 lines
3 KiB
TypeScript
93 lines
3 KiB
TypeScript
import { stringify as stringifyQs } from "qs";
|
|
import urlJoin from "url-join";
|
|
|
|
import { BulkAction, Dialog, Pagination, SingleAction } from "../types";
|
|
import { ShippingMethodTypeEnum } from "../types/globalTypes";
|
|
|
|
export const shippingSection = "/shipping/";
|
|
|
|
export const shippingZonesListPath = shippingSection;
|
|
export type ShippingZonesListUrlDialog = "remove" | "remove-many";
|
|
export type ShippingZonesListUrlQueryParams = BulkAction &
|
|
Dialog<ShippingZonesListUrlDialog> &
|
|
Pagination &
|
|
SingleAction;
|
|
export const shippingZonesListUrl = (
|
|
params?: ShippingZonesListUrlQueryParams
|
|
) => shippingZonesListPath + "?" + stringifyQs(params);
|
|
|
|
export const shippingZonePath = (id: string) =>
|
|
urlJoin(shippingZonesListPath, id);
|
|
export type ShippingZoneUrlDialog =
|
|
| "add-rate"
|
|
| "add-warehouse"
|
|
| "assign-country"
|
|
| "edit-rate"
|
|
| "remove"
|
|
| "remove-rate"
|
|
| "unassign-country";
|
|
export type ShippingZoneUrlQueryParams = Dialog<ShippingZoneUrlDialog> &
|
|
SingleAction &
|
|
Partial<{
|
|
type: ShippingMethodTypeEnum;
|
|
}>;
|
|
export const shippingZoneUrl = (
|
|
id: string,
|
|
params?: ShippingZoneUrlQueryParams
|
|
) => shippingZonePath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
|
|
|
type ZipCodeRangeActions = "add-range" | "remove-range";
|
|
export type ShippingRateUrlDialog = ZipCodeRangeActions | "remove";
|
|
export type ShippingRateUrlQueryParams = Dialog<ShippingRateUrlDialog> &
|
|
SingleAction;
|
|
export type ShippingRateCreateUrlDialog = ZipCodeRangeActions;
|
|
export type ShippingRateCreateUrlQueryParams = Dialog<
|
|
ShippingRateCreateUrlDialog
|
|
> &
|
|
SingleAction;
|
|
|
|
export const shippingPriceRatesPath = (id: string) =>
|
|
urlJoin(shippingZonePath(id), "price", "add");
|
|
export const shippingPriceRatesUrl = (
|
|
id: string,
|
|
params?: ShippingRateCreateUrlQueryParams
|
|
) => shippingPriceRatesPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
|
|
|
export const shippingWeightRatesPath = (id: string) =>
|
|
urlJoin(shippingZonePath(id), "weight", "add");
|
|
export const shippingWeightRatesUrl = (
|
|
id: string,
|
|
params?: ShippingRateCreateUrlQueryParams
|
|
) =>
|
|
shippingWeightRatesPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
|
|
|
export const shippingPriceRatesEditPath = (id: string, rateId: string) =>
|
|
urlJoin(shippingZonePath(id), "price", rateId);
|
|
export const shippingPriceRatesEditUrl = (
|
|
id: string,
|
|
rateId: string,
|
|
params?: ShippingRateUrlQueryParams
|
|
) =>
|
|
shippingPriceRatesEditPath(
|
|
encodeURIComponent(id),
|
|
encodeURIComponent(rateId)
|
|
) +
|
|
"?" +
|
|
stringifyQs(params);
|
|
|
|
export const shippingWeightRatesEditPath = (id: string, rateId: string) =>
|
|
urlJoin(shippingZonePath(id), "weight", rateId);
|
|
export const shippingWeightRatesEditUrl = (
|
|
id: string,
|
|
rateId: string,
|
|
params?: ShippingRateUrlQueryParams
|
|
) =>
|
|
shippingWeightRatesEditPath(
|
|
encodeURIComponent(id),
|
|
encodeURIComponent(rateId)
|
|
) +
|
|
"?" +
|
|
stringifyQs(params);
|
|
|
|
export const shippingZoneAddPath = urlJoin(shippingZonesListPath, "add");
|
|
export const shippingZoneAddUrl = shippingZoneAddPath + "?";
|