saleor-dashboard/src/shipping/index.tsx

66 lines
1.8 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import { parse as parseQs } from "qs";
2019-08-09 10:26:22 +00:00
import React from "react";
import { useIntl } from "react-intl";
2019-06-19 14:40:52 +00:00
import { Route, RouteComponentProps, Switch } from "react-router-dom";
import { sectionNames } from "@saleor/intl";
2019-06-19 14:40:52 +00:00
import { WindowTitle } from "../components/WindowTitle";
import {
shippingZoneAddPath,
shippingZonePath,
shippingZonesListPath,
ShippingZonesListUrlQueryParams,
ShippingZoneUrlQueryParams
} from "./urls";
import ShippingZoneCreate from "./views/ShippingZoneCreate";
import ShippingZoneDetailsComponent from "./views/ShippingZoneDetails";
import ShippingZonesListComponent from "./views/ShippingZonesList";
const ShippingZonesList: React.StatelessComponent<RouteComponentProps<{}>> = ({
location
}) => {
const qs = parseQs(location.search.substr(1));
const params: ShippingZonesListUrlQueryParams = qs;
return <ShippingZonesListComponent params={params} />;
};
interface ShippingZoneDetailsRouteProps {
id: string;
}
const ShippingZoneDetails: React.StatelessComponent<
RouteComponentProps<ShippingZoneDetailsRouteProps>
> = ({ location, match }) => {
const qs = parseQs(location.search.substr(1));
const params: ShippingZoneUrlQueryParams = qs;
return (
<ShippingZoneDetailsComponent
id={decodeURIComponent(match.params.id)}
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 path={shippingZonePath(":id")} component={ShippingZoneDetails} />
</Switch>
</>
);
};
2019-06-19 14:40:52 +00:00
export default ShippingRouter;