Skip to content

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

Simplify code

dominik-zeglend8544fea9ba3
diff --git a/saleor/static/dashboard-next/auth/AuthProvider.tsx b/saleor/static/dashboard-next/auth/AuthProvider.tsx
index 1320f9cd80..038e6f2fec 100644
--- a/saleor/static/dashboard-next/auth/AuthProvider.tsx
+++ b/saleor/static/dashboard-next/auth/AuthProvider.tsx
@@ -11,10 +11,12 @@ import {
import TokenAuthProvider from "./containers/TokenAuth";
import TokenVerifyProvider from "./containers/TokenVerify";
-const AuthProviderOperations: React.StatelessComponent<any> = ({
- children,
- onError
-}) => {
+interface AuthProviderOperationsProps {
+ onError?: () => void;
+}
+const AuthProviderOperations: React.StatelessComponent<
+ AuthProviderOperationsProps
+> = ({ children, onError }) => {
return (
<TokenAuthProvider onError={onError}>
{tokenAuth => (
diff --git a/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
index 162b317800..b4aae1a2b9 100644
--- a/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
+++ b/saleor/static/dashboard-next/collections/components/CollectionDetailsPage/CollectionDetailsPage.tsx
@@ -1,5 +1,5 @@
-import DialogContentText from "@material-ui/core/DialogContentText";
import Button from "@material-ui/core/Button";
+import DialogContentText from "@material-ui/core/DialogContentText";
import { withStyles } from "@material-ui/core/styles";
import * as React from "react";
diff --git a/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx b/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx
index cb66a5878e..4700db9023 100644
--- a/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx
+++ b/saleor/static/dashboard-next/collections/components/CollectionProducts/CollectionProducts.tsx
@@ -38,15 +38,15 @@ interface CollectionProductsProps {
}
const decorate = withStyles(theme => ({
+ link: {
+ color: theme.palette.secondary.main,
+ cursor: "pointer" as "pointer"
+ },
root: {
marginTop: theme.spacing.unit * 2,
[theme.breakpoints.down("md")]: {
marginTop: theme.spacing.unit
}
- },
- link: {
- color: theme.palette.secondary.main,
- cursor: "pointer" as "pointer"
}
}));
const CollectionProducts = decorate<CollectionProductsProps>(
diff --git a/saleor/static/dashboard-next/components/SaveButtonBar/SaveButtonBar.tsx b/saleor/static/dashboard-next/components/SaveButtonBar/SaveButtonBar.tsx
index 4d186cbb76..011d853e88 100644
--- a/saleor/static/dashboard-next/components/SaveButtonBar/SaveButtonBar.tsx
+++ b/saleor/static/dashboard-next/components/SaveButtonBar/SaveButtonBar.tsx
@@ -26,29 +26,6 @@ interface SaveButtonBarProps {
}
const decorate = withStyles(theme => ({
- cancelButton: {
- marginRight: theme.spacing.unit * 2
- },
- deleteButton: {
- "&:hover": {
- backgroundColor: theme.palette.error.dark
- },
- backgroundColor: theme.palette.error.main,
- color: theme.palette.error.contrastText
- },
- root: {
- borderTop: `1px ${gray[300]} solid`,
- display: "flex",
- marginBottom: theme.spacing.unit * 2,
- marginTop: theme.spacing.unit * 2,
- paddingTop: theme.spacing.unit * 2,
- [theme.breakpoints.down("sm")]: {
- marginTop: theme.spacing.unit
- }
- },
- spacer: {
- flex: "1"
- },
button: {
marginRight: theme.spacing.unit
},
@@ -63,12 +40,15 @@ const decorate = withStyles(theme => ({
marginTop: -theme.spacing.unit * 1.5,
position: "relative" as "relative"
},
- success: {
+ cancelButton: {
+ marginRight: theme.spacing.unit * 2
+ },
+ deleteButton: {
"&:hover": {
- backgroundColor: theme.palette.primary.main
+ backgroundColor: theme.palette.error.dark
},
- backgroundColor: theme.palette.primary.main,
- color: theme.palette.primary.contrastText
+ backgroundColor: theme.palette.error.main,
+ color: theme.palette.error.contrastText
},
error: {
"&:hover": {
@@ -82,6 +62,26 @@ const decorate = withStyles(theme => ({
marginRight: theme.spacing.unit * 0.5,
marginTop: -theme.spacing.unit * 1.5,
position: "relative" as "relative"
+ },
+ root: {
+ borderTop: `1px ${gray[300]} solid`,
+ display: "flex",
+ marginBottom: theme.spacing.unit * 2,
+ marginTop: theme.spacing.unit * 2,
+ paddingTop: theme.spacing.unit * 2,
+ [theme.breakpoints.down("sm")]: {
+ marginTop: theme.spacing.unit
+ }
+ },
+ spacer: {
+ flex: "1"
+ },
+ success: {
+ "&:hover": {
+ backgroundColor: theme.palette.primary.main
+ },
+ backgroundColor: theme.palette.primary.main,
+ color: theme.palette.primary.contrastText
}
}));
export const SaveButtonBar = decorate<SaveButtonBarProps>(
diff --git a/saleor/static/dashboard-next/components/Timeline/Timeline.tsx b/saleor/static/dashboard-next/components/Timeline/Timeline.tsx
index 7ac73a22aa..e373dcff0f 100644
--- a/saleor/static/dashboard-next/components/Timeline/Timeline.tsx
+++ b/saleor/static/dashboard-next/components/Timeline/Timeline.tsx
@@ -19,7 +19,6 @@ import * as React from "react";
import i18n from "../../i18n";
import DateFormatter from "../DateFormatter";
-interface TimelineProps {}
interface TimelineNodeProps {
date: string;
title: string;
@@ -37,92 +36,93 @@ interface TimelineAddNoteProps {
}
const decorate = withStyles(theme => ({
- root: {
- marginLeft: theme.spacing.unit * 5.5,
- paddingLeft: theme.spacing.unit * 3,
- borderStyle: "solid",
- borderWidth: "0 0 0 2px",
- borderColor: grey[300]
- },
avatar: {
alignSelf: "flex-start" as "flex-start",
marginRight: theme.spacing.unit * 5.5
},
cardActions: {
direction: "rtl" as "rtl",
+ display: "block" as "block",
maxHeight: 0,
- transitionDuration: "200ms",
overflow: "hidden" as "hidden",
- display: "block" as "block"
+ transitionDuration: "200ms"
},
cardActionsExpanded: {
maxHeight: theme.spacing.unit * 6
},
+ noExpander: {
+ marginLeft: theme.spacing.unit * 3
+ },
+ noExpanderNodeDate: {
+ position: "absolute" as "absolute",
+ right: theme.spacing.unit * 7
+ },
+ nodeDate: {
+ position: "absolute" as "absolute",
+ right: theme.spacing.unit * 3
+ },
nodeDot: {
- position: "relative" as "relative",
- left: -theme.spacing.unit * 4 - 1,
- width: theme.spacing.unit * 2,
- height: theme.spacing.unit * 2,
backgroundColor: theme.palette.secondary.main,
+ borderColor: grey[300],
borderRadius: "100%",
borderStyle: "solid",
borderWidth: 2,
- borderColor: grey[300]
+ height: theme.spacing.unit * 2,
+ left: -theme.spacing.unit * 4 - 1,
+ position: "relative" as "relative",
+ width: theme.spacing.unit * 2
},
nodeRoot: {
- marginBottom: theme.spacing.unit * 3,
- display: "flex",
- width: "100%",
- position: "relative" as "relative",
- alignItems: "center",
- minHeight: theme.spacing.unit * 8,
"&:last-child:after": {
+ background: theme.palette.background.default,
content: "''",
- position: "absolute" as "absolute",
- width: "2px",
height: `calc(50% - ${theme.spacing.unit}px)`,
- background: theme.palette.background.default,
+ left: `${-theme.spacing.unit * 3 - 2}px`,
+ position: "absolute" as "absolute",
top: `calc(50% + ${theme.spacing.unit}px)`,
- left: `${-theme.spacing.unit * 3 - 2}px`
- }
+ width: "2px"
+ },
+ alignItems: "center",
+ display: "flex",
+ marginBottom: theme.spacing.unit * 3,
+ minHeight: theme.spacing.unit * 8,
+ position: "relative" as "relative",
+ width: "100%"
},
- nodeDate: {
+ noteContent: {
+ paddingLeft: theme.spacing.unit * 10.5
+ },
+ noteDate: {
position: "absolute" as "absolute",
- right: theme.spacing.unit * 3
+ right: theme.spacing.unit * 7
},
noteRoot: {
- position: "relative" as "relative",
left: -theme.spacing.unit * 8.5 - 1,
- width: `calc(100% + ${theme.spacing.unit * 8.5}px)`,
- marginBottom: theme.spacing.unit * 3
+ marginBottom: theme.spacing.unit * 3,
+ position: "relative" as "relative",
+ width: `calc(100% + ${theme.spacing.unit * 8.5}px)`
},
noteTitle: {
- display: "flex" as "flex",
- alignItems: "center" as "center"
+ alignItems: "center" as "center",
+ display: "flex" as "flex"
},
noteUser: {
marginLeft: theme.spacing.unit * 5.5
},
- noteDate: {
- position: "absolute" as "absolute",
- right: theme.spacing.unit * 7
- },
- noteContent: {
- paddingLeft: theme.spacing.unit * 10.5
- },
panel: {
- background: "none",
- width: "100%",
"&:before": {
display: "none"
- }
- },
- noExpander: {
- marginLeft: theme.spacing.unit * 3
+ },
+ background: "none",
+ width: "100%"
},
- noExpanderNodeDate: {
- position: "absolute" as "absolute",
- right: theme.spacing.unit * 7
+
+ root: {
+ borderColor: grey[300],
+ borderStyle: "solid",
+ borderWidth: "0 0 0 2px",
+ marginLeft: theme.spacing.unit * 5.5,
+ paddingLeft: theme.spacing.unit * 3
}
}));
const palette = [
@@ -144,7 +144,7 @@ const palette = [
colors.yellow
].map(color => color[500]);
-export const Timeline = decorate<TimelineProps>(({ classes, children }) => (
+export const Timeline = decorate(({ classes, children }) => (
<div className={classes.root}>{children}</div>
));
export const TimelineNode = decorate<TimelineNodeProps>(
diff --git a/saleor/static/dashboard-next/components/messages/MessageManager.tsx b/saleor/static/dashboard-next/components/messages/MessageManager.tsx
index 33983aa076..bd79b0bf4d 100644
--- a/saleor/static/dashboard-next/components/messages/MessageManager.tsx
+++ b/saleor/static/dashboard-next/components/messages/MessageManager.tsx
@@ -9,18 +9,14 @@ import { IMessage, MessageContext } from "./";
interface Message extends IMessage {
key: string;
}
-interface MessageManagerProps {}
interface MessageManagerState {
message: Message;
opened: boolean;
}
-export class MessageManager extends React.Component<
- MessageManagerProps,
- MessageManagerState
-> {
+export class MessageManager extends React.Component<{}, MessageManagerState> {
state = {
- message: { text: "", key: "0" } as Message,
+ message: { text: "", key: "0", onUndo: undefined },
opened: false
};
queue = [];
@@ -93,7 +89,6 @@ export class MessageManager extends React.Component<
key="close"
aria-label="Close"
color="inherit"
- // className={classes.close}
onClick={this.handleClose as any}
>
<CloseIcon />
diff --git a/saleor/static/dashboard-next/orders/components/OrderAddressEditDialog/OrderAddressEditDialog.tsx b/saleor/static/dashboard-next/orders/components/OrderAddressEditDialog/OrderAddressEditDialog.tsx
index 96fd32068b..1936eda144 100644
--- a/saleor/static/dashboard-next/orders/components/OrderAddressEditDialog/OrderAddressEditDialog.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderAddressEditDialog/OrderAddressEditDialog.tsx
@@ -1,18 +1,13 @@
import Button from "@material-ui/core/Button";
-import Dialog, { DialogProps } from "@material-ui/core/Dialog";
+import Dialog from "@material-ui/core/Dialog";
import DialogActions from "@material-ui/core/DialogActions";
import DialogContent from "@material-ui/core/DialogContent";
import DialogTitle from "@material-ui/core/DialogTitle";
-import { withStyles } from "@material-ui/core/styles";
-import TextField from "@material-ui/core/TextField";
import * as React from "react";
-import FormSpacer from "../../../components/FormSpacer";
-import PhoneField from "../../../components/PhoneField";
-import SingleSelectField from "../../../components/SingleSelectField";
+import AddressEdit from "../../../components/AddressEdit/AddressEdit";
import { AddressType } from "../../../customers/";
import i18n from "../../../i18n";
-import AddressEdit from "../../../components/AddressEdit/AddressEdit";
interface OrderAddressEditDialogProps {
open: boolean;
@@ -28,52 +23,41 @@ interface OrderAddressEditDialogProps {
onConfirm?(event: React.FormEvent<any>);
}
-const decorate = withStyles(
- theme => ({
- root: {
- display: "grid",
- gridColumnGap: `${theme.spacing.unit * 2}px`,
- gridTemplateColumns: "1fr 1fr"
- }
- }),
- { name: "OrderAddressEditDialog" }
-);
-const OrderAddressEditDialog = decorate<OrderAddressEditDialogProps>(
- ({
- children,
- classes,
- open,
- variant,
- countries,
- data,
- prefixes,
- onConfirm,
- onClose,
- onChange
- }) => (
- <Dialog open={open}>
- <DialogTitle>
- {variant === "billing"
- ? i18n.t("Edit billing address", { context: "title" })
- : i18n.t("Edit shipping address", { context: "title" })}
- </DialogTitle>
- <DialogContent>
- <AddressEdit
- countries={countries}
- data={data}
- onChange={onChange}
- prefixes={prefixes}
- />
- </DialogContent>
- <DialogActions>
- <Button onClick={onClose}>
- {i18n.t("Cancel", { context: "button" })}
- </Button>
- <Button color="primary" variant="raised" onClick={onConfirm}>
- {i18n.t("Confirm", { context: "button" })}
- </Button>
- </DialogActions>
- </Dialog>
- )
+const OrderAddressEditDialog: React.StatelessComponent<
+ OrderAddressEditDialogProps
+> = ({
+ open,
+ variant,
+ countries,
+ data,
+ prefixes,
+ onConfirm,
+ onClose,
+ onChange
+}) => (
+ <Dialog open={open}>
+ <DialogTitle>
+ {variant === "billing"
+ ? i18n.t("Edit billing address", { context: "title" })
+ : i18n.t("Edit shipping address", { context: "title" })}
+ </DialogTitle>
+ <DialogContent>
+ <AddressEdit
+ countries={countries}
+ data={data}
+ onChange={onChange}
+ prefixes={prefixes}
+ />
+ </DialogContent>
+ <DialogActions>
+ <Button onClick={onClose}>
+ {i18n.t("Cancel", { context: "button" })}
+ </Button>
+ <Button color="primary" variant="raised" onClick={onConfirm}>
+ {i18n.t("Confirm", { context: "button" })}
+ </Button>
+ </DialogActions>
+ </Dialog>
);
+OrderAddressEditDialog.displayName = "OrderAddressEditDialog";
export default OrderAddressEditDialog;
diff --git a/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx b/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
index 6ecd5209c1..8de35c6e87 100644
--- a/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx
@@ -2,16 +2,13 @@ import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import blue from "@material-ui/core/colors/blue";
-import IconButton from "@material-ui/core/IconButton";
import { withStyles } from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
-import EditIcon from "@material-ui/icons/Edit";
import * as React from "react";
-import PageHeader from "../../../components/PageHeader";
+import CardTitle from "../../../components/CardTitle";
import Skeleton from "../../../components/Skeleton";
import i18n from "../../../i18n";
-import CardTitle from "../../../components/CardTitle";
interface AddressType {
city: string;
@@ -48,11 +45,11 @@ interface OrderCustomerProps {
const decorate = withStyles(
theme => ({
hr: {
- height: 1,
- display: "block",
+ backgroundColor: theme.palette.grey[200],
border: "none",
- width: "100%",
- backgroundColor: theme.palette.grey[200]
+ display: "block",
+ height: 1,
+ width: "100%"
},
link: {
color: blue[500],
diff --git a/saleor/static/dashboard-next/orders/components/OrderFulfillmentDialog/OrderFulfillmentDialog.tsx b/saleor/static/dashboard-next/orders/components/OrderFulfillmentDialog/OrderFulfillmentDialog.tsx
index 89f3aac1b3..656a6f1541 100644
--- a/saleor/static/dashboard-next/orders/components/OrderFulfillmentDialog/OrderFulfillmentDialog.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderFulfillmentDialog/OrderFulfillmentDialog.tsx
@@ -1,6 +1,6 @@
import Avatar from "@material-ui/core/Avatar";
import Button from "@material-ui/core/Button";
-import Dialog, { DialogProps } from "@material-ui/core/Dialog";
+import Dialog from "@material-ui/core/Dialog";
import DialogActions from "@material-ui/core/DialogActions";
import DialogTitle from "@material-ui/core/DialogTitle";
import Input from "@material-ui/core/Input";
@@ -36,13 +36,12 @@ const decorate = withStyles(
paddingRight: theme.spacing.unit * 3,
width: theme.spacing.unit * 5
},
- textRight: {
- textAlign: "right" as "right"
- },
quantityInput: {
width: "4rem"
},
- root: {}
+ textRight: {
+ textAlign: "right" as "right"
+ }
}),
{ name: "OrderFulfillmentDialog" }
);
diff --git a/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx b/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx
index 6cf1d2dcd4..472929a027 100644
--- a/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderProductAddDialog/OrderProductAddDialog.tsx
@@ -1,5 +1,5 @@
import Button from "@material-ui/core/Button";
-import Dialog, { DialogProps } from "@material-ui/core/Dialog";
+import Dialog from "@material-ui/core/Dialog";
import DialogActions from "@material-ui/core/DialogActions";
import DialogContent from "@material-ui/core/DialogContent";
import DialogTitle from "@material-ui/core/DialogTitle";
@@ -36,10 +36,6 @@ const decorate = withStyles(
dialog: {
overflowY: "visible" as "visible"
},
- select: {
- flex: 1,
- marginRight: theme.spacing.unit * 2
- },
root: {
display: "grid" as "grid",
gridColumnGap: theme.spacing.unit * 2 + "px",
@@ -47,6 +43,10 @@ const decorate = withStyles(
overflowY: "visible" as "visible",
width: theme.breakpoints.values.sm
},
+ select: {
+ flex: 1,
+ marginRight: theme.spacing.unit * 2
+ },
textRight: {
textAlign: "right" as "right"
}
diff --git a/saleor/static/dashboard-next/pages/components/PageContent/PageContent.tsx b/saleor/static/dashboard-next/pages/components/PageContent/PageContent.tsx
index 162f5508bd..5407f737db 100644
--- a/saleor/static/dashboard-next/pages/components/PageContent/PageContent.tsx
+++ b/saleor/static/dashboard-next/pages/components/PageContent/PageContent.tsx
@@ -10,7 +10,10 @@ import i18n from "../../../i18n";
interface PageContentProps {
content: string;
- errors?: Array<{ field: string; message: string }>;
+ errors: {
+ content?: string;
+ title?: string;
+ };
loading?: boolean;
title: string;
onChange?(event: React.ChangeEvent<any>);
@@ -24,54 +27,40 @@ const decorate = withStyles(theme => ({
}
}));
const PageContent = decorate<PageContentProps>(
- ({ classes, content, errors, loading, title, onChange }) => {
- const errorList: { [key: string]: string } = errors
- ? errors.reduce((acc, curr) => {
- acc[curr.field] = curr.message;
- return acc;
- }, {})
- : {};
- return (
- <Card>
- <CardContent>
- <TextField
- autoFocus
- disabled={loading}
- name="title"
- label={i18n.t("Title", { context: "object" })}
- value={title}
- onChange={onChange}
- className={
- (errors
- ? !errorList.title
- : true)
- ? classes.addHelperTextPadding
- : ""
- }
- error={!!(errorList && errorList.title)}
- helperText={errorList && errorList.title ? errorList.title : ""}
- fullWidth
- />
- <FormSpacer />
- <RichTextEditor
- disabled={loading}
- value={content}
- name="content"
- label={i18n.t("Content", { context: "object" })}
- helperText={
- errorList && errorList.content
- ? errorList.content
- : i18n.t("Select text to enable text-formatting tools.", {
- context: "object"
- })
- }
- onChange={onChange}
- error={!!(errorList && errorList.content)}
- fullWidth
- />
- </CardContent>
- </Card>
- );
- }
+ ({ classes, content, errors, loading, title, onChange }) => (
+ <Card>
+ <CardContent>
+ <TextField
+ autoFocus
+ disabled={loading}
+ name="title"
+ label={i18n.t("Title", { context: "object" })}
+ value={title}
+ onChange={onChange}
+ className={!errors.title ? classes.addHelperTextPadding : ""}
+ error={!!errors.title}
+ helperText={errors.title ? errors.title : undefined}
+ fullWidth
+ />
+ <FormSpacer />
+ <RichTextEditor
+ disabled={loading}
+ value={content}
+ name="content"
+ label={i18n.t("Content", { context: "object" })}
+ helperText={
+ errors.content
+ ? errors.content
+ : i18n.t("Select text to enable text-formatting tools.", {
+ context: "object"
+ })
+ }
+ onChange={onChange}
+ error={!!errors.content}
+ fullWidth
+ />
+ </CardContent>
+ </Card>
+ )
);
export default PageContent;
diff --git a/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx b/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx
index 3848928eb2..205e6315a8 100644
--- a/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx
+++ b/saleor/static/dashboard-next/pages/components/PageDetailsPage/PageDetailsPage.tsx
@@ -1,5 +1,4 @@
import { withStyles } from "@material-ui/core/styles";
-import DeleteIcon from "@material-ui/icons/Delete";
import * as React from "react";
import { Container } from "../../../components/Container";
@@ -64,11 +63,12 @@ const PageDetailsPage = decorate<PageDetailsPageProps>(
onSubmit
}) => (
<PageForm
+ errors={errors}
key={page ? "ready" : "loading"}
initial={page ? page : defaultPage}
onSubmit={onSubmit}
>
- {({ change, data, hasChanged, submit }) => (
+ {({ change, data, errors, hasChanged, submit }) => (
<Toggle>
{(opened, { toggle: togglePageDeleteDialog }) => (
<Container width="md">
@@ -77,6 +77,7 @@ const PageDetailsPage = decorate<PageDetailsPageProps>(
<div className={classes.root}>
<div>
<PageContent
+ errors={errors}
loading={disabled}
onChange={change}
content={data.content}
diff --git a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
index 8868cdddcb..a34df1e200 100644
--- a/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductUpdatePage/ProductUpdatePage.tsx
@@ -95,7 +95,7 @@ interface ProductUpdateProps {
onImageDelete: (id: string) => () => void;
onAttributesEdit: () => void;
onBack?();
- onDelete?(id: string);
+ onDelete();
onImageEdit?(id: string);
onImageReorder?(event: { oldIndex: number; newIndex: number });
onImageUpload?(event: React.ChangeEvent<any>);
@@ -129,8 +129,8 @@ export const ProductUpdate = decorate<ProductUpdateProps>(
({
classes,
disabled,
- categories,
- collections,
+ categories: categoryChoiceList,
+ collections: collectionChoiceList,
errors: userErrors,
images,
header,
@@ -151,56 +151,91 @@ export const ProductUpdate = decorate<ProductUpdateProps>(
onVariantAdd,
onVariantShow
}) => {
- const initialData = {
- attributes:
- product && product.attributes
- ? product.attributes.map(a => ({
- slug: a.attribute.slug,
- value: a.value ? a.value.slug : null
- }))
- : undefined,
- available: product ? product.isPublished : undefined,
- availableOn: product ? product.availableOn : "",
- category: product && product.category ? product.category.id : undefined,
- chargeTaxes: product && product.chargeTaxes ? product.chargeTaxes : false,
- collections:
- product && productCollections
- ? productCollections.map(node => node.id)
- : [],
- description: product ? product.description : "",
- featured: product && product.isFeatured ? product.isFeatured : false,
- name: product ? product.name : "",
- price:
- product && product.price ? product.price.amount.toString() : undefined,
- productType:
- product && product.productType && product.attributes
- ? {
- label: product.productType.name,
- value: {
- hasVariants: product.productType.hasVariants,
- id: product.productType.id,
- name: product.productType.name,
- productAttributes: {
- edges: product.attributes.map(a => ({ node: a.attribute }))
- }
- }
- }
- : undefined,
- seoDescription: product ? product.seoDescription : "",
- seoTitle: product && product.seoTitle ? product.seoTitle : "",
- sku:
- product && product.productType && product.productType.hasVariants
- ? undefined
- : variants && variants[0]
- ? variants[0].sku
- : undefined,
- stockQuantity:
- product && product.productType && product.productType.hasVariants
- ? undefined
- : variants && variants[0]
- ? variants[0].stockQuantity
- : undefined
+ const deleteDialogText = {
+ __html: i18n.t(
+ "Are you sure you want to remove <strong>{{ name }}</strong>?",
+ { name: product ? product.name : undefined }
+ )
};
+ const initialData = product
+ ? {
+ attributes: product.attributes
+ ? product.attributes.map(a => ({
+ slug: a.attribute.slug,
+ value: a.value ? a.value.slug : null
+ }))
+ : undefined,
+ available: product.isPublished,
+ availableOn: product.availableOn,
+ category: product.category ? product.category.id : undefined,
+ chargeTaxes: product.chargeTaxes ? product.chargeTaxes : false,
+ collections: productCollections
+ ? productCollections.map(node => node.id)
+ : [],
+ description: product.description,
+ featured: product.isFeatured,
+ name: product.name,
+ price: product.price ? product.price.amount.toString() : undefined,
+ productType:
+ product.productType && product.attributes
+ ? {
+ label: product.productType.name,
+ value: {
+ hasVariants: product.productType.hasVariants,
+ id: product.productType.id,
+ name: product.productType.name,
+ productAttributes: {
+ edges: product.attributes.map(a => ({
+ node: a.attribute
+ }))
+ }
+ }
+ }
+ : undefined,
+ seoDescription: product.seoDescription,
+ seoTitle: product.seoTitle,
+ sku:
+ product.productType && product.productType.hasVariants
+ ? undefined
+ : variants && variants[0]
+ ? variants[0].sku
+ : undefined,
+ stockQuantity:
+ product.productType && product.productType.hasVariants
+ ? undefined
+ : variants && variants[0]
+ ? variants[0].stockQuantity
+ : undefined
+ }
+ : {
+ availableOn: "",
+ chargeTaxes: false,
+ collections: [],
+ description: "",
+ featured: false,
+ name: "",
+ seoDescription: "",
+ seoTitle: ""
+ };
+ const categories =
+ categoryChoiceList !== undefined
+ ? categoryChoiceList.map(category => ({
+ label: category.name,
+ value: category.id
+ }))
+ : [];
+ const collections =
+ collectionChoiceList !== undefined
+ ? collectionChoiceList.map(collection => ({
+ label: collection.name,
+ value: collection.id
+ }))
+ : [];
+ const currency =
+ product && product.price ? product.price.currency : undefined;
+ const hasVariants =
+ product && product.productType && product.productType.hasVariants;
+
return (
<Toggle>
{(openedDeleteDialog, { toggle: toggleDeleteDialog }) => (
@@ -211,144 +246,113 @@ export const ProductUpdate = decorate<ProductUpdateProps>(
key={product ? JSON.stringify(product) : "loading"}
>
{({ change, data, errors, hasChanged, submit }) => (
- <Container width="md">
- <PageHeader title={header} onBack={onBack} />
- {product &&
- onDelete &&
- product.name && (
- <ActionDialog
- open={openedDeleteDialog}
- onClose={toggleDeleteDialog}
- onConfirm={() => {
- onDelete(product.id);
- toggleDeleteDialog();
- }}
- variant="delete"
- title={i18n.t("Remove product")}
- >
- <DialogContentText
- dangerouslySetInnerHTML={{
- __html: i18n.t(
- "Are you sure you want to remove <strong>{{ name }}</strong>?",
- { name: product.name }
- )
- }}
- />
- </ActionDialog>
- )}
-
- <div className={classes.root}>
- <div>
- <ProductDetailsForm
- data={data}
- disabled={disabled}
- errors={errors}
- onChange={change}
- />
- <div className={classes.cardContainer}>
- <ProductImages
- images={images}
- placeholderImage={placeholderImage}
- onImageDelete={onImageDelete}
- onImageReorder={onImageReorder}
- onImageEdit={onImageEdit}
- onImageUpload={onImageUpload}
- />
- </div>
- <div className={classes.cardContainer}>
- <ProductPricing
- currency={
- product && product.price
- ? product.price.currency
- : undefined
- }
+ <>
+ <Container width="md">
+ <PageHeader title={header} onBack={onBack} />
+ <div className={classes.root}>
+ <div>
+ <ProductDetailsForm
data={data}
disabled={disabled}
+ errors={errors}
onChange={change}
/>
- </div>
- <div className={classes.cardContainer}>
- {product &&
- product.productType &&
- product.productType.hasVariants ? (
- <ProductVariants
- variants={variants}
- fallbackPrice={product ? product.price : undefined}
- onAttributesEdit={onAttributesEdit}
- onRowClick={onVariantShow}
- onVariantAdd={onVariantAdd}
+ <div className={classes.cardContainer}>
+ <ProductImages
+ images={images}
+ placeholderImage={placeholderImage}
+ onImageDelete={onImageDelete}
+ onImageReorder={onImageReorder}
+ onImageEdit={onImageEdit}
+ onImageUpload={onImageUpload}
/>
- ) : (
- <ProductStock
+ </div>
+ <div className={classes.cardContainer}>
+ <ProductPricing
+ currency={currency}
data={data}
disabled={disabled}
onChange={change}
/>
- )}
- </div>
- <div className={classes.cardContainer}>
- <SeoForm
- helperText={i18n.t(
- "Add search engine title and description to make this product easier to find"
+ </div>
+ <div className={classes.cardContainer}>
+ {hasVariants ? (
+ <ProductVariants
+ variants={variants}
+ fallbackPrice={product ? product.price : undefined}
+ onAttributesEdit={onAttributesEdit}
+ onRowClick={onVariantShow}
+ onVariantAdd={onVariantAdd}
+ />
+ ) : (
+ <ProductStock
+ data={data}
+ disabled={disabled}
+ onChange={change}
+ />
)}
- title={data.seoTitle}
- titlePlaceholder={data.name}
- description={data.seoDescription}
- descriptionPlaceholder={data.description}
- storefrontUrl={product ? product.url : undefined}
- loading={disabled}
- onClick={onSeoClick}
- onChange={change}
- />
+ </div>
+ <div className={classes.cardContainer}>
+ <SeoForm
+ helperText={i18n.t(
+ "Add search engine title and description to make this product easier to find"
+ )}
+ title={data.seoTitle}
+ titlePlaceholder={data.name}
+ description={data.seoDescription}
+ descriptionPlaceholder={data.description}
+ storefrontUrl={product ? product.url : undefined}
+ loading={disabled}
+ onClick={onSeoClick}
+ onChange={change}
+ />
+ </div>
</div>
- </div>
- <div>
- <ProductOrganization
- category={data.category}
- categories={
- categories !== undefined && categories !== null
- ? categories.map(category => ({
- label: category.name,
- value: category.id
- }))
- : []
- }
- errors={errors}
- productCollections={data.collections}
- collections={
- collections !== undefined && collections !== null
- ? collections.map(collection => ({
- label: collection.name,
- value: collection.id
- }))
- : []
- }
- product={product}
- data={data}
- disabled={disabled}
- onChange={change}
- />
- <div className={classes.cardContainer}>
- <ProductAvailabilityForm
- data={data}
+ <div>
+ <ProductOrganization
+ category={data.category}
+ categories={categories}
errors={errors}
- loading={disabled}
+ productCollections={data.collections}
+ collections={collections}
+ product={product}
+ data={data}
+ disabled={disabled}
onChange={change}
/>
+ <div className={classes.cardContainer}>
+ <ProductAvailabilityForm
+ data={data}
+ errors={errors}
+ loading={disabled}
+ onChange={change}
+ />
+ </div>
</div>
</div>
- </div>
- <SaveButtonBar
- labels={{
- delete: i18n.t("Remove product"),
- save: i18n.t("Save product")
- }}
- onDelete={toggleDeleteDialog}
- onSave={submit}
- state={saveButtonBarState}
- disabled={disabled || !onSubmit || !hasChanged}
- />
- </Container>
+ <SaveButtonBar
+ labels={{
+ delete: i18n.t("Remove product"),
+ save: i18n.t("Save product")
+ }}
+ onDelete={toggleDeleteDialog}
+ onSave={submit}
+ state={saveButtonBarState}
+ disabled={disabled || !hasChanged}
+ />
+ </Container>
+ <ActionDialog
+ open={openedDeleteDialog}
+ onClose={toggleDeleteDialog}
+ onConfirm={onDelete}
+ variant="delete"
+ title={i18n.t("Remove product")}
+ >
+ <DialogContentText
+ dangerouslySetInnerHTML={deleteDialogText}
+ />
+ </ActionDialog>
+ </>
)}
</Form>
)}
diff --git a/saleor/static/dashboard-next/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx b/saleor/static/dashboard-next/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx
index ab689eee9d..3fa0645b47 100644
--- a/saleor/static/dashboard-next/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx
+++ b/saleor/static/dashboard-next/products/components/ProductVariantCreatePage/ProductVariantCreatePage.tsx
@@ -12,7 +12,6 @@ import SaveButtonBar, {
import Toggle from "../../../components/Toggle";
import i18n from "../../../i18n";
import ProductVariantAttributes from "../ProductVariantAttributes";
-import ProductVariantImageSelectDialog from "../ProductVariantImageSelectDialog";
import ProductVariantNavigation from "../ProductVariantNavigation";
import ProductVariantPrice from "../ProductVariantPrice";
import ProductVariantStock from "../ProductVariantStock";
@@ -93,7 +92,6 @@ const ProductVariantCreatePage = decorate<ProductVariantCreatePageProps>(
onSubmit,
onVariantClick
}) => {
- const handleImageSelect = (ids: string[]) => {};
const initialForm = {
attributes:
product &&
diff --git a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
index d428b0af15..6701fe3061 100644
--- a/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductUpdate.tsx
@@ -152,7 +152,7 @@ export const ProductUpdate: React.StatelessComponent<ProductUpdateProps> = ({
onBack={() => {
navigate(productListUrl);
}}
- onDelete={deleteProduct.mutate}
+ onDelete={() => deleteProduct.mutate({ id })}
onProductShow={() => {
if (product) {
window.open(product.url);
diff --git a/saleor/static/dashboard-next/storybook/stories/products/ProductUpdatePage.tsx b/saleor/static/dashboard-next/storybook/stories/products/ProductUpdatePage.tsx
index 628e676849..5559bfea30 100644
--- a/saleor/static/dashboard-next/storybook/stories/products/ProductUpdatePage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/products/ProductUpdatePage.tsx
@@ -88,6 +88,7 @@ storiesOf("Views / Products / Product edit", module)
disabled={true}
placeholderImage={placeholderImage}
onAttributesEdit={undefined}
+ onDelete={undefined}
onImageDelete={() => undefined}
onVariantShow={() => undefined}
/>