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

143 lines
4.7 KiB
TypeScript
Raw Normal View History

import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
import CardContent from "@material-ui/core/CardContent";
import { makeStyles } from "@material-ui/core/styles";
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 Typography from "@material-ui/core/Typography";
import CardTitle from "@saleor/components/CardTitle";
2020-06-22 16:34:59 +00:00
import Date from "@saleor/components/Date";
import ResponsiveTable from "@saleor/components/ResponsiveTable";
2020-06-22 16:34:59 +00:00
import Skeleton from "@saleor/components/Skeleton";
import TableCellHeader from "@saleor/components/TableCellHeader";
import { buttonMessages } from "@saleor/intl";
2020-06-22 16:34:59 +00:00
import { InvoiceFragment } from "@saleor/orders/types/InvoiceFragment";
import React from "react";
2020-06-23 09:19:21 +00:00
import { FormattedMessage, useIntl } from "react-intl";
const useStyles = makeStyles(
() => ({
2020-06-22 16:34:59 +00:00
cardContentTable: {
"&:last-child": {
2020-06-22 16:34:59 +00:00
padding: 0,
},
2020-06-22 16:34:59 +00:00
padding: 0,
},
2020-06-22 16:34:59 +00:00
colAction: { paddingRight: "0.5rem", width: "auto" },
colNumber: { width: "100%" },
colNumberClickable: {
cursor: "pointer",
2020-06-22 16:34:59 +00:00
width: "100%",
},
}),
{ name: "OrderInvoiceList" }
);
2020-06-22 16:34:59 +00:00
interface OrderInvoiceListProps {
invoices: InvoiceFragment[];
2020-06-30 12:38:04 +00:00
onInvoiceGenerate?: () => void;
onInvoiceClick?: (invoice: InvoiceFragment) => void;
onInvoiceSend?: (invoice: InvoiceFragment) => void;
2020-06-22 16:34:59 +00:00
}
2020-06-22 16:34:59 +00:00
const OrderInvoiceList: React.FC<OrderInvoiceListProps> = (props) => {
2020-06-30 12:38:04 +00:00
const { invoices, onInvoiceGenerate, onInvoiceClick, onInvoiceSend } = props;
2020-06-22 16:34:59 +00:00
const classes = useStyles(props);
const intl = useIntl();
return (
<Card>
<CardTitle
title={intl.formatMessage({
defaultMessage: "Invoices",
2020-06-22 16:34:59 +00:00
description: "section header",
})}
2020-06-22 16:34:59 +00:00
toolbar={
2020-06-30 12:38:04 +00:00
onInvoiceGenerate && (
<Button color="primary" onClick={onInvoiceGenerate}>
<FormattedMessage
2020-06-22 16:34:59 +00:00
defaultMessage="Generate"
description="generate invoice button"
/>
2020-06-22 16:34:59 +00:00
</Button>
)
}
/>
<CardContent className={invoices?.length && classes.cardContentTable}>
{!invoices ? (
<Skeleton />
) : !invoices?.length ? (
<Typography color="textSecondary">
<FormattedMessage defaultMessage="No invoices to be shown" />
</Typography>
) : (
<ResponsiveTable>
<TableHead>
<TableRow>
<TableCellHeader className={classes.colNumber}>
<FormattedMessage
defaultMessage="Invoice no"
description="invoice number"
/>
</TableCellHeader>
2020-06-30 12:38:04 +00:00
{onInvoiceSend && (
2020-06-22 16:34:59 +00:00
<TableCellHeader className={classes.colAction}>
<FormattedMessage
defaultMessage="Action"
description="action for invoice"
/>
</TableCellHeader>
)}
</TableRow>
</TableHead>
<TableBody>
2020-06-22 16:34:59 +00:00
{invoices?.map((invoice) => (
2020-06-22 16:34:59 +00:00
<TableRow key={invoice.id}>
<TableCell
className={
2020-06-30 12:38:04 +00:00
onInvoiceClick
2020-06-22 16:34:59 +00:00
? classes.colNumberClickable
: classes.colNumber
}
2020-06-30 12:38:04 +00:00
onClick={() => onInvoiceClick(invoice)}
2020-06-22 16:34:59 +00:00
>
<FormattedMessage
defaultMessage="Invoice"
description="invoice number prefix"
/>{" "}
{invoice.number}
<Typography variant="caption">
<FormattedMessage
defaultMessage="created"
description="invoice create date prefix"
/>{" "}
<Date date={invoice.createdAt} plain />
</Typography>
</TableCell>
2020-06-30 12:38:04 +00:00
{onInvoiceSend && (
2020-06-22 16:34:59 +00:00
<TableCell
className={classes.colAction}
2020-06-30 12:38:04 +00:00
onClick={() => onInvoiceSend(invoice)}
2020-06-22 16:34:59 +00:00
>
<Button color="primary">
<FormattedMessage {...buttonMessages.send} />
</Button>
</TableCell>
)}
</TableRow>
))}
</TableBody>
</ResponsiveTable>
)}
</CardContent>
</Card>
);
};
OrderInvoiceList.displayName = "OrderInvoiceList";
export default OrderInvoiceList;