Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add sale catalogue unassigning actions

dominik-zeglend9ee5fd20b66
diff --git a/saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsx b/saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsx
index 16bb2f847e..fd3d9abe49 100644
--- a/saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsx
+++ b/saleor/static/dashboard-next/discounts/components/DiscountCategories/DiscountCategories.tsx
@@ -1,5 +1,6 @@
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
+import Checkbox from "@material-ui/core/Checkbox";
import IconButton from "@material-ui/core/IconButton";
import {
createStyles,
@@ -11,21 +12,21 @@ import Table from "@material-ui/core/Table";
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
import TableFooter from "@material-ui/core/TableFooter";
-import TableHead from "@material-ui/core/TableHead";
import TableRow from "@material-ui/core/TableRow";
import DeleteIcon from "@material-ui/icons/Delete";
import * as React from "react";
import CardTitle from "../../../components/CardTitle";
import Skeleton from "../../../components/Skeleton";
+import TableHead from "../../../components/TableHead";
import TablePagination from "../../../components/TablePagination";
import i18n from "../../../i18n";
import { maybe, renderCollection } from "../../../misc";
-import { ListProps } from "../../../types";
+import { ListActions, ListProps } from "../../../types";
import { SaleDetails_sale } from "../../types/SaleDetails";
import { VoucherDetails_voucher } from "../../types/VoucherDetails";
-export interface DiscountCategoriesProps extends ListProps {
+export interface DiscountCategoriesProps extends ListProps, ListActions {
discount: SaleDetails_sale | VoucherDetails_voucher;
onCategoryAssign: () => void;
onCategoryUnassign: (id: string) => void;
@@ -61,7 +62,11 @@ const DiscountCategories = withStyles(styles, {
onCategoryUnassign,
onRowClick,
onPreviousPage,
- onNextPage
+ onNextPage,
+ toolbar,
+ toggle,
+ selected,
+ isChecked
}: DiscountCategoriesProps & WithStyles<typeof styles>) => (
<Card>
<CardTitle
@@ -75,8 +80,9 @@ const DiscountCategories = withStyles(styles, {
}
/>
<Table>
- <TableHead>
+ <TableHead selected={selected} toolbar={toolbar}>
<TableRow>
+ <TableCell />
<TableCell className={classes.wideColumn}>
{i18n.t("Category name")}
</TableCell>
@@ -89,7 +95,7 @@ const DiscountCategories = withStyles(styles, {
<TableFooter>
<TableRow>
<TablePagination
- colSpan={3}
+ colSpan={4}
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
onNextPage={onNextPage}
hasPreviousPage={
@@ -102,38 +108,54 @@ const DiscountCategories = withStyles(styles, {
<TableBody>
{renderCollection(
maybe(() => sale.categories.edges.map(edge => edge.node)),
- category => (
- <TableRow
- hover={!!category}
- key={category ? category.id : "skeleton"}
- onClick={category && onRowClick(category.id)}
- className={classes.tableRow}
- >
- <TableCell>
- {maybe<React.ReactNode>(() => category.name, <Skeleton />)}
- </TableCell>
- <TableCell className={classes.textRight}>
- {maybe<React.ReactNode>(
- () => category.products.totalCount,
- <Skeleton />
- )}
- </TableCell>
- <TableCell className={classes.iconCell}>
- <IconButton
- disabled={!category || disabled}
- onClick={event => {
- event.stopPropagation();
- onCategoryUnassign(category.id);
- }}
- >
- <DeleteIcon color="primary" />
- </IconButton>
- </TableCell>
- </TableRow>
- ),
+ category => {
+ const isSelected = category ? isChecked(category.id) : false;
+
+ return (
+ <TableRow
+ hover={!!category}
+ key={category ? category.id : "skeleton"}
+ onClick={category && onRowClick(category.id)}
+ className={classes.tableRow}
+ selected={isSelected}
+ >
+ <TableCell padding="checkbox">
+ <Checkbox
+ color="primary"
+ checked={isSelected}
+ disabled={disabled}
+ onClick={event => {
+ toggle(category.id);
+ event.stopPropagation();
+ }}
+ />
+ </TableCell>
+ <TableCell>
+ {maybe<React.ReactNode>(() => category.name, <Skeleton />)}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {maybe<React.ReactNode>(
+ () => category.products.totalCount,
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.iconCell}>
+ <IconButton
+ disabled={!category || disabled}
+ onClick={event => {
+ event.stopPropagation();
+ onCategoryUnassign(category.id);
+ }}
+ >
+ <DeleteIcon color="primary" />
+ </IconButton>
+ </TableCell>
+ </TableRow>
+ );
+ },
() => (
<TableRow>
- <TableCell colSpan={3}>
+ <TableCell colSpan={4}>
{i18n.t("No categories found")}
</TableCell>
</TableRow>
diff --git a/saleor/static/dashboard-next/discounts/components/DiscountCollections/DiscountCollections.tsx b/saleor/static/dashboard-next/discounts/components/DiscountCollections/DiscountCollections.tsx
index 81a718b6c3..e71591fb2d 100644
--- a/saleor/static/dashboard-next/discounts/components/DiscountCollections/DiscountCollections.tsx
+++ b/saleor/static/dashboard-next/discounts/components/DiscountCollections/DiscountCollections.tsx
@@ -1,5 +1,6 @@
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
+import Checkbox from "@material-ui/core/Checkbox";
import IconButton from "@material-ui/core/IconButton";
import {
createStyles,
@@ -11,7 +12,6 @@ import Table from "@material-ui/core/Table";
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
import TableFooter from "@material-ui/core/TableFooter";
-import TableHead from "@material-ui/core/TableHead";
import TableRow from "@material-ui/core/TableRow";
import DeleteIcon from "@material-ui/icons/Delete";
import * as React from "react";
@@ -21,11 +21,12 @@ import Skeleton from "../../../components/Skeleton";
import TablePagination from "../../../components/TablePagination";
import i18n from "../../../i18n";
import { maybe, renderCollection } from "../../../misc";
-import { ListProps } from "../../../types";
+import { ListActions, ListProps } from "../../../types";
import { SaleDetails_sale } from "../../types/SaleDetails";
import { VoucherDetails_voucher } from "../../types/VoucherDetails";
+import TableHead from "../../../components/TableHead";
-export interface DiscountCollectionsProps extends ListProps {
+export interface DiscountCollectionsProps extends ListProps, ListActions {
discount: SaleDetails_sale | VoucherDetails_voucher;
onCollectionAssign: () => void;
onCollectionUnassign: (id: string) => void;
@@ -61,7 +62,11 @@ const DiscountCollections = withStyles(styles, {
onCollectionUnassign,
onRowClick,
onPreviousPage,
- onNextPage
+ onNextPage,
+ isChecked,
+ selected,
+ toggle,
+ toolbar
}: DiscountCollectionsProps & WithStyles<typeof styles>) => (
<Card>
<CardTitle
@@ -75,8 +80,9 @@ const DiscountCollections = withStyles(styles, {
}
/>
<Table>
- <TableHead>
+ <TableHead selected={selected} toolbar={toolbar}>
<TableRow>
+ <TableCell />
<TableCell className={classes.wideColumn}>
{i18n.t("Collection name")}
</TableCell>
@@ -89,7 +95,7 @@ const DiscountCollections = withStyles(styles, {
<TableFooter>
<TableRow>
<TablePagination
- colSpan={3}
+ colSpan={4}
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
onNextPage={onNextPage}
hasPreviousPage={
@@ -102,38 +108,56 @@ const DiscountCollections = withStyles(styles, {
<TableBody>
{renderCollection(
maybe(() => sale.collections.edges.map(edge => edge.node)),
- collection => (
- <TableRow
- hover={!!collection}
- key={collection ? collection.id : "skeleton"}
- onClick={collection && onRowClick(collection.id)}
- className={classes.tableRow}
- >
- <TableCell>
- {maybe<React.ReactNode>(() => collection.name, <Skeleton />)}
- </TableCell>
- <TableCell className={classes.textRight}>
- {maybe<React.ReactNode>(
- () => collection.products.totalCount,
- <Skeleton />
- )}
- </TableCell>
- <TableCell className={classes.iconCell}>
- <IconButton
- disabled={!collection || disabled}
- onClick={event => {
- event.stopPropagation();
- onCollectionUnassign(collection.id);
- }}
- >
- <DeleteIcon color="primary" />
- </IconButton>
- </TableCell>
- </TableRow>
- ),
+ collection => {
+ const isSelected = collection ? isChecked(collection.id) : false;
+ return (
+ <TableRow
+ selected={isSelected}
+ hover={!!collection}
+ key={collection ? collection.id : "skeleton"}
+ onClick={collection && onRowClick(collection.id)}
+ className={classes.tableRow}
+ >
+ <TableCell padding="checkbox">
+ <Checkbox
+ color="primary"
+ checked={isSelected}
+ disabled={disabled}
+ onClick={event => {
+ toggle(collection.id);
+ event.stopPropagation();
+ }}
+ />
+ </TableCell>
+ <TableCell>
+ {maybe<React.ReactNode>(
+ () => collection.name,
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {maybe<React.ReactNode>(
+ () => collection.products.totalCount,
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.iconCell}>
+ <IconButton
+ disabled={!collection || disabled}
+ onClick={event => {
+ event.stopPropagation();
+ onCollectionUnassign(collection.id);
+ }}
+ >
+ <DeleteIcon color="primary" />
+ </IconButton>
+ </TableCell>
+ </TableRow>
+ );
+ },
() => (
<TableRow>
- <TableCell colSpan={3}>
+ <TableCell colSpan={4}>
{i18n.t("No collections found")}
</TableCell>
</TableRow>
diff --git a/saleor/static/dashboard-next/discounts/components/DiscountProducts/DiscountProducts.tsx b/saleor/static/dashboard-next/discounts/components/DiscountProducts/DiscountProducts.tsx
index e64b9af9fc..a3b3df68f3 100644
--- a/saleor/static/dashboard-next/discounts/components/DiscountProducts/DiscountProducts.tsx
+++ b/saleor/static/dashboard-next/discounts/components/DiscountProducts/DiscountProducts.tsx
@@ -1,5 +1,6 @@
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
+import Checkbox from "@material-ui/core/Checkbox";
import IconButton from "@material-ui/core/IconButton";
import {
createStyles,
@@ -11,7 +12,6 @@ import Table from "@material-ui/core/Table";
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
import TableFooter from "@material-ui/core/TableFooter";
-import TableHead from "@material-ui/core/TableHead";
import TableRow from "@material-ui/core/TableRow";
import DeleteIcon from "@material-ui/icons/Delete";
import * as React from "react";
@@ -20,14 +20,15 @@ import CardTitle from "../../../components/CardTitle";
import Skeleton from "../../../components/Skeleton";
import StatusLabel from "../../../components/StatusLabel";
import TableCellAvatar from "../../../components/TableCellAvatar";
+import TableHead from "../../../components/TableHead";
import TablePagination from "../../../components/TablePagination";
import i18n from "../../../i18n";
import { maybe, renderCollection } from "../../../misc";
-import { ListProps } from "../../../types";
+import { ListActions, ListProps } from "../../../types";
import { SaleDetails_sale } from "../../types/SaleDetails";
import { VoucherDetails_voucher } from "../../types/VoucherDetails";
-export interface SaleProductsProps extends ListProps {
+export interface SaleProductsProps extends ListProps, ListActions {
discount: SaleDetails_sale | VoucherDetails_voucher;
onProductAssign: () => void;
onProductUnassign: (id: string) => void;
@@ -63,7 +64,11 @@ const DiscountProducts = withStyles(styles, {
onPreviousPage,
onProductAssign,
onProductUnassign,
- onNextPage
+ onNextPage,
+ isChecked,
+ selected,
+ toggle,
+ toolbar
}: SaleProductsProps & WithStyles<typeof styles>) => (
<Card>
<CardTitle
@@ -77,8 +82,9 @@ const DiscountProducts = withStyles(styles, {
}
/>
<Table>
- <TableHead>
+ <TableHead selected={selected} toolbar={toolbar}>
<TableRow>
+ <TableCell />
<TableCell />
<TableCell className={classes.wideColumn}>
{i18n.t("Product name")}
@@ -95,7 +101,7 @@ const DiscountProducts = withStyles(styles, {
<TableFooter>
<TableRow>
<TablePagination
- colSpan={5}
+ colSpan={6}
hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
onNextPage={onNextPage}
hasPreviousPage={
@@ -108,57 +114,72 @@ const DiscountProducts = withStyles(styles, {
<TableBody>
{renderCollection(
maybe(() => sale.products.edges.map(edge => edge.node)),
- product => (
- <TableRow
- hover={!!product}
- key={product ? product.id : "skeleton"}
- onClick={product && onRowClick(product.id)}
- className={classes.tableRow}
- >
- <TableCellAvatar
- thumbnail={maybe(() => product.thumbnail.url)}
- />
- <TableCell>
- {maybe<React.ReactNode>(() => product.name, <Skeleton />)}
- </TableCell>
- <TableCell className={classes.textRight}>
- {maybe<React.ReactNode>(
- () => product.productType.name,
- <Skeleton />
- )}
- </TableCell>
- <TableCell className={classes.textRight}>
- {product && product.isPublished !== undefined ? (
- <StatusLabel
- label={
- product.isPublished
- ? i18n.t("Published", { context: "product status" })
- : i18n.t("Not published", {
- context: "product status"
- })
- }
- status={product.isPublished ? "success" : "error"}
+ product => {
+ const isSelected = product ? isChecked(product.id) : false;
+ return (
+ <TableRow
+ hover={!!product}
+ key={product ? product.id : "skeleton"}
+ onClick={product && onRowClick(product.id)}
+ className={classes.tableRow}
+ selected={isSelected}
+ >
+ <TableCell padding="checkbox">
+ <Checkbox
+ color="primary"
+ checked={isSelected}
+ disabled={disabled}
+ onClick={event => {
+ toggle(product.id);
+ event.stopPropagation();
+ }}
/>
- ) : (
- <Skeleton />
- )}
- </TableCell>
- <TableCell className={classes.iconCell}>
- <IconButton
- disabled={!product || disabled}
- onClick={event => {
- event.stopPropagation();
- onProductUnassign(product.id);
- }}
- >
- <DeleteIcon color="primary" />
- </IconButton>
- </TableCell>
- </TableRow>
- ),
+ </TableCell>
+ <TableCellAvatar
+ thumbnail={maybe(() => product.thumbnail.url)}
+ />
+ <TableCell>
+ {maybe<React.ReactNode>(() => product.name, <Skeleton />)}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {maybe<React.ReactNode>(
+ () => product.productType.name,
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {product && product.isPublished !== undefined ? (
+ <StatusLabel
+ label={
+ product.isPublished
+ ? i18n.t("Published", { context: "product status" })
+ : i18n.t("Not published", {
+ context: "product status"
+ })
+ }
+ status={product.isPublished ? "success" : "error"}
+ />
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.iconCell}>
+ <IconButton
+ disabled={!product || disabled}
+ onClick={event => {
+ event.stopPropagation();
+ onProductUnassign(product.id);
+ }}
+ >
+ <DeleteIcon color="primary" />
+ </IconButton>
+ </TableCell>
+ </TableRow>
+ );
+ },
() => (
<TableRow>
- <TableCell colSpan={5}>{i18n.t("No products found")}</TableCell>
+ <TableCell colSpan={6}>{i18n.t("No products found")}</TableCell>
</TableRow>
)
)}
diff --git a/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx b/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx
index 0ea7a93be6..64a0b43113 100644
--- a/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx
+++ b/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx
@@ -12,7 +12,7 @@ import { Tab } from "../../../components/Tab";
import TabContainer from "../../../components/Tab/TabContainer";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
-import { ListProps, UserError } from "../../../types";
+import { ListProps, TabListActions, UserError } from "../../../types";
import { SaleType } from "../../../types/globalTypes";
import { SaleDetails_sale } from "../../types/SaleDetails";
import DiscountCategories from "../DiscountCategories";
@@ -44,7 +44,10 @@ export function saleDetailsPageTab(tab: string): SaleDetailsPageTab {
}
export interface SaleDetailsPageProps
- extends Pick<ListProps, Exclude<keyof ListProps, "onRowClick">> {
+ extends Pick<ListProps, Exclude<keyof ListProps, "onRowClick">>,
+ TabListActions<
+ "categoryListToolbar" | "collectionListToolbar" | "productListToolbar"
+ > {
activeTab: SaleDetailsPageTab;
defaultCurrency: string;
errors: UserError[];
@@ -91,7 +94,13 @@ const SaleDetailsPage: React.StatelessComponent<SaleDetailsPageProps> = ({
onPreviousPage,
onProductAssign,
onProductUnassign,
- onProductClick
+ onProductClick,
+ categoryListToolbar,
+ collectionListToolbar,
+ productListToolbar,
+ isChecked,
+ selected,
+ toggle
}) => {
const initialForm: FormData = {
endDate: maybe(() => (sale.endDate ? sale.endDate : ""), ""),
@@ -169,6 +178,10 @@ const SaleDetailsPage: React.StatelessComponent<SaleDetailsPageProps> = ({
onRowClick={onCategoryClick}
pageInfo={pageInfo}
discount={sale}
+ isChecked={isChecked}
+ selected={selected}
+ toggle={toggle}
+ toolbar={categoryListToolbar}
/>
) : activeTab === SaleDetailsPageTab.collections ? (
<DiscountCollections
@@ -180,6 +193,10 @@ const SaleDetailsPage: React.StatelessComponent<SaleDetailsPageProps> = ({
onRowClick={onCollectionClick}
pageInfo={pageInfo}
discount={sale}
+ isChecked={isChecked}
+ selected={selected}
+ toggle={toggle}
+ toolbar={collectionListToolbar}
/>
) : (
<DiscountProducts
@@ -191,6 +208,10 @@ const SaleDetailsPage: React.StatelessComponent<SaleDetailsPageProps> = ({
onRowClick={onProductClick}
pageInfo={pageInfo}
discount={sale}
+ isChecked={isChecked}
+ selected={selected}
+ toggle={toggle}
+ toolbar={productListToolbar}
/>
)}
</div>
diff --git a/saleor/static/dashboard-next/discounts/urls.ts b/saleor/static/dashboard-next/discounts/urls.ts
index 353c86a5d8..e737fd469d 100644
--- a/saleor/static/dashboard-next/discounts/urls.ts
+++ b/saleor/static/dashboard-next/discounts/urls.ts
@@ -1,7 +1,7 @@
import { stringify as stringifyQs } from "qs";
import * as urlJoin from "url-join";
-import { ActiveTab, Dialog, Pagination } from "../types";
+import { ActiveTab, BulkAction, Dialog, Pagination } from "../types";
import { SaleDetailsPageTab } from "./components/SaleDetailsPage";
import { VoucherDetailsPageTab } from "./components/VoucherDetailsPage";
@@ -15,8 +15,12 @@ export type SaleUrlDialog =
| "assign-category"
| "assign-collection"
| "assign-product"
+ | "unassign-category"
+ | "unassign-collection"
+ | "unassign-product"
| "remove";
export type SaleUrlQueryParams = Pagination &
+ BulkAction &
Dialog<SaleUrlDialog> &
ActiveTab<SaleDetailsPageTab>;
export const saleUrl = (id: string, params?: SaleUrlQueryParams) =>
@@ -33,8 +37,12 @@ export type VoucherUrlDialog =
| "assign-collection"
| "assign-country"
| "assign-product"
+ | "unassign-category"
+ | "unassign-collection"
+ | "unassign-product"
| "remove";
export type VoucherUrlQueryParams = Pagination &
+ BulkAction &
Dialog<VoucherUrlDialog> &
ActiveTab<VoucherDetailsPageTab>;
export const voucherUrl = (id: string, params?: VoucherUrlQueryParams) =>
diff --git a/saleor/static/dashboard-next/discounts/views/SaleDetails.tsx b/saleor/static/dashboard-next/discounts/views/SaleDetails.tsx
index d0b9c7e447..efc9422b78 100644
--- a/saleor/static/dashboard-next/discounts/views/SaleDetails.tsx
+++ b/saleor/static/dashboard-next/discounts/views/SaleDetails.tsx
@@ -1,3 +1,4 @@
+import Button from "@material-ui/core/Button";
import DialogContentText from "@material-ui/core/DialogContentText";
import * as React from "react";
@@ -12,6 +13,7 @@ import { WindowTitle } from "../../components/WindowTitle";
import { SearchCategoriesProvider } from "../../containers/SearchCategories";
import { SearchCollectionsProvider } from "../../containers/SearchCollections";
import { SearchProductsProvider } from "../../containers/SearchProducts";
+import useBulkActions from "../../hooks/useBulkActions";
import useNavigator from "../../hooks/useNavigator";
import useNotifier from "../../hooks/useNotifier";
import usePaginator from "../../hooks/usePaginator";
@@ -31,6 +33,7 @@ import {
} from "../mutations";
import { TypedSaleDetails } from "../queries";
import { SaleCataloguesAdd } from "../types/SaleCataloguesAdd";
+import { SaleCataloguesRemove } from "../types/SaleCataloguesRemove";
import { SaleDelete } from "../types/SaleDelete";
import { SaleUpdate } from "../types/SaleUpdate";
import {
@@ -61,19 +64,16 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({
const paginate = usePaginator();
const notify = useNotifier();
const shop = useShop();
+ const { isSelected, listElements, reset, toggle } = useBulkActions();
const paginationState = createPaginationState(PAGINATE_BY, params);
- const changeTab = (tab: SaleDetailsPageTab) =>
+ const changeTab = (tab: SaleDetailsPageTab) => {
+ reset();
navigate(
saleUrl(id, {
activeTab: tab
})
);
-
- const handleCatalogueAdd = (data: SaleCataloguesAdd) => {
- if (data.saleCataloguesAdd.errors.length === 0) {
- closeModal();
- }
};
const handleSaleDelete = (data: SaleDelete) => {
@@ -101,21 +101,36 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({
navigate(
saleUrl(id, {
...params,
- action: undefined
+ action: undefined,
+ ids: undefined
}),
true
);
- const openModal = (action: SaleUrlDialog) =>
+ const openModal = (action: SaleUrlDialog, ids?: string[]) =>
navigate(
saleUrl(id, {
...params,
- action
+ action,
+ ids
})
);
+ const handleCatalogueAdd = (data: SaleCataloguesAdd) => {
+ if (data.saleCataloguesAdd.errors.length === 0) {
+ closeModal();
+ }
+ };
+
+ const handleCatalogueRemove = (data: SaleCataloguesRemove) => {
+ if (data.saleCataloguesRemove.errors.length === 0) {
+ closeModal();
+ reset();
+ }
+ };
+
return (
- <TypedSaleCataloguesRemove>
+ <TypedSaleCataloguesRemove onCompleted={handleCatalogueRemove}>
{(saleCataloguesRemove, saleCataloguesRemoveOpts) => (
<TypedSaleCataloguesAdd onCompleted={handleCatalogueAdd}>
{(saleCataloguesAdd, saleCataloguesAddOpts) => (
@@ -149,12 +164,54 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({
.errors
)
);
+ const unassignTransitionState = getMutationState(
+ saleCataloguesRemoveOpts.called,
+ saleCataloguesRemoveOpts.loading,
+ maybe(
+ () =>
+ saleCataloguesRemoveOpts.data.saleCataloguesRemove
+ .errors
+ )
+ );
const removeTransitionState = getMutationState(
saleDeleteOpts.called,
saleDeleteOpts.loading,
maybe(() => saleDeleteOpts.data.saleDelete.errors)
);
+ const handleCategoriesUnassign = (ids: string[]) =>
+ saleCataloguesRemove({
+ variables: {
+ ...paginationState,
+ id,
+ input: {
+ categories: ids
+ }
+ }
+ });
+
+ const handleCollectionsUnassign = (ids: string[]) =>
+ saleCataloguesRemove({
+ variables: {
+ ...paginationState,
+ id,
+ input: {
+ collections: ids
+ }
+ }
+ });
+
+ const handleProductsUnassign = (ids: string[]) =>
+ saleCataloguesRemove({
+ variables: {
+ ...paginationState,
+ id,
+ input: {
+ products: ids
+ }
+ }
+ });
+
const {
loadNextPage,
loadPreviousPage,
@@ -187,26 +244,10 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({
openModal("assign-collection")
}
onCollectionUnassign={collectionId =>
- saleCataloguesRemove({
- variables: {
- ...paginationState,
- id,
- input: {
- collections: [collectionId]
- }
- }
- })
+ handleCollectionsUnassign([collectionId])
}
onCategoryUnassign={categoryId =>
- saleCataloguesRemove({
- variables: {
- ...paginationState,
- id,
- input: {
- categories: [categoryId]
- }
- }
- })
+ handleCategoriesUnassign([categoryId])
}
onCollectionClick={id => () =>
navigate(collectionUrl(id))}
@@ -214,15 +255,7 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({
openModal("assign-product")
}
onProductUnassign={productId =>
- saleCataloguesRemove({
- variables: {
- ...paginationState,
- id,
- input: {
- products: [productId]
- }
- }
- })
+ handleProductsUnassign([productId])
}
onProductClick={id => () =>
navigate(productUrl(id))}
@@ -253,6 +286,42 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({
}
onRemove={() => openModal("remove")}
saveButtonBarState={formTransitionState}
+ categoryListToolbar={
+ <Button
+ color="primary"
+ onClick={() =>
+ openModal("unassign-category", listElements)
+ }
+ >
+ {i18n.t("Unassign")}
+ </Button>
+ }
+ collectionListToolbar={
+ <Button
+ color="primary"
+ onClick={() =>
+ openModal(
+ "unassign-collection",
+ listElements
+ )
+ }
+ >
+ {i18n.t("Unassign")}
+ </Button>
+ }
+ productListToolbar={
+ <Button
+ color="primary"
+ onClick={() =>
+ openModal("unassign-product", listElements)
+ }
+ >
+ {i18n.t("Unassign")}
+ </Button>
+ }
+ isChecked={isSelected}
+ selected={listElements.length}
+ toggle={toggle}
/>
<SearchProductsProvider>
{(searchProducts, searchProductsOpts) => (
@@ -349,6 +418,75 @@ export const SaleDetails: React.StatelessComponent<SaleDetailsProps> = ({
/>
)}
</SearchCollectionsProvider>
+ <ActionDialog
+ open={params.action === "unassign-category"}
+ title={i18n.t("Unassign Categories From Sale")}
+ confirmButtonState={unassignTransitionState}
+ onClose={closeModal}
+ onConfirm={() =>
+ handleCategoriesUnassign(params.ids)
+ }
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to unassign <strong>{{ saleName }}</strong> categories?",
+ {
+ saleName: maybe(
+ () => params.ids.length.toString(),
+ "..."
+ )
+ }
+ )
+ }}
+ />
+ </ActionDialog>
+ <ActionDialog
+ open={params.action === "unassign-collection"}
+ title={i18n.t("Unassign Collections From Sale")}
+ confirmButtonState={unassignTransitionState}
+ onClose={closeModal}
+ onConfirm={() =>
+ handleCollectionsUnassign(params.ids)
+ }
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to unassign <strong>{{ saleName }}</strong> collections?",
+ {
+ saleName: maybe(
+ () => params.ids.length.toString(),
+ "..."
+ )
+ }
+ )
+ }}
+ />
+ </ActionDialog>
+ <ActionDialog
+ open={params.action === "unassign-product"}
+ title={i18n.t("Unassign Products From Sale")}
+ confirmButtonState={unassignTransitionState}
+ onClose={closeModal}
+ onConfirm={() =>
+ handleProductsUnassign(params.ids)
+ }
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to unassign <strong>{{ saleName }}</strong> products?",
+ {
+ saleName: maybe(
+ () => params.ids.length.toString(),
+ "..."
+ )
+ }
+ )
+ }}
+ />
+ </ActionDialog>
<ActionDialog
open={params.action === "remove"}
title={i18n.t("Remove Sale")}