Skip to content

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

Add unfulfilled items card

dominik-zeglen5d23152e05a5
diff --git a/saleor/static/dashboard-next/components/CardSpacer.tsx b/saleor/static/dashboard-next/components/CardSpacer.tsx
new file mode 100644
index 0000000000..785467a1f5
--- /dev/null
+++ b/saleor/static/dashboard-next/components/CardSpacer.tsx
@@ -0,0 +1,20 @@
+import { withStyles } from "@material-ui/core/styles";
+import * as React from "react";
+
+interface CardSpacerProps {
+ children?: React.ReactNode;
+}
+
+const decorate = withStyles(theme => ({
+ spacer: {
+ [theme.breakpoints.down("sm")]: {
+ marginTop: theme.spacing.unit
+ },
+ marginTop: theme.spacing.unit * 3
+ }
+}));
+export const CardSpacer = decorate<CardSpacerProps>(({ classes, children }) => (
+ <div className={classes.spacer}>{children}</div>
+));
+
+export default CardSpacer;
diff --git a/saleor/static/dashboard-next/components/CardTitle/CardTitle.tsx b/saleor/static/dashboard-next/components/CardTitle/CardTitle.tsx
index 56af6d6a17..7f41f8c593 100644
--- a/saleor/static/dashboard-next/components/CardTitle/CardTitle.tsx
+++ b/saleor/static/dashboard-next/components/CardTitle/CardTitle.tsx
@@ -3,7 +3,7 @@ import Typography from "@material-ui/core/Typography";
import * as React from "react";
interface CardTitleProps extends React.StatelessComponent {
- title: string;
+ title: string | React.ReactNode;
toolbar?: React.ReactNode;
onClick?: (event: React.MouseEvent<any>) => void;
}
diff --git a/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx b/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx
index 180ad084d4..821eb4f373 100644
--- a/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx
+++ b/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx
@@ -4,6 +4,7 @@ import * as React from "react";
import { transformAddressToForm } from "../..";
import { UserError } from "../../..";
+import { CardSpacer } from "../../../components/CardSpacer";
import { Container } from "../../../components/Container";
import DateFormatter from "../../../components/DateFormatter";
import Form from "../../../components/Form";
@@ -39,6 +40,7 @@ import OrderShippingMethodEditDialog, {
FormData as ShippingMethodForm
} from "../OrderShippingMethodEditDialog";
import OrderSummary from "../OrderSummary";
+import OrderUnfulfilledItems from "../OrderUnfulfilledItems/OrderUnfulfilledItems";
export interface OrderDetailsPageProps {
order: OrderDetails_order;
@@ -305,6 +307,12 @@ class OrderDetailsPageComponent extends React.Component<
</>
)}
+ <CardSpacer />
+ <OrderUnfulfilledItems
+ lines={unfulfilled}
+ onFulfill={this.toggleFulfillmentDialog}
+ />
+
{order ? (
!isDraft &&
order.fulfillments &&
diff --git a/saleor/static/dashboard-next/orders/components/OrderUnfulfilledItems/OrderUnfulfilledItems.tsx b/saleor/static/dashboard-next/orders/components/OrderUnfulfilledItems/OrderUnfulfilledItems.tsx
new file mode 100644
index 0000000000..b0a182c675
--- /dev/null
+++ b/saleor/static/dashboard-next/orders/components/OrderUnfulfilledItems/OrderUnfulfilledItems.tsx
@@ -0,0 +1,130 @@
+import Button from "@material-ui/core/Button";
+import Card from "@material-ui/core/Card";
+import CardActions from "@material-ui/core/CardActions";
+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 * as React from "react";
+
+import CardTitle from "../../../components/CardTitle";
+import Money from "../../../components/Money";
+import Skeleton from "../../../components/Skeleton";
+import StatusLabel from "../../../components/StatusLabel";
+import TableCellAvatar from "../../../components/TableCellAvatar";
+import i18n from "../../../i18n";
+import { maybe } from "../../../misc";
+import { OrderDetails_order_lines_edges_node } from "../../types/OrderDetails";
+
+interface OrderUnfulfilledItemsProps {
+ lines: OrderDetails_order_lines_edges_node[];
+ onFulfill: () => void;
+}
+
+const decorate = withStyles({
+ clickableRow: {
+ cursor: "pointer" as "pointer"
+ },
+ textCenter: {
+ textAlign: "center" as "center"
+ },
+ textRight: {
+ textAlign: "right" as "right"
+ },
+ wideCell: {
+ width: "50%"
+ }
+});
+const OrderUnfulfilledItems = decorate<OrderUnfulfilledItemsProps>(
+ ({ classes, lines }) => (
+ <Card>
+ <CardTitle
+ title={
+ <StatusLabel
+ label={i18n.t("Unfulfilled ({{ quantity }})", {
+ quantity: lines
+ .map(line => line.quantity - line.quantityFulfilled)
+ .reduce((prev, curr) => prev + curr)
+ })}
+ status="error"
+ />
+ }
+ />
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell className={classes.wideCell} colSpan={2}>
+ {i18n.t("Product")}
+ </TableCell>
+ <TableCell className={classes.textCenter}>
+ {i18n.t("Quantity")}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {i18n.t("Price")}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {i18n.t("Total")}
+ </TableCell>
+ </TableRow>
+ </TableHead>
+ <TableBody>
+ {lines.map(line => (
+ <TableRow
+ className={!!line ? classes.clickableRow : undefined}
+ hover={!!line}
+ key={maybe(() => line.id)}
+ >
+ <TableCellAvatar thumbnail={line.thumbnailUrl} />
+ <TableCell>
+ {maybe(() => line.productName) || <Skeleton />}
+ </TableCell>
+ <TableCell className={classes.textCenter}>
+ {maybe(() => line.quantity - line.quantityFulfilled) || (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {maybe(() => line.unitPrice.gross) ? (
+ <Money
+ amount={line.unitPrice.gross.amount}
+ currency={line.unitPrice.gross.currency}
+ />
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {maybe(
+ () =>
+ (line.quantity - line.quantityFulfilled) *
+ line.unitPrice.gross.amount
+ ) ? (
+ <Money
+ amount={
+ (line.quantity - line.quantityFulfilled) *
+ line.unitPrice.gross.amount
+ }
+ currency={line.unitPrice.gross.currency}
+ />
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ <CardActions>
+ <Button variant="flat" color="secondary">
+ {i18n.t("Fulfill", {
+ context: "button"
+ })}
+ </Button>
+ </CardActions>
+ </Card>
+ )
+);
+OrderUnfulfilledItems.displayName = "OrderUnfulfilledItems";
+export default OrderUnfulfilledItems;
diff --git a/saleor/static/dashboard-next/orders/components/OrderUnfulfilledItems/index.ts b/saleor/static/dashboard-next/orders/components/OrderUnfulfilledItems/index.ts
new file mode 100644
index 0000000000..4d7c268648
--- /dev/null
+++ b/saleor/static/dashboard-next/orders/components/OrderUnfulfilledItems/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./OrderUnfulfilledItems";
+export * from "./OrderUnfulfilledItems";
diff --git a/saleor/static/dashboard-next/theme.ts b/saleor/static/dashboard-next/theme.ts
index 07b6d39e8c..456c3cbb61 100644
--- a/saleor/static/dashboard-next/theme.ts
+++ b/saleor/static/dashboard-next/theme.ts
@@ -30,6 +30,11 @@ export default createMuiTheme({
borderRadius: 8
}
},
+ MuiCardActions: {
+ root: {
+ flexDirection: "row-reverse" as "row-reverse"
+ }
+ },
MuiInput: {
input: {
"&:-webkit-autofill": {