Skip to content

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

Add draft order product management

dominik-zeglen679eadd8d2bc
diff --git a/saleor/static/dashboard-next/components/CardTitle/CardTitle.tsx b/saleor/static/dashboard-next/components/CardTitle/CardTitle.tsx
index 7f41f8c593..c12fcf206f 100644
--- a/saleor/static/dashboard-next/components/CardTitle/CardTitle.tsx
+++ b/saleor/static/dashboard-next/components/CardTitle/CardTitle.tsx
@@ -26,7 +26,8 @@ const decorate = withStyles(theme => ({
title: {
flex: 1,
fontSize: "1rem",
- fontWeight: 600 as 600
+ fontWeight: 600 as 600,
+ lineHeight: 1
},
toolbar: {
marginRight: -theme.spacing.unit * 2,
diff --git a/saleor/static/dashboard-next/components/Debounce.tsx b/saleor/static/dashboard-next/components/Debounce.tsx
new file mode 100644
index 0000000000..43675d5b19
--- /dev/null
+++ b/saleor/static/dashboard-next/components/Debounce.tsx
@@ -0,0 +1,40 @@
+import * as React from "react";
+
+export interface DebounceProps {
+ change: (event: React.ChangeEvent<any>) => void;
+ children:
+ | ((
+ props: (event: React.ChangeEvent<any>) => void
+ ) => React.ReactElement<any>)
+ | React.ReactNode;
+ submit: (event: React.FormEvent<any>) => void;
+}
+export interface DebounceState {
+ timer: any | null;
+}
+
+export class Debounce extends React.Component<DebounceProps, DebounceState> {
+ state: DebounceState = {
+ timer: null
+ };
+
+ handleChange = (event: React.ChangeEvent<any>) => {
+ const { timer } = this.state;
+ if (timer) {
+ clearTimeout(timer);
+ }
+ this.setState({
+ timer: setTimeout(this.props.submit, 200)
+ });
+ this.props.change(event);
+ };
+
+ render() {
+ const { children } = this.props;
+ if (typeof children === "function") {
+ return children(this.handleChange);
+ }
+ return children;
+ }
+}
+export default Debounce;
diff --git a/saleor/static/dashboard-next/components/Form/Form.tsx b/saleor/static/dashboard-next/components/Form/Form.tsx
index f6ac4cacae..3fcc1513f8 100644
--- a/saleor/static/dashboard-next/components/Form/Form.tsx
+++ b/saleor/static/dashboard-next/components/Form/Form.tsx
@@ -42,7 +42,9 @@ class Form<T extends {} = {}> extends React.Component<FormProps<T>, T> {
handleSubmit = (event?: React.FormEvent<any>) => {
const { onSubmit } = this.props;
- event.preventDefault();
+ if (event) {
+ event.preventDefault();
+ }
if (onSubmit !== undefined) {
onSubmit(this.state);
}
diff --git a/saleor/static/dashboard-next/components/Link.tsx b/saleor/static/dashboard-next/components/Link.tsx
new file mode 100644
index 0000000000..fee2fd1013
--- /dev/null
+++ b/saleor/static/dashboard-next/components/Link.tsx
@@ -0,0 +1,34 @@
+import { withStyles } from "@material-ui/core/styles";
+import Typography, { TypographyProps } from "@material-ui/core/Typography";
+import * as classNames from "classnames";
+import * as React from "react";
+
+interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
+ color?: "primary" | "secondary";
+ typographyProps?: TypographyProps;
+}
+
+const decorate = withStyles(theme => ({
+ primary: {
+ color: theme.palette.primary.main
+ },
+ root: {
+ cursor: "pointer" as "pointer",
+ textDecoration: "underline" as "underline"
+ },
+ secondary: {
+ color: theme.palette.secondary.main
+ }
+}));
+const Link = decorate<LinkProps>(
+ ({ classes, className, children, color = "primary", ...linkProps }) => (
+ <Typography
+ component="a"
+ className={classNames(classes.root, classes[color])}
+ {...linkProps}
+ >
+ {children}
+ </Typography>
+ )
+);
+export default Link;
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftDetails/OrderDraftDetails.tsx b/saleor/static/dashboard-next/orders/components/OrderDraftDetails/OrderDraftDetails.tsx
new file mode 100644
index 0000000000..819f9e207f
--- /dev/null
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftDetails/OrderDraftDetails.tsx
@@ -0,0 +1,57 @@
+import Button from "@material-ui/core/Button";
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import * as React from "react";
+
+import CardTitle from "../../../components/CardTitle";
+import i18n from "../../../i18n";
+import { maybe } from "../../../misc";
+import { OrderDetails_order } from "../../types/OrderDetails";
+import OrderDraftDetailsProducts, {
+ FormData as OrderDraftDetailsProductsFormData
+} from "../OrderDraftDetailsProducts";
+import OrderDraftDetailsSummary from "../OrderDraftDetailsSummary/OrderDraftDetailsSummary";
+
+interface OrderDraftDetailsProps {
+ order: OrderDetails_order;
+ onOrderLineAdd: () => void;
+ onOrderLineChange: (
+ id: string,
+ data: OrderDraftDetailsProductsFormData
+ ) => void;
+ onShippingMethodEdit: () => void;
+}
+
+const OrderDraftDetails: React.StatelessComponent<OrderDraftDetailsProps> = ({
+ order,
+ onOrderLineAdd,
+ onOrderLineChange,
+ onShippingMethodEdit
+}) => (
+ <Card>
+ <CardTitle
+ title={i18n.t("Order details", {
+ context: "card title"
+ })}
+ toolbar={
+ <Button color="secondary" variant="flat" onClick={onOrderLineAdd}>
+ {i18n.t("Add products", {
+ context: "button"
+ })}
+ </Button>
+ }
+ />
+ <OrderDraftDetailsProducts
+ lines={maybe(() => order.lines.edges.map(edge => edge.node))}
+ onOrderLineChange={onOrderLineChange}
+ />
+ <CardContent>
+ <OrderDraftDetailsSummary
+ order={order}
+ onShippingMethodEdit={onShippingMethodEdit}
+ />
+ </CardContent>
+ </Card>
+);
+OrderDraftDetails.displayName = "OrderDraftDetails";
+export default OrderDraftDetails;
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftDetails/index.ts b/saleor/static/dashboard-next/orders/components/OrderDraftDetails/index.ts
new file mode 100644
index 0000000000..02dcb0a12f
--- /dev/null
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftDetails/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./OrderDraftDetails";
+export * from "./OrderDraftDetails";
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftDetailsProducts/OrderDraftDetailsProducts.tsx b/saleor/static/dashboard-next/orders/components/OrderDraftDetailsProducts/OrderDraftDetailsProducts.tsx
new file mode 100644
index 0000000000..a6448e146f
--- /dev/null
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftDetailsProducts/OrderDraftDetailsProducts.tsx
@@ -0,0 +1,149 @@
+import IconButton from "@material-ui/core/IconButton";
+import { withStyles } from "@material-ui/core/styles";
+import Table from "@material-ui/core/Table";
+import TableBody from "@material-ui/core/TableBody";
+import TableCell from "@material-ui/core/TableCell";
+import TableHead from "@material-ui/core/TableHead";
+import TableRow from "@material-ui/core/TableRow";
+import TextField from "@material-ui/core/TextField";
+import Typography from "@material-ui/core/Typography";
+import DeleteIcon from "@material-ui/icons/Delete";
+import * as React from "react";
+
+import Debounce from "../../../components/Debounce";
+import Form from "../../../components/Form";
+import Money from "../../../components/Money";
+import Skeleton from "../../../components/Skeleton";
+import TableCellAvatar from "../../../components/TableCellAvatar";
+import i18n from "../../../i18n";
+import { maybe, renderCollection } from "../../../misc";
+import { OrderDetails_order_lines_edges_node } from "../../types/OrderDetails";
+
+export interface FormData {
+ quantity: number;
+}
+
+interface OrderDraftDetailsProductsProps {
+ lines: OrderDetails_order_lines_edges_node[];
+ onOrderLineChange: (id: string, data: FormData) => void;
+}
+
+const decorate = withStyles({
+ iconCell: {
+ "&:last-child": {
+ paddingRight: 0
+ }
+ },
+ quantityField: {
+ "& input": {
+ textAlign: "right" as "right"
+ },
+ width: 60
+ },
+ textRight: {
+ textAlign: "right" as "right"
+ }
+});
+const OrderDraftDetailsProducts = decorate<OrderDraftDetailsProductsProps>(
+ ({ classes, lines, onOrderLineChange }) => (
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell colSpan={2}>
+ {i18n.t("Product", { context: "table header" })}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {i18n.t("Quantity", { context: "table header" })}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {i18n.t("Price", { context: "table header" })}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {i18n.t("Total", { context: "table header" })}
+ </TableCell>
+ <TableCell />
+ </TableRow>
+ </TableHead>
+ <TableBody>
+ {renderCollection(
+ lines,
+ line => (
+ <TableRow key={line ? line.id : "skeleton"}>
+ <TableCellAvatar thumbnail={maybe(() => line.thumbnailUrl)} />
+ <TableCell>
+ {maybe(() => line.productName && line.productSku) ? (
+ <>
+ <Typography variant="body1">{line.productName}</Typography>
+ <Typography variant="caption">{line.productSku}</Typography>
+ </>
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {maybe(() => line.quantity) ? (
+ <Form
+ initial={{ quantity: line.quantity }}
+ onSubmit={data => onOrderLineChange(line.id, data)}
+ >
+ {({ change, data, hasChanged, submit }) => (
+ <Debounce
+ change={change}
+ submit={hasChanged ? submit : undefined}
+ >
+ {debounce => (
+ <TextField
+ className={classes.quantityField}
+ fullWidth
+ name="quantity"
+ type="number"
+ value={data.quantity}
+ onChange={debounce}
+ />
+ )}
+ </Debounce>
+ )}
+ </Form>
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {maybe(() => line.unitPrice.net) ? (
+ <Money
+ amount={line.unitPrice.net.amount}
+ currency={line.unitPrice.net.currency}
+ />
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {maybe(() => line.unitPrice.net && line.quantity) ? (
+ <Money
+ amount={line.unitPrice.net.amount * line.quantity}
+ currency={line.unitPrice.net.currency}
+ />
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.iconCell}>
+ <IconButton>
+ <DeleteIcon color="secondary" />
+ </IconButton>
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell colSpan={5}>{i18n.t("No products found")}</TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ )
+);
+OrderDraftDetailsProducts.displayName = "OrderDraftDetailsProducts";
+export default OrderDraftDetailsProducts;
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftDetailsProducts/index.ts b/saleor/static/dashboard-next/orders/components/OrderDraftDetailsProducts/index.ts
new file mode 100644
index 0000000000..75f2b953f5
--- /dev/null
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftDetailsProducts/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./OrderDraftDetailsProducts";
+export * from "./OrderDraftDetailsProducts";
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftDetailsSummary/OrderDraftDetailsSummary.tsx b/saleor/static/dashboard-next/orders/components/OrderDraftDetailsSummary/OrderDraftDetailsSummary.tsx
new file mode 100644
index 0000000000..2c979fea7f
--- /dev/null
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftDetailsSummary/OrderDraftDetailsSummary.tsx
@@ -0,0 +1,101 @@
+import { withStyles } from "@material-ui/core/styles";
+import * as React from "react";
+
+import Link from "../../../components/Link";
+import Money from "../../../components/Money";
+import Skeleton from "../../../components/Skeleton";
+import i18n from "../../../i18n";
+import { maybe } from "../../../misc";
+import { OrderDetails_order } from "../../types/OrderDetails";
+
+interface OrderDraftDetailsSummaryProps {
+ order: OrderDetails_order;
+ onShippingMethodEdit: () => void;
+}
+
+const decorate = withStyles(theme => ({
+ root: {
+ ...theme.typography.body1,
+ lineHeight: 1.9,
+ width: "100%"
+ },
+ textRight: {
+ textAlign: "right" as "right"
+ }
+}));
+const OrderDraftDetailsSummary = decorate<OrderDraftDetailsSummaryProps>(
+ ({ classes, order, onShippingMethodEdit }) => (
+ <table className={classes.root}>
+ <tbody>
+ <tr>
+ {maybe(() => order.subtotal) ? (
+ <>
+ <td>{i18n.t("Subtotal")}</td>
+ <td className={classes.textRight}>
+ <Money {...order.subtotal.gross} />
+ </td>
+ </>
+ ) : (
+ <td colSpan={2}>
+ <Skeleton />
+ </td>
+ )}
+ </tr>
+ <tr>
+ {maybe(() => order.shippingMethod) !== undefined ? (
+ <>
+ <td>
+ <Link onClick={onShippingMethodEdit}>
+ {maybe(() => order.shippingMethodName)
+ ? order.shippingMethodName
+ : i18n.t("Add Shipping Carrier")}
+ </Link>
+ </td>
+ <td className={classes.textRight}>
+ {maybe(() => order.shippingPrice) ? (
+ <Money {...order.shippingPrice.gross} />
+ ) : (
+ "---"
+ )}
+ </td>
+ </>
+ ) : (
+ <td colSpan={2}>
+ <Skeleton />
+ </td>
+ )}
+ </tr>
+ <tr>
+ {maybe(() => order.total.tax) !== undefined ? (
+ <>
+ <td>{i18n.t("Taxes (VAT included)")}</td>
+ <td className={classes.textRight}>
+ <Money {...order.total.tax} />
+ </td>
+ </>
+ ) : (
+ <td colSpan={2}>
+ <Skeleton />
+ </td>
+ )}
+ </tr>
+ <tr>
+ {maybe(() => order.total.gross) !== undefined ? (
+ <>
+ <td>{i18n.t("Total")}</td>
+ <td className={classes.textRight}>
+ <Money {...order.total.gross} />
+ </td>
+ </>
+ ) : (
+ <td colSpan={2}>
+ <Skeleton />
+ </td>
+ )}
+ </tr>
+ </tbody>
+ </table>
+ )
+);
+OrderDraftDetailsSummary.displayName = "OrderDraftDetailsSummary";
+export default OrderDraftDetailsSummary;
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftDetailsSummary/index.ts b/saleor/static/dashboard-next/orders/components/OrderDraftDetailsSummary/index.ts
new file mode 100644
index 0000000000..78bbd58f09
--- /dev/null
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftDetailsSummary/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./OrderDraftDetailsSummary";
+export * from "./OrderDraftDetailsSummary";
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftPage/index.ts b/saleor/static/dashboard-next/orders/components/OrderDraftPage/index.ts
new file mode 100644
index 0000000000..4d4fa008b9
--- /dev/null
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftPage/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./OrderDraftPage";
+export * from "./OrderDraftPage";
diff --git a/saleor/static/dashboard-next/orders/fixtures.ts b/saleor/static/dashboard-next/orders/fixtures.ts
index 8202299db3..4bb3450735 100644
--- a/saleor/static/dashboard-next/orders/fixtures.ts
+++ b/saleor/static/dashboard-next/orders/fixtures.ts
@@ -957,6 +957,108 @@ export const order = (placeholder: string): OrderDetails_order => ({
},
user: null
});
+export const draftOrder = (placeholder: string) => ({
+ __typename: "Order" as "Order",
+ availableShippingMethods: null,
+ billingAddress: null,
+ created: "2018-09-20T23:23:39.811428+00:00",
+ events: [],
+ fulfillments: [],
+ id: "T3JkZXI6MjQ=",
+ lines: {
+ __typename: "OrderLineCountableConnection" as "OrderLineCountableConnection",
+ edges: [
+ {
+ __typename: "OrderLineCountableEdge" as "OrderLineCountableEdge",
+ node: {
+ __typename: "OrderLine" as "OrderLine",
+ id: "T3JkZXJMaW5lOjQ1",
+ productName: "Davis Group (Hard)",
+ productSku: "58-1338",
+ quantity: 2,
+ quantityFulfilled: 0,
+ thumbnailUrl: placeholder,
+ unitPrice: {
+ __typename: "TaxedMoney" as "TaxedMoney",
+ gross: {
+ __typename: "Money" as "Money",
+ amount: 65.95,
+ currency: "USD"
+ },
+ net: {
+ __typename: "Money" as "Money",
+ amount: 65.95,
+ currency: "USD"
+ }
+ }
+ }
+ },
+ {
+ __typename: "OrderLineCountableEdge" as "OrderLineCountableEdge",
+ node: {
+ __typename: "OrderLine" as "OrderLine",
+ id: "T3JkZXJMaW5lOjQ2",
+ productName: "Anderson PLC (15-1337)",
+ productSku: "15-1337",
+ quantity: 2,
+ quantityFulfilled: 0,
+ thumbnailUrl: placeholder,
+ unitPrice: {
+ __typename: "TaxedMoney" as "TaxedMoney",
+ gross: {
+ __typename: "Money" as "Money",
+ amount: 68.2,
+ currency: "USD"
+ },
+ net: {
+ __typename: "Money" as "Money",
+ amount: 68.2,
+ currency: "USD"
+ }
+ }
+ }
+ }
+ ]
+ },
+ number: "24",
+ paymentStatus: null,
+ shippingAddress: null,
+ shippingMethod: null,
+ shippingMethodName: null,
+ shippingPrice: {
+ __typename: "TaxedMoney" as "TaxedMoney",
+ gross: {
+ __typename: "Money" as "Money",
+ amount: 0,
+ currency: "USD"
+ }
+ },
+ status: "DRAFT" as OrderStatus.DRAFT,
+ subtotal: {
+ __typename: "TaxedMoney" as "TaxedMoney",
+ gross: {
+ __typename: "Money" as "Money",
+ amount: 168.3,
+ currency: "USD"
+ }
+ },
+ total: {
+ __typename: "TaxedMoney" as "TaxedMoney",
+ gross: {
+ __typename: "Money" as "Money",
+ amount: 168.3,
+ currency: "USD"
+ },
+ tax: {
+ __typename: "Money" as "Money",
+ amount: 68.3,
+ currency: "USD"
+ }
+ },
+ totalAuthorized: null,
+ totalCaptured: null,
+ user: null
+});
export const flatOrders = orders.map(order => ({
...order,
orderStatus: transformOrderStatus(order.status),
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index 1e3df1e0af..ed8277abac 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -78,6 +78,7 @@ function loadStories() {
require("./stories/orders/OrderCustomer");
require("./stories/orders/OrderCustomerEditDialog");
require("./stories/orders/OrderDetailsPage");
+ require("./stories/orders/OrderDraftPage");
require("./stories/orders/OrderFulfillmentCancelDialog");
require("./stories/orders/OrderFulfillmentDialog");
require("./stories/orders/OrderFulfillmentTrackingDialog");
diff --git a/saleor/static/dashboard-next/storybook/stories/orders/OrderDraftPage.tsx b/saleor/static/dashboard-next/storybook/stories/orders/OrderDraftPage.tsx
new file mode 100644
index 0000000000..7ec8bbfa9f
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/orders/OrderDraftPage.tsx
@@ -0,0 +1,52 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import * as placeholderImage from "../../../../images/placeholder60x60.png";
+import OrderDraftPage, {
+ OrderDraftPageProps
+} from "../../../orders/components/OrderDraftPage";
+import {
+ clients,
+ countries,
+ draftOrder,
+ shippingMethods,
+ variants
+} from "../../../orders/fixtures";
+import Decorator from "../../Decorator";
+
+const order = draftOrder(placeholderImage);
+
+const props: OrderDraftPageProps = {
+ countries,
+ errors: [],
+ fetchUsers: () => undefined,
+ fetchVariants: () => undefined,
+ onBack: () => undefined,
+ onBillingAddressEdit: undefined,
+ onCustomerEdit: () => undefined,
+ onDraftFinalize: () => undefined,
+ onDraftRemove: () => undefined,
+ onNoteAdd: undefined,
+ onOrderLineAdd: () => undefined,
+ onOrderLineChange: () => undefined,
+ onOrderLineRemove: () => () => undefined,
+ onProductClick: undefined,
+ onShippingAddressEdit: undefined,
+ onShippingMethodEdit: undefined,
+ order,
+ shippingMethods,
+ users: clients,
+ variants,
+ variantsLoading: false
+};
+
+storiesOf("Views / Orders / Order draft", module)
+ .addDecorator(Decorator)
+ .add("default", () => <OrderDraftPage {...props} />)
+ .add("loading", () => <OrderDraftPage {...props} order={undefined} />)
+ .add("without lines", () => (
+ <OrderDraftPage
+ {...props}
+ order={{ ...order, lines: { ...order.lines, edges: [] } }}
+ />
+ ));
diff --git a/saleor/static/dashboard-next/theme.ts b/saleor/static/dashboard-next/theme.ts
index 456c3cbb61..2a619d80bf 100644
--- a/saleor/static/dashboard-next/theme.ts
+++ b/saleor/static/dashboard-next/theme.ts
@@ -108,7 +108,7 @@ export default createMuiTheme({
paddingLeft: 24 + "px",
textAlign: "left" as "left"
},
- paddingLeft: 0
+ padding: "4px 24px 4px 0"
}
},
MuiTableRow: {