import { TableCell, TableRow, TextField, Typography } from "@material-ui/core"; import Skeleton from "@saleor/components/Skeleton"; import TableCellAvatar from "@saleor/components/TableCellAvatar"; import { OrderFulfillLineFragment, OrderFulfillStockInput } from "@saleor/graphql"; import { FormsetChange, FormsetData } from "@saleor/hooks/useFormset"; import { Tooltip, WarningIcon } from "@saleor/macaw-ui"; import { getAttributesCaption, getOrderLineAvailableQuantity, getWarehouseStock } from "@saleor/orders/utils/data"; import classNames from "classnames"; import React from "react"; import { useIntl } from "react-intl"; import { messages } from "./messages"; import { useStyles } from "./styles"; interface OrderFulfillLineProps { line: OrderFulfillLineFragment; lineIndex: number; warehouseId: string; formsetData: FormsetData; formsetChange: FormsetChange; } export const OrderFulfillLine: React.FC = props => { const { line, lineIndex, warehouseId, formsetData, formsetChange } = props; const classes = useStyles(); const intl = useIntl(); const isDeletedVariant = !line?.variant; const isPreorder = !!line.variant?.preorder; const lineFormQuantity = isPreorder ? 0 : formsetData[lineIndex].value?.[0]?.quantity; const overfulfill = lineFormQuantity > line.quantityToFulfill; const warehouseStock = getWarehouseStock(line?.variant?.stocks, warehouseId); const availableQuantity = getOrderLineAvailableQuantity(line, warehouseStock); const isStockExceeded = lineFormQuantity > availableQuantity; if (!line) { return ( ); } return (
) : ( undefined ) } > {line.productName} {getAttributesCaption(line.variant?.attributes)}
{line.variant?.sku} {isPreorder ? ( ) : ( formsetChange(line.id, [ { quantity: parseInt(event.target.value, 10), warehouse: warehouseId } ]) } error={overfulfill} variant="outlined" InputProps={{ classes: { ...(isStockExceeded && !overfulfill && { notchedOutline: classes.warning }) }, endAdornment: (
/ {line.quantityToFulfill}
) }} />
)} {isPreorder || isDeletedVariant ? undefined : availableQuantity}
); }; OrderFulfillLine.displayName = "OrderFulfillLine"; export default OrderFulfillLine;