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

186 lines
6 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 { defineMessages, useIntl } from "react-intl";
const messages = defineMessages({
createNewChannel: {
defaultMessage: "Create new channel"
},
noOrders: {
defaultMessage: "No orders ready to fulfill",
id: "homeNotificationTableNoOrders"
},
noPaymentWaiting: {
defaultMessage: "No payments waiting for capture",
id: "homeNotificationsNoPayments"
},
noProductsOut: {
defaultMessage: "No products out of stock",
id: "homeNotificationsTableNoProducts"
},
orderReady: {
defaultMessage:
"{amount, plural,one {One order is ready to fulfill} other {{amount} Orders are ready to fulfill}}",
id: "homeNotificationTableOrders"
},
paymentCapture: {
defaultMessage:
"{amount, plural,one {One payment to capture}other {{amount} Payments to capture}}",
id: "homeNotificationTablePayments"
},
productOut: {
defaultMessage:
"{amount, plural,one {One product out of stock}other {{amount} Products out of stock}}",
id: "homeNotificationTableProducts"
}
});
2019-06-19 14:40:52 +00:00
2019-12-03 15:28:40 +00:00
const useStyles = makeStyles(
() => ({
2019-12-03 15:28:40 +00:00
arrowIcon: {
textAlign: "right",
width: "auto"
},
tableCard: {
overflow: "hidden"
2019-12-03 15:28:40 +00:00
},
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;
onCreateNewChannelClick: () => void;
2019-06-19 14:40:52 +00:00
onOrdersToFulfillClick: () => void;
onOrdersToCaptureClick: () => void;
onProductsOutOfStockClick: () => void;
noChannel: boolean;
2019-06-19 14:40:52 +00:00
}
2019-10-30 14:34:24 +00:00
const HomeNotificationTable: React.FC<HomeNotificationTableProps> = props => {
const {
onCreateNewChannelClick,
2019-06-19 14:40:52 +00:00
onOrdersToCaptureClick,
onOrdersToFulfillClick,
onProductsOutOfStockClick,
ordersToCapture,
ordersToFulfill,
2019-10-08 14:19:24 +00:00
productsOutOfStock,
userPermissions,
noChannel
2019-10-30 14:34:24 +00:00
} = props;
const classes = useStyles(props);
const intl = useIntl();
2019-10-30 14:34:24 +00:00
return (
<Card className={classes.tableCard}>
2019-11-04 14:25:23 +00:00
<ResponsiveTable>
2019-08-27 09:35:54 +00:00
<TableBody className={classes.tableRow}>
{noChannel && (
<TableRow hover={true} onClick={onCreateNewChannelClick}>
<TableCell>
<Typography>
{intl.formatMessage(messages.createNewChannel)}
</Typography>
</TableCell>
<TableCell className={classes.arrowIcon}>
<KeyboardArrowRight />
</TableCell>
</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>
{intl.formatMessage(messages.noOrders)}
2019-10-08 14:19:24 +00:00
</Typography>
) : (
<Typography>
{intl.formatMessage(messages.orderReady, {
amount: <strong>{ordersToFulfill}</strong>
})}
2019-10-08 14:19:24 +00:00
</Typography>
)}
</TableCell>
<TableCell className={classes.arrowIcon}>
<KeyboardArrowRight />
</TableCell>
</TableRow>
<TableRow hover={true} onClick={onOrdersToCaptureClick}>
<TableCell>
{ordersToCapture === undefined ? (
<Skeleton />
) : ordersToCapture === 0 ? (
<Typography>
{intl.formatMessage(messages.noPaymentWaiting)}
2019-10-08 14:19:24 +00:00
</Typography>
) : (
<Typography>
{intl.formatMessage(messages.paymentCapture, {
amount: <strong>{ordersToCapture}</strong>
})}
2019-10-08 14:19:24 +00:00
</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>
{intl.formatMessage(messages.noProductsOut)}
2019-10-08 14:19:24 +00:00
</Typography>
) : (
<Typography>
{intl.formatMessage(messages.productOut, {
amount: <strong>{productsOutOfStock}</strong>
})}
2019-10-08 14:19:24 +00:00
</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;