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-29 10:55:56 +00:00
|
|
|
import { useIntl } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { Route, RouteComponentProps, Switch } from "react-router-dom";
|
2019-08-29 10:55:56 +00:00
|
|
|
|
|
|
|
import { sectionNames } from "@saleor/intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { WindowTitle } from "../components/WindowTitle";
|
|
|
|
import {
|
|
|
|
categoryAddPath,
|
|
|
|
categoryListPath,
|
|
|
|
CategoryListUrlQueryParams,
|
|
|
|
categoryPath,
|
|
|
|
CategoryUrlQueryParams
|
|
|
|
} from "./urls";
|
|
|
|
import { CategoryCreateView } from "./views/CategoryCreate";
|
|
|
|
import CategoryDetailsView, { getActiveTab } from "./views/CategoryDetails";
|
|
|
|
import CategoryListComponent from "./views/CategoryList";
|
|
|
|
|
|
|
|
interface CategoryDetailsRouteParams {
|
|
|
|
id: string;
|
|
|
|
}
|
2019-11-07 11:34:54 +00:00
|
|
|
const CategoryDetails: React.FC<
|
2019-06-19 14:40:52 +00:00
|
|
|
RouteComponentProps<CategoryDetailsRouteParams>
|
|
|
|
> = ({ location, match }) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: CategoryUrlQueryParams = {
|
|
|
|
...qs,
|
|
|
|
activeTab: getActiveTab(qs.activeTab)
|
|
|
|
};
|
|
|
|
return (
|
|
|
|
<CategoryDetailsView
|
|
|
|
id={decodeURIComponent(match.params.id)}
|
|
|
|
params={params}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
interface CategoryCreateRouteParams {
|
|
|
|
id: string;
|
|
|
|
}
|
2019-11-07 11:34:54 +00:00
|
|
|
const CategoryCreate: React.FC<
|
2019-06-19 14:40:52 +00:00
|
|
|
RouteComponentProps<CategoryCreateRouteParams>
|
2019-12-02 10:49:14 +00:00
|
|
|
> = ({ match }) => (
|
|
|
|
<CategoryCreateView
|
|
|
|
parentId={match.params.id ? decodeURIComponent(match.params.id) : undefined}
|
|
|
|
/>
|
|
|
|
);
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const CategoryList: React.FC<RouteComponentProps<{}>> = ({ location }) => {
|
2019-06-19 14:40:52 +00:00
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: CategoryListUrlQueryParams = qs;
|
|
|
|
return <CategoryListComponent params={params} />;
|
|
|
|
};
|
|
|
|
|
2019-08-29 10:55:56 +00:00
|
|
|
const Component = () => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<WindowTitle title={intl.formatMessage(sectionNames.categories)} />
|
|
|
|
<Switch>
|
|
|
|
<Route exact path={categoryListPath} component={CategoryList} />
|
|
|
|
<Route exact path={categoryAddPath()} component={CategoryCreate} />
|
|
|
|
<Route exact path={categoryAddPath(":id")} component={CategoryCreate} />
|
|
|
|
<Route path={categoryPath(":id")} component={CategoryDetails} />
|
|
|
|
</Switch>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
export default Component;
|