
* 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>
153 lines
4.2 KiB
TypeScript
153 lines
4.2 KiB
TypeScript
import { sectionNames } from "@saleor/intl";
|
|
import { parse as parseQs } from "qs";
|
|
import React from "react";
|
|
import { useIntl } from "react-intl";
|
|
import { Route, RouteComponentProps, Switch } from "react-router-dom";
|
|
|
|
import { WindowTitle } from "../components/WindowTitle";
|
|
import {
|
|
shippingPriceRatesEditPath,
|
|
shippingPriceRatesPath,
|
|
ShippingRateCreateUrlQueryParams,
|
|
ShippingRateUrlQueryParams,
|
|
shippingWeightRatesEditPath,
|
|
shippingWeightRatesPath,
|
|
shippingZoneAddPath,
|
|
shippingZonePath,
|
|
shippingZonesListPath,
|
|
ShippingZonesListUrlQueryParams,
|
|
ShippingZoneUrlQueryParams
|
|
} from "./urls";
|
|
import PriceRatesCreateComponent from "./views/PriceRatesCreate";
|
|
import PriceRatesUpdateComponent from "./views/PriceRatesUpdate";
|
|
import ShippingZoneCreate from "./views/ShippingZoneCreate";
|
|
import ShippingZoneDetailsComponent from "./views/ShippingZoneDetails";
|
|
import ShippingZonesListComponent from "./views/ShippingZonesList";
|
|
import WeightRatesCreateComponent from "./views/WeightRatesCreate";
|
|
import WeightRatesUpdateComponent from "./views/WeightRatesUpdate";
|
|
|
|
const ShippingZonesList: React.FC<RouteComponentProps<{}>> = ({ location }) => {
|
|
const qs = parseQs(location.search.substr(1));
|
|
const params: ShippingZonesListUrlQueryParams = qs;
|
|
return <ShippingZonesListComponent params={params} />;
|
|
};
|
|
|
|
interface ShippingZoneDetailsRouteProps {
|
|
id: string;
|
|
}
|
|
const ShippingZoneDetails: React.FC<RouteComponentProps<
|
|
ShippingZoneDetailsRouteProps
|
|
>> = ({ location, match }) => {
|
|
const qs = parseQs(location.search.substr(1));
|
|
const params: ShippingZoneUrlQueryParams = qs;
|
|
return (
|
|
<ShippingZoneDetailsComponent
|
|
id={decodeURIComponent(match.params.id)}
|
|
params={params}
|
|
/>
|
|
);
|
|
};
|
|
|
|
const PriceRatesCreate: React.FC<RouteComponentProps<{ id: string }>> = ({
|
|
match
|
|
}) => {
|
|
const qs = parseQs(location.search.substr(1));
|
|
const params: ShippingRateCreateUrlQueryParams = qs;
|
|
|
|
return (
|
|
<PriceRatesCreateComponent
|
|
id={decodeURIComponent(match.params.id)}
|
|
params={params}
|
|
/>
|
|
);
|
|
};
|
|
|
|
const WeightRatesCreate: React.FC<RouteComponentProps<{ id: string }>> = ({
|
|
match
|
|
}) => {
|
|
const qs = parseQs(location.search.substr(1));
|
|
const params: ShippingRateCreateUrlQueryParams = qs;
|
|
|
|
return (
|
|
<WeightRatesCreateComponent
|
|
id={decodeURIComponent(match.params.id)}
|
|
params={params}
|
|
/>
|
|
);
|
|
};
|
|
|
|
const WeightRatesUpdate: React.FC<RouteComponentProps<{
|
|
id: string;
|
|
rateId: string;
|
|
}>> = ({ match }) => {
|
|
const qs = parseQs(location.search.substr(1));
|
|
const params: ShippingRateUrlQueryParams = qs;
|
|
|
|
return (
|
|
<WeightRatesUpdateComponent
|
|
id={decodeURIComponent(match.params.id)}
|
|
rateId={decodeURIComponent(match.params.rateId)}
|
|
params={params}
|
|
/>
|
|
);
|
|
};
|
|
|
|
const PriceRatesUpdate: React.FC<RouteComponentProps<{
|
|
id: string;
|
|
rateId: string;
|
|
}>> = ({ match }) => {
|
|
const qs = parseQs(location.search.substr(1));
|
|
const params: ShippingRateUrlQueryParams = qs;
|
|
|
|
return (
|
|
<PriceRatesUpdateComponent
|
|
id={decodeURIComponent(match.params.id)}
|
|
rateId={decodeURIComponent(match.params.rateId)}
|
|
params={params}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export const ShippingRouter: React.FC = () => {
|
|
const intl = useIntl();
|
|
|
|
return (
|
|
<>
|
|
<WindowTitle title={intl.formatMessage(sectionNames.shipping)} />
|
|
<Switch>
|
|
<Route
|
|
exact
|
|
path={shippingZonesListPath}
|
|
component={ShippingZonesList}
|
|
/>
|
|
<Route
|
|
exact
|
|
path={shippingZoneAddPath}
|
|
component={ShippingZoneCreate}
|
|
/>
|
|
<Route
|
|
exact
|
|
path={shippingZonePath(":id")}
|
|
component={ShippingZoneDetails}
|
|
/>
|
|
<Route
|
|
path={shippingPriceRatesPath(":id")}
|
|
component={PriceRatesCreate}
|
|
/>
|
|
<Route
|
|
path={shippingWeightRatesPath(":id")}
|
|
component={WeightRatesCreate}
|
|
/>
|
|
<Route
|
|
path={shippingWeightRatesEditPath(":id", ":rateId")}
|
|
component={WeightRatesUpdate}
|
|
/>
|
|
<Route
|
|
path={shippingPriceRatesEditPath(":id", ":rateId")}
|
|
component={PriceRatesUpdate}
|
|
/>
|
|
</Switch>
|
|
</>
|
|
);
|
|
};
|
|
export default ShippingRouter;
|