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

162 lines
5.3 KiB
TypeScript
Raw Normal View History

import {
Card,
TableBody,
TableCell,
TableRow,
Typography
} from "@material-ui/core";
2019-06-19 14:40:52 +00:00
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";
Use MacawUI (#1229) * Replace withStyleswith useStyles (#1100) * Replace withStyleswith useStyles * Update messages * Use rem as a spacing unit (#1101) * Use rems as spacing units * Fix visual bugs * Update stories * Use macaw-ui as theme provider (#1108) * Use macaw ui as a theme provider * Add react-dom to aliases * Fix jest module resolution * Update useTheme hook usage * Fix test wrapper * Use macaw from git repo * Fix CI * Update stories * Fix aliasing * Extract savebar to macaw ui (#1146) * wip * Use savebar from macaw * Use confirm button from macaw * Improve file structure * Use sidebar context from macaw * Update macaw * Update macaw version * Remove savebar from storybook * Update stories * Use alerts and notifications from macaw (#1166) * Use alerts from macaw * Add notifications from macaw * Update stories * Pin macaw version * Encapsulate limit reached in one component * Remove unused imports * Use backlinks from macaw (#1183) * Use backlink from macaw * Update macaw version * Use macaw sidebar (#1148) * Use sidebar from macaw * Use shipped logo * Use lowercase * Update stories * Use user chip from macaw (#1191) * Use user chip from macaw * Use dedicated components for menu items * Simplify code * Bump version and fix types (#1210) * Rename onBack to onClick * Rename UserChip to UserChipMenu * Rename IMenuItem to SidebarMenuItem * Update macaw version * Fix tables after changes in macaw (#1220) * Update macaw version * Update changelog * Update stories * Fix after rebase * Update to macaw 0.2.0 * Lint files * Update macaw to 0.2.2
2021-07-21 08:59:52 +00:00
import { makeStyles } from "@saleor/macaw-ui";
2019-10-08 14:19:24 +00:00
import { UserPermissionProps } from "@saleor/types";
import { PermissionEnum } from "@saleor/types/globalTypes";
import React from "react";
import { useIntl } from "react-intl";
import { homeNotificationTableMessages as messages } from "./messages";
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: 100
},
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 && (
<RequirePermissions
userPermissions={userPermissions}
requiredPermissions={[PermissionEnum.MANAGE_CHANNELS]}
>
<TableRow hover={true} onClick={onCreateNewChannelClick}>
<TableCell>
<Typography>
{intl.formatMessage(messages.createNewChannel)}
</Typography>
</TableCell>
<TableCell className={classes.arrowIcon}>
<KeyboardArrowRight />
</TableCell>
</TableRow>
</RequirePermissions>
)}
2019-10-08 14:19:24 +00:00
<RequirePermissions
userPermissions={userPermissions}
requiredPermissions={[PermissionEnum.MANAGE_ORDERS]}
>
<TableRow hover={true} onClick={onOrdersToFulfillClick}>
2021-02-11 12:20:00 +00:00
<TableCell data-test-id="orders-to-fulfill">
2019-10-08 14:19:24 +00:00
{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}>
2021-02-11 12:20:00 +00:00
<TableCell data-test-id="orders-to-capture">
2019-10-08 14:19:24 +00:00
{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}>
2021-02-11 12:20:00 +00:00
<TableCell data-test-id="products-out-of-stock">
2019-10-08 14:19:24 +00:00
{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;