import { TableCell, TextField, Typography } from "@material-ui/core"; import Skeleton from "@saleor/components/Skeleton"; import TableCellAvatar from "@saleor/components/TableCellAvatar"; import TableRowLink from "@saleor/components/TableRowLink"; import { OrderFulfillLineFragment } from "@saleor/graphql"; import { FormsetChange, FormsetData } from "@saleor/hooks/useFormset"; import { ChevronIcon, IconButton, Tooltip, WarningIcon, } from "@saleor/macaw-ui"; import { getAttributesCaption, getOrderLineAvailableQuantity, getWarehouseStock, OrderFulfillLineFormData, } 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; formsetData: FormsetData; formsetChange: FormsetChange; onWarehouseChange: () => void; } export const OrderFulfillLine: React.FC = props => { const { line, lineIndex, formsetData, formsetChange, onWarehouseChange, } = 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 lineFormWarehouse = formsetData[lineIndex]?.value?.[0]?.warehouse; const overfulfill = lineFormQuantity > line.quantityToFulfill; const warehouseStock = getWarehouseStock( line?.variant?.stocks, lineFormWarehouse?.id, ); 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: lineFormWarehouse, }, ]) } error={overfulfill} variant="outlined" InputProps={{ classes: { ...(isStockExceeded && !overfulfill && { notchedOutline: classes.warning, }), }, endAdornment: (
/ {line.quantityToFulfill}
), }} />
)} {lineFormWarehouse ? isPreorder || isDeletedVariant ? undefined : availableQuantity : "-"} {isPreorder ? ( "-" ) : (
{lineFormWarehouse?.name ?? intl.formatMessage(messages.selectWarehouse)}
)}
); }; OrderFulfillLine.displayName = "OrderFulfillLine"; export default OrderFulfillLine;