2020-05-14 09:30:32 +00:00
|
|
|
import { sectionNames } from "@saleor/intl";
|
|
|
|
import { asSortParams } from "@saleor/utils/sort";
|
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";
|
2019-08-26 17:44:42 +00:00
|
|
|
import { useIntl } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { Route, RouteComponentProps, Switch } from "react-router-dom";
|
|
|
|
|
|
|
|
import { WindowTitle } from "../components/WindowTitle";
|
|
|
|
import {
|
|
|
|
orderDraftListPath,
|
|
|
|
OrderDraftListUrlQueryParams,
|
2020-05-14 09:30:32 +00:00
|
|
|
OrderDraftListUrlSortField,
|
|
|
|
orderFulfillPath,
|
2019-06-19 14:40:52 +00:00
|
|
|
orderListPath,
|
|
|
|
OrderListUrlQueryParams,
|
2020-04-20 17:18:20 +00:00
|
|
|
OrderListUrlSortField,
|
2020-05-14 09:30:32 +00:00
|
|
|
orderPath,
|
2020-12-01 13:13:05 +00:00
|
|
|
orderRefundPath,
|
2020-11-30 13:19:57 +00:00
|
|
|
orderSettingsPath,
|
2020-05-14 09:30:32 +00:00
|
|
|
OrderUrlQueryParams
|
2019-06-19 14:40:52 +00:00
|
|
|
} from "./urls";
|
|
|
|
import OrderDetailsComponent from "./views/OrderDetails";
|
|
|
|
import OrderDraftListComponent from "./views/OrderDraftList";
|
2020-05-14 09:30:32 +00:00
|
|
|
import OrderFulfillComponent from "./views/OrderFulfill";
|
2019-06-19 14:40:52 +00:00
|
|
|
import OrderListComponent from "./views/OrderList";
|
2020-12-01 13:13:05 +00:00
|
|
|
import OrderRefundComponent from "./views/OrderRefund";
|
2020-11-30 13:19:57 +00:00
|
|
|
import OrderSettings from "./views/OrderSettings";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const OrderList: React.FC<RouteComponentProps<any>> = ({ location }) => {
|
2019-06-19 14:40:52 +00:00
|
|
|
const qs = parseQs(location.search.substr(1));
|
2019-12-17 17:13:56 +00:00
|
|
|
const params: OrderListUrlQueryParams = asSortParams(
|
|
|
|
qs,
|
|
|
|
OrderListUrlSortField,
|
|
|
|
OrderListUrlSortField.number,
|
|
|
|
false
|
|
|
|
);
|
2019-06-19 14:40:52 +00:00
|
|
|
return <OrderListComponent params={params} />;
|
|
|
|
};
|
2019-11-07 11:34:54 +00:00
|
|
|
const OrderDraftList: React.FC<RouteComponentProps<any>> = ({ location }) => {
|
2019-06-19 14:40:52 +00:00
|
|
|
const qs = parseQs(location.search.substr(1));
|
2019-12-17 17:13:56 +00:00
|
|
|
const params: OrderDraftListUrlQueryParams = asSortParams(
|
|
|
|
qs,
|
|
|
|
OrderDraftListUrlSortField,
|
|
|
|
OrderDraftListUrlSortField.number,
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
return <OrderDraftListComponent params={params} />;
|
|
|
|
};
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const OrderDetails: React.FC<RouteComponentProps<any>> = ({
|
2019-06-19 14:40:52 +00:00
|
|
|
location,
|
|
|
|
match
|
|
|
|
}) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: OrderUrlQueryParams = qs;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<OrderDetailsComponent
|
|
|
|
id={decodeURIComponent(match.params.id)}
|
|
|
|
params={params}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2020-04-20 17:18:20 +00:00
|
|
|
const OrderFulfill: React.FC<RouteComponentProps<any>> = ({ match }) => (
|
|
|
|
<OrderFulfillComponent orderId={decodeURIComponent(match.params.id)} />
|
|
|
|
);
|
|
|
|
|
2020-12-01 13:13:05 +00:00
|
|
|
const OrderRefund: React.FC<RouteComponentProps<any>> = ({ match }) => (
|
|
|
|
<OrderRefundComponent orderId={decodeURIComponent(match.params.id)} />
|
|
|
|
);
|
|
|
|
|
2019-08-26 17:44:42 +00:00
|
|
|
const Component = () => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<WindowTitle title={intl.formatMessage(sectionNames.orders)} />
|
|
|
|
<Switch>
|
2020-11-30 13:19:57 +00:00
|
|
|
<Route exact path={orderSettingsPath} component={OrderSettings} />
|
2019-08-26 17:44:42 +00:00
|
|
|
<Route exact path={orderDraftListPath} component={OrderDraftList} />
|
|
|
|
<Route exact path={orderListPath} component={OrderList} />
|
2020-04-20 17:18:20 +00:00
|
|
|
<Route path={orderFulfillPath(":id")} component={OrderFulfill} />
|
2020-12-01 13:13:05 +00:00
|
|
|
<Route path={orderRefundPath(":id")} component={OrderRefund} />
|
2019-08-26 17:44:42 +00:00
|
|
|
<Route path={orderPath(":id")} component={OrderDetails} />
|
|
|
|
</Switch>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
export default Component;
|