saleor-dashboard/src/orders/components/OrderUnfulfilledItems/OrderUnfulfilledItems.tsx

175 lines
5.3 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
import CardActions from "@material-ui/core/CardActions";
import { createStyles, withStyles, 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";
2019-08-09 10:26:22 +00:00
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
2019-06-19 14:40:52 +00:00
import CardTitle from "@saleor/components/CardTitle";
import Money from "@saleor/components/Money";
import Skeleton from "@saleor/components/Skeleton";
import StatusLabel from "@saleor/components/StatusLabel";
2019-08-09 11:14:35 +00:00
import TableCellAvatar, {
AVATAR_MARGIN
} from "@saleor/components/TableCellAvatar";
2019-06-19 14:40:52 +00:00
import { maybe } from "../../../misc";
import { OrderDetails_order_lines } from "../../types/OrderDetails";
const styles = createStyles({
clickableRow: {
cursor: "pointer"
},
2019-08-09 11:14:35 +00:00
colName: {
2019-09-02 08:44:26 +00:00
paddingLeft: 0,
2019-08-09 11:14:35 +00:00
width: "auto"
2019-06-19 14:40:52 +00:00
},
2019-08-09 11:14:35 +00:00
colNameLabel: {
marginLeft: AVATAR_MARGIN
2019-06-19 14:40:52 +00:00
},
2019-08-09 11:14:35 +00:00
colPrice: {
textAlign: "right",
width: 120
},
colQuantity: {
textAlign: "center",
width: 120
},
colTotal: {
textAlign: "right",
width: 120
},
statusBar: {
paddingTop: 0
},
table: {
tableLayout: "fixed"
2019-06-19 14:40:52 +00:00
}
});
interface OrderUnfulfilledItemsProps extends WithStyles<typeof styles> {
canFulfill: boolean;
lines: OrderDetails_order_lines[];
onFulfill: () => void;
}
const OrderUnfulfilledItems = withStyles(styles, {
name: "OrderUnfulfilledItems"
})(({ canFulfill, classes, lines, onFulfill }: OrderUnfulfilledItemsProps) => {
const intl = useIntl();
return (
<Card>
<CardTitle
title={
<StatusLabel
label={intl.formatMessage(
{
defaultMessage: "Unfulfilled ({quantity})",
description: "section header"
},
{
quantity: lines
.map(line => line.quantity - line.quantityFulfilled)
.reduce((prev, curr) => prev + curr, 0)
}
)}
status="error"
/>
}
/>
<Table className={classes.table}>
<TableHead>
<TableRow>
<TableCell className={classes.colName}>
<span className={classes.colNameLabel}>
<FormattedMessage
defaultMessage="Product"
description="product name"
/>
</span>
</TableCell>
2019-08-09 11:14:35 +00:00
<TableCell className={classes.colQuantity}>
<FormattedMessage
defaultMessage="Quantity"
description="ordered products"
/>
2019-06-19 14:40:52 +00:00
</TableCell>
2019-08-09 11:14:35 +00:00
<TableCell className={classes.colPrice}>
<FormattedMessage
defaultMessage="Price"
description="product unit price"
/>
2019-06-19 14:40:52 +00:00
</TableCell>
2019-08-09 11:14:35 +00:00
<TableCell className={classes.colTotal}>
<FormattedMessage
defaultMessage="Total"
description="order line total price"
/>
2019-06-19 14:40:52 +00:00
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{lines.map(line => (
<TableRow
className={!!line ? classes.clickableRow : undefined}
hover={!!line}
key={maybe(() => line.id)}
>
<TableCellAvatar
className={classes.colName}
thumbnail={maybe(() => line.thumbnail.url)}
>
{maybe(() => line.productName) || <Skeleton />}
</TableCellAvatar>
<TableCell className={classes.colQuantity}>
{maybe(() => line.quantity - line.quantityFulfilled) || (
<Skeleton />
)}
</TableCell>
<TableCell className={classes.colPrice}>
{maybe(() => line.unitPrice.gross) ? (
<Money money={line.unitPrice.gross} />
) : (
<Skeleton />
)}
</TableCell>
<TableCell className={classes.colTotal}>
{maybe(
() =>
(line.quantity - line.quantityFulfilled) *
line.unitPrice.gross.amount
) ? (
<Money
money={{
amount:
(line.quantity - line.quantityFulfilled) *
line.unitPrice.gross.amount,
currency: line.unitPrice.gross.currency
}}
/>
) : (
<Skeleton />
)}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
{canFulfill && (
<CardActions>
<Button variant="text" color="primary" onClick={onFulfill}>
<FormattedMessage defaultMessage="Fulfill" description="button" />
</Button>
</CardActions>
)}
</Card>
);
});
2019-06-19 14:40:52 +00:00
OrderUnfulfilledItems.displayName = "OrderUnfulfilledItems";
export default OrderUnfulfilledItems;