From a5c1c9d544205a50b036d706cc2387229371e9e2 Mon Sep 17 00:00:00 2001 From: dominik-zeglen Date: Mon, 20 Apr 2020 18:23:54 +0200 Subject: [PATCH] Create fulfillment page --- .../OrderFulfillPage/OrderFulfillPage.tsx | 116 ++++++++++++++---- .../OrderFulfillmentDialog.tsx | 2 +- 2 files changed, 91 insertions(+), 27 deletions(-) diff --git a/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx b/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx index fecf6dcda..b2cd30842 100644 --- a/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx +++ b/src/orders/components/OrderFulfillPage/OrderFulfillPage.tsx @@ -1,20 +1,19 @@ import React from "react"; import { FormattedMessage, useIntl } from "react-intl"; import Card from "@material-ui/core/Card"; -import Typography from "@material-ui/core/Typography"; +import CardActions from "@material-ui/core/CardActions"; 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 classNames from "classnames"; +import Typography from "@material-ui/core/Typography"; import useFormset, { FormsetData } from "@saleor/hooks/useFormset"; import { StockInput } from "@saleor/types/globalTypes"; import { WarehouseFragment } from "@saleor/warehouses/types/WarehouseFragment"; -import TableCellAvatar, { - AVATAR_MARGIN -} from "@saleor/components/TableCellAvatar"; +import TableCellAvatar from "@saleor/components/TableCellAvatar"; import Container from "@saleor/components/Container"; import PageHeader from "@saleor/components/PageHeader"; import SaveButtonBar from "@saleor/components/SaveButtonBar"; @@ -24,18 +23,21 @@ import { OrderFulfillData_order } from "@saleor/orders/types/OrderFulfillData"; import CardTitle from "@saleor/components/CardTitle"; import ResponsiveTable from "@saleor/components/ResponsiveTable"; import makeStyles from "@material-ui/core/styles/makeStyles"; +import { update } from "@saleor/utils/lists"; +import ControlledCheckbox from "@saleor/components/ControlledCheckbox"; const useStyles = makeStyles( theme => ({ + actionBar: { + flexDirection: "row", + paddingLeft: theme.spacing(2) + 2 + }, colName: { width: 300 }, - colNameLabel: { - marginLeft: AVATAR_MARGIN - }, colQuantity: { textAlign: "right", - width: 200 + width: 210 }, colQuantityContent: { alignItems: "center", @@ -52,12 +54,17 @@ const useStyles = makeStyles( error: { color: theme.palette.error.main }, + full: { + fontWeight: 600 + }, + quantityInnerInput: { + padding: "16px 0 14px 12px" + }, quantityInput: { - width: "4rem" + width: 100 }, remainingQuantity: { - marginLeft: theme.spacing(), - paddingTop: 14 + marginLeft: theme.spacing() }, table: { "&&": { @@ -98,7 +105,10 @@ const OrderFulfillPage: React.FC = ({ const intl = useIntl(); const classes = useStyles({}); - const { change, data: formsetData } = useFormset( + const { change: formsetChange, data: formsetData } = useFormset< + null, + StockInput[] + >( order?.lines.map(line => ({ data: null, id: line.id, @@ -149,9 +159,7 @@ const OrderFulfillPage: React.FC = ({ - - - + = ({ {order?.lines.map((line, lineIndex) => { const remainingQuantity = line.quantity - line.quantityFulfilled; + const quantityToFulfill = formsetData[ + lineIndex + ].value.reduce( + (quantityToFulfill, lineInput) => + quantityToFulfill + lineInput.quantity, + 0 + ); + const overfulfill = remainingQuantity < quantityToFulfill; return ( @@ -187,6 +203,15 @@ const OrderFulfillPage: React.FC = ({ thumbnail={line?.thumbnail?.url} > {line.productName} + + {line.variant.attributes + .map(attribute => + attribute.values + .map(attributeValue => attributeValue.name) + .join(", ") + ) + .join(" / ")} + {line.variant.sku} @@ -195,6 +220,10 @@ const OrderFulfillPage: React.FC = ({ const warehouseStock = line.variant.stocks.find( stock => stock.warehouse.id === warehouse.id ); + const formsetStock = formsetData[ + lineIndex + ].value.find(line => line.warehouse === warehouse.id); + if (!warehouseStock) { return ( = ({ + formsetChange( + line.id, + update( + { + quantity: parseInt( + event.target.value, + 10 + ), + warehouse: warehouse.id + }, + formsetData[lineIndex].value, + (a, b) => a.warehouse === b.warehouse + ) + ) } - onChange={event => undefined} error={ - remainingQuantity < - formsetData[lineIndex].value[0] - .quantity || - formsetData[lineIndex].value[0].quantity > + overfulfill || + formsetStock.quantity > warehouseStock.quantity } /> @@ -241,10 +283,15 @@ const OrderFulfillPage: React.FC = ({ ); })} - {formsetData[lineIndex].value.reduce( - (acc, stock) => acc + stock.quantity, - 0 - )}{" "} + + {quantityToFulfill} + {" "} / {remainingQuantity} @@ -252,9 +299,26 @@ const OrderFulfillPage: React.FC = ({ })} + + +