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 13:59:32 +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 { saleDetailsPageTab } from "./components/SaleDetailsPage";
|
|
|
|
import { voucherDetailsPageTab } from "./components/VoucherDetailsPage";
|
|
|
|
import {
|
|
|
|
saleAddPath,
|
|
|
|
saleListPath,
|
|
|
|
SaleListUrlQueryParams,
|
2020-05-14 09:30:32 +00:00
|
|
|
SaleListUrlSortField,
|
2019-06-19 14:40:52 +00:00
|
|
|
salePath,
|
|
|
|
SaleUrlQueryParams,
|
|
|
|
voucherAddPath,
|
|
|
|
voucherListPath,
|
|
|
|
VoucherListUrlQueryParams,
|
2020-05-14 09:30:32 +00:00
|
|
|
VoucherListUrlSortField,
|
2019-06-19 14:40:52 +00:00
|
|
|
voucherPath,
|
2020-05-14 09:30:32 +00:00
|
|
|
VoucherUrlQueryParams
|
2019-06-19 14:40:52 +00:00
|
|
|
} from "./urls";
|
|
|
|
import SaleCreateView from "./views/SaleCreate";
|
|
|
|
import SaleDetailsViewComponent from "./views/SaleDetails";
|
|
|
|
import SaleListViewComponent from "./views/SaleList";
|
|
|
|
import VoucherCreateView from "./views/VoucherCreate";
|
|
|
|
import VoucherDetailsViewComponent from "./views/VoucherDetails";
|
|
|
|
import VoucherListViewComponent from "./views/VoucherList";
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const SaleListView: React.FC<RouteComponentProps<{}>> = ({ 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: SaleListUrlQueryParams = asSortParams(qs, SaleListUrlSortField);
|
2019-06-19 14:40:52 +00:00
|
|
|
return <SaleListViewComponent params={params} />;
|
|
|
|
};
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const SaleDetailsView: React.FC<RouteComponentProps<{ id: string }>> = ({
|
|
|
|
match,
|
|
|
|
location
|
|
|
|
}) => {
|
2019-06-19 14:40:52 +00:00
|
|
|
const { activeTab, ...qs } = parseQs(location.search.substr(1));
|
|
|
|
const params: SaleUrlQueryParams = {
|
|
|
|
...qs,
|
|
|
|
activeTab: saleDetailsPageTab(activeTab)
|
|
|
|
};
|
2019-12-17 17:13:56 +00:00
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
return (
|
|
|
|
<SaleDetailsViewComponent
|
|
|
|
id={decodeURIComponent(match.params.id)}
|
|
|
|
params={params}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const VoucherListView: React.FC<RouteComponentProps<{}>> = ({ 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: VoucherListUrlQueryParams = asSortParams(
|
|
|
|
qs,
|
|
|
|
VoucherListUrlSortField,
|
|
|
|
VoucherListUrlSortField.code
|
|
|
|
);
|
2019-06-19 14:40:52 +00:00
|
|
|
return <VoucherListViewComponent params={params} />;
|
|
|
|
};
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const VoucherDetailsView: React.FC<RouteComponentProps<{ id: string }>> = ({
|
|
|
|
match,
|
|
|
|
location
|
|
|
|
}) => {
|
2019-06-19 14:40:52 +00:00
|
|
|
const { activeTab, ...qs } = parseQs(location.search.substr(1));
|
|
|
|
const params: VoucherUrlQueryParams = {
|
|
|
|
...qs,
|
|
|
|
activeTab: voucherDetailsPageTab(activeTab)
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<VoucherDetailsViewComponent
|
|
|
|
id={decodeURIComponent(match.params.id)}
|
|
|
|
params={params}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
export const DiscountSection: React.FC<{}> = () => {
|
2019-08-26 13:59:32 +00:00
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<WindowTitle title={intl.formatMessage(sectionNames.vouchers)} />
|
|
|
|
<Switch>
|
|
|
|
<Route exact path={saleListPath} component={SaleListView} />
|
|
|
|
<Route exact path={saleAddPath} component={SaleCreateView} />
|
|
|
|
<Route exact path={voucherAddPath} component={VoucherCreateView} />
|
|
|
|
<Route path={salePath(":id")} component={SaleDetailsView} />
|
|
|
|
<Route exact path={voucherListPath} component={VoucherListView} />
|
|
|
|
<Route path={voucherPath(":id")} component={VoucherDetailsView} />
|
|
|
|
</Switch>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
export default DiscountSection;
|