2019-08-09 10:17:04 +00:00
|
|
|
import { parse as parseQs } from "qs";
|
|
|
|
import React from "react";
|
|
|
|
import { Route, RouteComponentProps, Switch } from "react-router-dom";
|
|
|
|
|
2019-08-16 11:47:30 +00:00
|
|
|
import { sectionNames } from "@saleor/intl";
|
|
|
|
import { useIntl } from "react-intl";
|
2019-12-17 17:13:56 +00:00
|
|
|
import { asSortParams } from "@saleor/utils/sort";
|
2019-08-09 10:17:04 +00:00
|
|
|
import { WindowTitle } from "../components/WindowTitle";
|
|
|
|
import {
|
|
|
|
attributeAddPath,
|
|
|
|
AttributeAddUrlQueryParams,
|
|
|
|
attributeListPath,
|
|
|
|
AttributeListUrlQueryParams,
|
|
|
|
attributePath,
|
2019-12-17 17:13:56 +00:00
|
|
|
AttributeUrlQueryParams,
|
|
|
|
AttributeListUrlSortField
|
2019-08-09 10:17:04 +00:00
|
|
|
} from "./urls";
|
|
|
|
import AttributeCreateComponent from "./views/AttributeCreate";
|
|
|
|
import AttributeDetailsComponent from "./views/AttributeDetails";
|
|
|
|
import AttributeListComponent from "./views/AttributeList";
|
|
|
|
|
|
|
|
const AttributeList: React.FC<RouteComponentProps<{}>> = ({ location }) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
2019-12-17 17:13:56 +00:00
|
|
|
const params: AttributeListUrlQueryParams = asSortParams(
|
|
|
|
qs,
|
|
|
|
AttributeListUrlSortField
|
|
|
|
);
|
|
|
|
|
2019-08-09 10:17:04 +00:00
|
|
|
return <AttributeListComponent params={params} />;
|
|
|
|
};
|
|
|
|
|
|
|
|
const AttributeCreate: React.FC<RouteComponentProps<{}>> = ({ location }) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: AttributeAddUrlQueryParams = qs;
|
|
|
|
return <AttributeCreateComponent params={params} />;
|
|
|
|
};
|
|
|
|
|
|
|
|
const AttributeDetails: React.FC<RouteComponentProps<{ id: string }>> = ({
|
|
|
|
location,
|
|
|
|
match
|
|
|
|
}) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: AttributeUrlQueryParams = qs;
|
|
|
|
return (
|
|
|
|
<AttributeDetailsComponent
|
|
|
|
id={decodeURIComponent(match.params.id)}
|
|
|
|
params={params}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-08-16 11:47:30 +00:00
|
|
|
export const AttributeSection: React.FC = () => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<WindowTitle title={intl.formatMessage(sectionNames.attributes)} />
|
|
|
|
<Switch>
|
|
|
|
<Route exact path={attributeListPath} component={AttributeList} />
|
|
|
|
<Route exact path={attributeAddPath} component={AttributeCreate} />
|
|
|
|
<Route path={attributePath(":id")} component={AttributeDetails} />
|
|
|
|
</Switch>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2019-08-09 10:17:04 +00:00
|
|
|
export default AttributeSection;
|