saleor-dashboard/src/home/components/HomeNotificationTable/HomeNotificationTable.tsx

152 lines
5.4 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import Card from "@material-ui/core/Card";
2019-10-30 14:34:24 +00:00
import { makeStyles } from "@material-ui/core/styles";
2019-06-19 14:40:52 +00:00
import TableBody from "@material-ui/core/TableBody";
import TableCell from "@material-ui/core/TableCell";
import TableRow from "@material-ui/core/TableRow";
import Typography from "@material-ui/core/Typography";
import KeyboardArrowRight from "@material-ui/icons/KeyboardArrowRight";
2019-10-08 14:19:24 +00:00
import RequirePermissions from "@saleor/components/RequirePermissions";
2019-11-04 14:25:23 +00:00
import ResponsiveTable from "@saleor/components/ResponsiveTable";
2019-06-19 14:40:52 +00:00
import Skeleton from "@saleor/components/Skeleton";
2019-10-08 14:19:24 +00:00
import { UserPermissionProps } from "@saleor/types";
import { PermissionEnum } from "@saleor/types/globalTypes";
import React from "react";
import { FormattedMessage } from "react-intl";
2019-06-19 14:40:52 +00:00
2019-12-03 15:28:40 +00:00
const useStyles = makeStyles(
theme => ({
arrowIcon: {
width: theme.spacing(4)
},
tableRow: {
cursor: "pointer"
}
}),
{ name: "HomeNotificationTable" }
);
2019-06-19 14:40:52 +00:00
2019-10-08 14:19:24 +00:00
interface HomeNotificationTableProps extends UserPermissionProps {
2019-06-19 14:40:52 +00:00
ordersToCapture: number;
ordersToFulfill: number;
productsOutOfStock: number;
onOrdersToFulfillClick: () => void;
onOrdersToCaptureClick: () => void;
onProductsOutOfStockClick: () => void;
}
2019-10-30 14:34:24 +00:00
const HomeNotificationTable: React.FC<HomeNotificationTableProps> = props => {
const {
2019-06-19 14:40:52 +00:00
onOrdersToCaptureClick,
onOrdersToFulfillClick,
onProductsOutOfStockClick,
ordersToCapture,
ordersToFulfill,
2019-10-08 14:19:24 +00:00
productsOutOfStock,
userPermissions
2019-10-30 14:34:24 +00:00
} = props;
const classes = useStyles(props);
return (
2019-08-27 09:35:54 +00:00
<Card>
2019-11-04 14:25:23 +00:00
<ResponsiveTable>
2019-08-27 09:35:54 +00:00
<TableBody className={classes.tableRow}>
2019-10-08 14:19:24 +00:00
<RequirePermissions
userPermissions={userPermissions}
requiredPermissions={[PermissionEnum.MANAGE_ORDERS]}
>
<TableRow hover={true} onClick={onOrdersToFulfillClick}>
<TableCell>
{ordersToFulfill === undefined ? (
<Skeleton />
) : ordersToFulfill === 0 ? (
<Typography>
<FormattedMessage
defaultMessage="No orders ready to fulfill"
id="homeNotificationTableNoOrders"
/>
</Typography>
) : (
<Typography>
<FormattedMessage
2020-02-13 11:14:16 +00:00
defaultMessage="{amount, plural,one {One order is ready to fulfill} other {{amount} Orders are ready to fulfill}}"
2019-10-08 14:19:24 +00:00
id="homeNotificationTableOrders"
values={{
amount: <strong>{ordersToFulfill}</strong>
}}
/>
</Typography>
)}
</TableCell>
<TableCell className={classes.arrowIcon}>
<KeyboardArrowRight />
</TableCell>
</TableRow>
<TableRow hover={true} onClick={onOrdersToCaptureClick}>
<TableCell>
{ordersToCapture === undefined ? (
<Skeleton />
) : ordersToCapture === 0 ? (
<Typography>
<FormattedMessage
defaultMessage="No payments waiting for capture"
id="homeNotificationsNoPayments"
/>
</Typography>
) : (
<Typography>
<FormattedMessage
2020-02-13 11:14:16 +00:00
defaultMessage="{amount, plural,one {One payment to capture}other {{amount} Payments to capture}}"
2019-10-08 14:19:24 +00:00
id="homeNotificationTablePayments"
values={{
amount: <strong>{ordersToCapture}</strong>
}}
/>
</Typography>
)}
</TableCell>
<TableCell className={classes.arrowIcon}>
<KeyboardArrowRight />
</TableCell>
</TableRow>
</RequirePermissions>
<RequirePermissions
userPermissions={userPermissions}
requiredPermissions={[PermissionEnum.MANAGE_PRODUCTS]}
>
<TableRow hover={true} onClick={onProductsOutOfStockClick}>
<TableCell>
{productsOutOfStock === undefined ? (
<Skeleton />
) : productsOutOfStock === 0 ? (
<Typography>
<FormattedMessage
defaultMessage="No products out of stock"
id="homeNotificationsTableNoProducts"
/>
</Typography>
) : (
<Typography>
<FormattedMessage
2020-02-13 11:14:16 +00:00
defaultMessage="{amount, plural,one {One product out of stock}other {{amount} Products out of stock}}"
2019-10-08 14:19:24 +00:00
id="homeNotificationTableProducts"
values={{
amount: <strong>{productsOutOfStock}</strong>
}}
/>
</Typography>
)}
</TableCell>
<TableCell className={classes.arrowIcon}>
<KeyboardArrowRight />
</TableCell>
</TableRow>
</RequirePermissions>
2019-08-27 09:35:54 +00:00
</TableBody>
2019-11-04 14:25:23 +00:00
</ResponsiveTable>
2019-08-27 09:35:54 +00:00
</Card>
2019-10-30 14:34:24 +00:00
);
};
2019-06-19 14:40:52 +00:00
HomeNotificationTable.displayName = "HomeNotificationTable";
export default HomeNotificationTable;