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:53:22 +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-26 17:53:22 +00:00
|
|
|
import { sectionNames } from "@saleor/intl";
|
2019-12-17 17:13:56 +00:00
|
|
|
import { asSortParams } from "@saleor/utils/sort";
|
2020-01-20 15:12:20 +00:00
|
|
|
import { getArrayQueryParam } from "@saleor/utils/urls";
|
2019-06-19 14:40:52 +00:00
|
|
|
import { WindowTitle } from "../components/WindowTitle";
|
|
|
|
import {
|
|
|
|
productAddPath,
|
|
|
|
productImagePath,
|
|
|
|
ProductImageUrlQueryParams,
|
|
|
|
productListPath,
|
|
|
|
ProductListUrlQueryParams,
|
2019-09-13 14:17:12 +00:00
|
|
|
ProductListUrlSortField,
|
2019-06-19 14:40:52 +00:00
|
|
|
productPath,
|
|
|
|
ProductUrlQueryParams,
|
|
|
|
productVariantAddPath,
|
|
|
|
productVariantEditPath,
|
2020-03-25 13:06:14 +00:00
|
|
|
ProductVariantEditUrlQueryParams,
|
2020-03-27 11:06:11 +00:00
|
|
|
ProductAddUrlQueryParams,
|
|
|
|
ProductVariantAddUrlQueryParams
|
2019-06-19 14:40:52 +00:00
|
|
|
} from "./urls";
|
2020-03-25 13:06:14 +00:00
|
|
|
import ProductCreateComponent from "./views/ProductCreate";
|
2019-06-19 14:40:52 +00:00
|
|
|
import ProductImageComponent from "./views/ProductImage";
|
|
|
|
import ProductListComponent from "./views/ProductList";
|
|
|
|
import ProductUpdateComponent from "./views/ProductUpdate";
|
|
|
|
import ProductVariantComponent from "./views/ProductVariant";
|
|
|
|
import ProductVariantCreateComponent from "./views/ProductVariantCreate";
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const ProductList: 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: ProductListUrlQueryParams = asSortParams(
|
2020-01-20 15:12:20 +00:00
|
|
|
{
|
|
|
|
...qs,
|
|
|
|
categories: getArrayQueryParam(qs.categories),
|
|
|
|
collections: getArrayQueryParam(qs.collections),
|
2020-01-31 13:21:34 +00:00
|
|
|
ids: getArrayQueryParam(qs.ids),
|
2020-01-20 15:12:20 +00:00
|
|
|
productTypes: getArrayQueryParam(qs.productTypes)
|
|
|
|
},
|
2019-12-17 17:13:56 +00:00
|
|
|
ProductListUrlSortField
|
|
|
|
);
|
2019-11-05 16:06:47 +00:00
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
return <ProductListComponent params={params} />;
|
|
|
|
};
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const ProductUpdate: React.FC<RouteComponentProps<any>> = ({ match }) => {
|
2019-06-19 14:40:52 +00:00
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: ProductUrlQueryParams = qs;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ProductUpdateComponent
|
|
|
|
id={decodeURIComponent(match.params.id)}
|
|
|
|
params={params}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const ProductVariant: React.FC<RouteComponentProps<any>> = ({ match }) => {
|
2019-06-19 14:40:52 +00:00
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: ProductVariantEditUrlQueryParams = qs;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ProductVariantComponent
|
|
|
|
variantId={decodeURIComponent(match.params.variantId)}
|
|
|
|
productId={decodeURIComponent(match.params.productId)}
|
|
|
|
params={params}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const ProductImage: React.FC<RouteComponentProps<any>> = ({
|
2019-06-19 14:40:52 +00:00
|
|
|
location,
|
|
|
|
match
|
|
|
|
}) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: ProductImageUrlQueryParams = qs;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ProductImageComponent
|
|
|
|
imageId={decodeURIComponent(match.params.imageId)}
|
|
|
|
productId={decodeURIComponent(match.params.productId)}
|
|
|
|
params={params}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const ProductVariantCreate: React.FC<RouteComponentProps<any>> = ({
|
|
|
|
match
|
2020-03-27 11:06:11 +00:00
|
|
|
}) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: ProductVariantAddUrlQueryParams = qs;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ProductVariantCreateComponent
|
|
|
|
productId={decodeURIComponent(match.params.id)}
|
|
|
|
params={params}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2020-03-25 13:06:14 +00:00
|
|
|
const ProductCreate: React.FC<RouteComponentProps> = ({ location }) => {
|
|
|
|
const qs = parseQs(location.search.substr(1));
|
|
|
|
const params: ProductAddUrlQueryParams = qs;
|
|
|
|
|
|
|
|
return <ProductCreateComponent params={params} />;
|
|
|
|
};
|
|
|
|
|
2019-08-26 17:53:22 +00:00
|
|
|
const Component = () => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<WindowTitle title={intl.formatMessage(sectionNames.products)} />
|
|
|
|
<Switch>
|
|
|
|
<Route exact path={productListPath} component={ProductList} />
|
|
|
|
<Route exact path={productAddPath} component={ProductCreate} />
|
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={productVariantAddPath(":id")}
|
|
|
|
component={ProductVariantCreate}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path={productVariantEditPath(":productId", ":variantId")}
|
|
|
|
component={ProductVariant}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path={productImagePath(":productId", ":imageId")}
|
|
|
|
component={ProductImage}
|
|
|
|
/>
|
|
|
|
<Route path={productPath(":id")} component={ProductUpdate} />
|
|
|
|
</Switch>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
export default Component;
|