Skip to content

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

Add transaction states to dialogs in product views

dominik-zeglenfee6a5e70872
diff --git a/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx b/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
index fc61c35122..3bff9fb503 100644
--- a/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductImages/ProductImages.tsx
@@ -1,17 +1,14 @@
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
-import DialogContentText from "@material-ui/core/DialogContentText";
import { withStyles } from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
import AddPhotoIcon from "@material-ui/icons/AddAPhoto";
import * as React from "react";
import { SortableContainer, SortableElement } from "react-sortable-hoc";
-import ActionDialog from "../../../components/ActionDialog";
import CardTitle from "../../../components/CardTitle";
import ImageTile from "../../../components/ImageTile";
-import Toggle from "../../../components/Toggle";
import i18n from "../../../i18n";
import { ProductDetails_product_images } from "../../types/ProductDetails";
@@ -112,13 +109,15 @@ const decorate = withStyles(theme => ({
}
}));
-const SortableImage = SortableElement(({ image, onImageEdit, toggle }) => (
- <ImageTile
- image={image}
- onImageEdit={onImageEdit ? () => onImageEdit(image.id) : undefined}
- onImageDelete={toggle}
- />
-));
+const SortableImage = SortableElement(
+ ({ image, onImageEdit, onImageDelete }) => (
+ <ImageTile
+ image={image}
+ onImageEdit={onImageEdit ? () => onImageEdit(image.id) : undefined}
+ onImageDelete={onImageDelete}
+ />
+ )
+);
const ImageListContainer = SortableContainer(
decorate<ImageListContainerProps>(
@@ -126,33 +125,13 @@ const ImageListContainer = SortableContainer(
return (
<div {...props}>
{items.map((image, index) => (
- <Toggle key={index}>
- {(opened, { toggle }) => (
- <>
- <SortableImage
- key={`item-${index}`}
- index={index}
- image={image}
- onImageEdit={onImageEdit ? onImageEdit(image.id) : null}
- onImageDelete={toggle}
- />
- <ActionDialog
- open={opened}
- onClose={toggle}
- onConfirm={() => {
- onImageDelete(image.id)();
- toggle();
- }}
- variant="delete"
- title={i18n.t("Remove product image")}
- >
- <DialogContentText>
- {i18n.t("Are you sure you want to delete this image?")}
- </DialogContentText>
- </ActionDialog>
- </>
- )}
- </Toggle>
+ <SortableImage
+ key={`item-${index}`}
+ index={index}
+ image={image}
+ onImageEdit={onImageEdit ? onImageEdit(image.id) : null}
+ onImageDelete={onImageDelete(image.id)}
+ />
))}
</div>
);
diff --git a/saleor/static/dashboard-next/products/components/ProductVariantDeleteDialog/ProductVariantDeleteDialog.tsx b/saleor/static/dashboard-next/products/components/ProductVariantDeleteDialog/ProductVariantDeleteDialog.tsx
index 11850b9057..ae417ed56f 100644
--- a/saleor/static/dashboard-next/products/components/ProductVariantDeleteDialog/ProductVariantDeleteDialog.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductVariantDeleteDialog/ProductVariantDeleteDialog.tsx
@@ -7,6 +7,9 @@ import DialogTitle from "@material-ui/core/DialogTitle";
import { withStyles } from "@material-ui/core/styles";
import * as React from "react";
+import ConfirmButton, {
+ ConfirmButtonTransitionState
+} from "../../../components/ConfirmButton/ConfirmButton";
import i18n from "../../../i18n";
const decorate = withStyles(theme => ({
@@ -20,6 +23,7 @@ const decorate = withStyles(theme => ({
}));
export interface ProductVariantDeleteDialogProps {
+ confirmButtonState: ConfirmButtonTransitionState;
open: boolean;
name: string;
onClose?();
@@ -28,7 +32,14 @@ export interface ProductVariantDeleteDialogProps {
const ProductVariantDeleteDialog = decorate<ProductVariantDeleteDialogProps>(
props => {
- const { classes, name, open, onConfirm, onClose } = props;
+ const {
+ classes,
+ confirmButtonState,
+ name,
+ open,
+ onConfirm,
+ onClose
+ } = props;
return (
<Dialog open={open}>
<DialogTitle>
@@ -48,13 +59,14 @@ const ProductVariantDeleteDialog = decorate<ProductVariantDeleteDialogProps>(
<Button onClick={onClose}>
{i18n.t("Cancel", { context: "button" })}
</Button>
- <Button
+ <ConfirmButton
+ transitionState={confirmButtonState}
className={classes.deleteButton}
variant="raised"
onClick={onConfirm}
>
{i18n.t("Delete variant", { context: "button" })}
- </Button>
+ </ConfirmButton>
</DialogActions>
</Dialog>
);
diff --git a/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx b/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx
index 5eb647bbc6..2203e3aacf 100644
--- a/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx
+++ b/saleor/static/dashboard-next/products/containers/ProductUpdateOperations.tsx
@@ -8,7 +8,7 @@ import {
TypedProductImageDeleteMutation,
TypedProductUpdateMutation
} from "../mutations";
-import { ProductDelete } from "../types/ProductDelete";
+import { ProductDelete, ProductDeleteVariables } from "../types/ProductDelete";
import { ProductDetails_product } from "../types/ProductDetails";
import {
ProductImageCreate,
@@ -33,7 +33,10 @@ interface ProductUpdateOperationsProps {
ProductImageCreate,
ProductImageCreateVariables
>;
- deleteProduct: PartialMutationProviderOutput;
+ deleteProduct: PartialMutationProviderOutput<
+ ProductDelete,
+ ProductDeleteVariables
+ >;
deleteProductImage: PartialMutationProviderOutput<
ProductImageDelete,
ProductImageDeleteVariables
diff --git a/saleor/static/dashboard-next/products/views/ProductImage/index.tsx b/saleor/static/dashboard-next/products/views/ProductImage/index.tsx
index 2e88c18ae1..27f14b4a2c 100644
--- a/saleor/static/dashboard-next/products/views/ProductImage/index.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductImage/index.tsx
@@ -54,7 +54,7 @@ export const ProductImage: React.StatelessComponent<ProductImageProps> = ({
>
{(updateImage, updateResult) => (
<TypedProductImageDeleteMutation onCompleted={handleBack}>
- {deleteImage => {
+ {(deleteImage, deleteResult) => {
const handleDelete = () =>
deleteImage({ variables: { id: imageId } });
const handleImageClick = (id: string) => () =>
@@ -79,6 +79,11 @@ export const ProductImage: React.StatelessComponent<ProductImageProps> = ({
() => updateResult.data.productImageUpdate.errors
)
);
+ const deleteTransitionState = getMutationState(
+ deleteResult.called,
+ deleteResult.loading,
+ []
+ );
return (
<>
<ProductImagePage
@@ -113,10 +118,11 @@ export const ProductImage: React.StatelessComponent<ProductImageProps> = ({
context: "modal title"
})}
variant="delete"
+ confirmButtonState={deleteTransitionState}
>
<DialogContentText>
{i18n.t(
- "Are you sure you want o remove this image?",
+ "Are you sure you want to remove this image?",
{
context: "modal content"
}
diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
index 534f380153..6107bf492f 100644
--- a/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductUpdate/index.tsx
@@ -121,6 +121,13 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
() => updateProduct.opts.data.productUpdate.errors
)
);
+ const deleteTransitionState = getMutationState(
+ deleteProduct.opts.called,
+ deleteProduct.opts.loading,
+ maybe(
+ () => deleteProduct.opts.data.productDelete.errors
+ )
+ );
return (
<>
<WindowTitle
@@ -194,6 +201,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
<ActionDialog
open={!!match}
onClose={() => navigate(productUrl(id))}
+ confirmButtonState={deleteTransitionState}
onConfirm={() => deleteProduct.mutate({ id })}
variant="delete"
title={i18n.t("Remove product")}