Skip to content

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

Add modal transition state in product type views

dominik-zeglen0c6f61c44b73
diff --git a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
index 5f2d04513e..993b738d06 100644
--- a/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
+++ b/saleor/static/dashboard-next/productTypes/components/ProductTypeDetailsPage/ProductTypeDetailsPage.tsx
@@ -1,15 +1,12 @@
-import DialogContentText from "@material-ui/core/DialogContentText";
import { withStyles } from "@material-ui/core/styles";
import * as React from "react";
-import ActionDialog from "../../../components/ActionDialog";
import { ConfirmButtonTransitionState } from "../../../components/ConfirmButton/ConfirmButton";
import Container from "../../../components/Container";
import { ControlledCheckbox } from "../../../components/ControlledCheckbox";
import Form from "../../../components/Form";
import PageHeader from "../../../components/PageHeader";
import SaveButtonBar from "../../../components/SaveButtonBar";
-import Toggle from "../../../components/Toggle";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
import {
@@ -111,100 +108,73 @@ const ProductTypeDetailsPage = decorate<ProductTypeDetailsPageProps>(
weight: maybe(() => productType.weight.value)
};
return (
- <Toggle>
- {(openedDeleteDialog, { toggle: toggleDeleteDialog }) => (
- <>
- <Form errors={errors} initial={formInitialData} onSubmit={onSubmit}>
- {({ change, data, hasChanged, submit }) => (
- <Container width="md">
- <PageHeader title={pageTitle} onBack={onBack} />
- <div className={classes.root}>
- <div>
- <ProductTypeDetails
- data={data}
- disabled={disabled}
- onChange={change}
- />
- <div className={classes.cardContainer}>
- <ProductTypeAttributes
- attributes={maybe(
- () => productType.productAttributes
- )}
- type={AttributeTypeEnum.PRODUCT}
- onAttributeAdd={onAttributeAdd}
- onAttributeDelete={onAttributeDelete}
- onAttributeUpdate={onAttributeUpdate}
- />
- </div>
- <div className={classes.cardContainer}>
- <ControlledCheckbox
- checked={data.hasVariants}
- disabled={disabled}
- label={i18n.t("This product type has variants")}
- name="hasVariants"
- onChange={change}
- />
- </div>
- {data.hasVariants && (
- <div className={classes.cardContainer}>
- <ProductTypeAttributes
- attributes={maybe(
- () => productType.variantAttributes
- )}
- type={AttributeTypeEnum.VARIANT}
- onAttributeAdd={onAttributeAdd}
- onAttributeDelete={onAttributeDelete}
- onAttributeUpdate={onAttributeUpdate}
- />
- </div>
- )}
- </div>
- <div>
- <ProductTypeShipping
- disabled={disabled}
- data={data}
- defaultWeightUnit={defaultWeightUnit}
- onChange={change}
- />
- <div className={classes.cardContainer}>
- <ProductTypeTaxes
- disabled={disabled}
- data={data}
- onChange={change}
- />
- </div>
- </div>
+ <Form errors={errors} initial={formInitialData} onSubmit={onSubmit}>
+ {({ change, data, hasChanged, submit }) => (
+ <Container width="md">
+ <PageHeader title={pageTitle} onBack={onBack} />
+ <div className={classes.root}>
+ <div>
+ <ProductTypeDetails
+ data={data}
+ disabled={disabled}
+ onChange={change}
+ />
+ <div className={classes.cardContainer}>
+ <ProductTypeAttributes
+ attributes={maybe(() => productType.productAttributes)}
+ type={AttributeTypeEnum.PRODUCT}
+ onAttributeAdd={onAttributeAdd}
+ onAttributeDelete={onAttributeDelete}
+ onAttributeUpdate={onAttributeUpdate}
+ />
+ </div>
+ <div className={classes.cardContainer}>
+ <ControlledCheckbox
+ checked={data.hasVariants}
+ disabled={disabled}
+ label={i18n.t("This product type has variants")}
+ name="hasVariants"
+ onChange={change}
+ />
+ </div>
+ {data.hasVariants && (
+ <div className={classes.cardContainer}>
+ <ProductTypeAttributes
+ attributes={maybe(() => productType.variantAttributes)}
+ type={AttributeTypeEnum.VARIANT}
+ onAttributeAdd={onAttributeAdd}
+ onAttributeDelete={onAttributeDelete}
+ onAttributeUpdate={onAttributeUpdate}
+ />
</div>
- <SaveButtonBar
- onCancel={onBack}
- onDelete={toggleDeleteDialog}
- onSave={submit}
- disabled={disabled || !hasChanged}
- state={saveButtonBarState}
+ )}
+ </div>
+ <div>
+ <ProductTypeShipping
+ disabled={disabled}
+ data={data}
+ defaultWeightUnit={defaultWeightUnit}
+ onChange={change}
+ />
+ <div className={classes.cardContainer}>
+ <ProductTypeTaxes
+ disabled={disabled}
+ data={data}
+ onChange={change}
/>
- </Container>
- )}
- </Form>
-
- <ActionDialog
- open={openedDeleteDialog}
- onClose={toggleDeleteDialog}
- onConfirm={onDelete}
- title={i18n.t("Remove product type")}
- variant="delete"
- >
- <DialogContentText
- dangerouslySetInnerHTML={{
- __html: i18n.t(
- "Are you sure you want to remove <strong>{{ name }}</strong>?",
- { name: maybe(() => productType.name) }
- )
- }}
- />
- </ActionDialog>
- </>
+ </div>
+ </div>
+ </div>
+ <SaveButtonBar
+ onCancel={onBack}
+ onDelete={onDelete}
+ onSave={submit}
+ disabled={disabled || !hasChanged}
+ state={saveButtonBarState}
+ />
+ </Container>
)}
- </Toggle>
+ </Form>
);
}
);
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
index 2b8863e665..646a7d3586 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/index.tsx
@@ -1,11 +1,13 @@
+import DialogContentText from "@material-ui/core/DialogContentText";
import * as React from "react";
import { Route } from "react-router-dom";
+import ActionDialog from "../../../components/ActionDialog";
import Messages from "../../../components/messages";
import Navigator from "../../../components/Navigator";
import { WindowTitle } from "../../../components/WindowTitle";
import i18n from "../../../i18n";
-import { maybe } from "../../../misc";
+import { getMutationState, maybe } from "../../../misc";
import { AttributeTypeEnum } from "../../../types/globalTypes";
import ProductTypeAttributeEditDialog, {
FormData as AttributeForm
@@ -26,7 +28,9 @@ import {
addAttributePath,
addAttributeUrl,
editAttributePath,
- editAttributeUrl
+ editAttributeUrl,
+ productTypeRemovePath,
+ productTypeRemoveUrl
} from "./urls";
interface ProductTypeUpdateProps {
@@ -226,6 +230,15 @@ export const ProductTypeUpdate: React.StatelessComponent<
};
const loading =
updateProductType.opts.loading || dataLoading;
+ const deleteTransactionState = getMutationState(
+ deleteProductType.opts.called,
+ deleteProductType.opts.loading,
+ maybe(
+ () =>
+ deleteProductType.opts.data.productTypeDelete
+ .errors
+ )
+ );
return (
<>
<WindowTitle
@@ -257,7 +270,9 @@ export const ProductTypeUpdate: React.StatelessComponent<
)
}
onBack={() => navigate(productTypeListUrl)}
- onDelete={handleProductTypeDelete}
+ onDelete={() =>
+ navigate(productTypeRemoveUrl(id))
+ }
onSubmit={handleProductTypeUpdate}
/>
{!dataLoading && (
@@ -340,6 +355,36 @@ export const ProductTypeUpdate: React.StatelessComponent<
);
}}
</Route>
+ <Route
+ path={productTypeRemovePath(":id")}
+ render={({ match }) => (
+ <ActionDialog
+ confirmButtonState={
+ deleteTransactionState
+ }
+ open={!!match}
+ onClose={() =>
+ navigate(productTypeUrl(id))
+ }
+ onConfirm={handleProductTypeDelete}
+ title={i18n.t("Remove product type")}
+ variant="delete"
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={{
+ __html: i18n.t(
+ "Are you sure you want to remove <strong>{{ name }}</strong>?",
+ {
+ name: maybe(
+ () => data.productType.name
+ )
+ }
+ )
+ }}
+ />
+ </ActionDialog>
+ )}
+ />
</>
)}
</>
diff --git a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts
index a1ff7a1186..8e28c58efa 100644
--- a/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts
+++ b/saleor/static/dashboard-next/productTypes/views/ProductTypeUpdate/urls.ts
@@ -22,3 +22,7 @@ export const editAttributeUrl = (productTypeId: string, attributeId: string) =>
encodeURIComponent(productTypeId),
encodeURIComponent(attributeId)
);
+export const productTypeRemovePath = (id: string) =>
+ urlJoin(productTypePath(id), "remove");
+export const productTypeRemoveUrl = (id: string) =>
+ productTypeRemovePath(encodeURIComponent(id));