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

148 lines
4.4 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";
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 i18n from "../../../i18n";
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: {
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) => (
<Card>
<CardTitle
title={
<StatusLabel
label={i18n.t("Unfulfilled ({{ quantity }})", {
quantity: lines
.map(line => line.quantity - line.quantityFulfilled)
.reduce((prev, curr) => prev + curr, 0)
})}
status="error"
/>
}
/>
2019-08-09 11:14:35 +00:00
<Table className={classes.table}>
2019-06-19 14:40:52 +00:00
<TableHead>
<TableRow>
2019-08-09 11:14:35 +00:00
<TableCell className={classes.colName}>
<span className={classes.colNameLabel}>{i18n.t("Product")}</span>
2019-06-19 14:40:52 +00:00
</TableCell>
2019-08-09 11:14:35 +00:00
<TableCell className={classes.colQuantity}>
2019-06-19 14:40:52 +00:00
{i18n.t("Quantity")}
</TableCell>
2019-08-09 11:14:35 +00:00
<TableCell className={classes.colPrice}>{i18n.t("Price")}</TableCell>
<TableCell className={classes.colTotal}>{i18n.t("Total")}</TableCell>
2019-06-19 14:40:52 +00:00
</TableRow>
</TableHead>
<TableBody>
{lines.map(line => (
<TableRow
className={!!line ? classes.clickableRow : undefined}
hover={!!line}
key={maybe(() => line.id)}
>
2019-08-09 11:14:35 +00:00
<TableCellAvatar
className={classes.colName}
thumbnail={maybe(() => line.thumbnail.url)}
>
2019-06-19 14:40:52 +00:00
{maybe(() => line.productName) || <Skeleton />}
2019-08-09 11:14:35 +00:00
</TableCellAvatar>
<TableCell className={classes.colQuantity}>
2019-06-19 14:40:52 +00:00
{maybe(() => line.quantity - line.quantityFulfilled) || (
<Skeleton />
)}
</TableCell>
2019-08-09 11:14:35 +00:00
<TableCell className={classes.colPrice}>
2019-06-19 14:40:52 +00:00
{maybe(() => line.unitPrice.gross) ? (
<Money money={line.unitPrice.gross} />
) : (
<Skeleton />
)}
</TableCell>
2019-08-09 11:14:35 +00:00
<TableCell className={classes.colTotal}>
2019-06-19 14:40:52 +00:00
{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}>
{i18n.t("Fulfill", {
context: "button"
})}
</Button>
</CardActions>
)}
</Card>
));
OrderUnfulfilledItems.displayName = "OrderUnfulfilledItems";
export default OrderUnfulfilledItems;