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

184 lines
5.5 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import CardSpacer from "@saleor/components/CardSpacer";
import Container from "@saleor/components/Container";
import Grid from "@saleor/components/Grid";
import Money from "@saleor/components/Money";
2019-10-08 14:19:24 +00:00
import RequirePermissions from "@saleor/components/RequirePermissions";
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";
2019-06-19 14:40:52 +00:00
import Orders from "../../../icons/Orders";
import Sales from "../../../icons/Sales";
import {
Home_activities_edges_node,
Home_productTopToday_edges_node,
Home_salesToday_gross
} from "../../types/Home";
import HomeActivityCard from "../HomeActivityCard";
import HomeAnalyticsCard from "../HomeAnalyticsCard";
import HomeHeader from "../HomeHeader";
import HomeNotificationTable from "../HomeNotificationTable/HomeNotificationTable";
import HomeProductListCard from "../HomeProductListCard";
2019-12-03 15:28:40 +00:00
const useStyles = makeStyles(
theme => ({
cardContainer: {
display: "grid",
gridColumnGap: theme.spacing(3),
gridTemplateColumns: "1fr 1fr",
[theme.breakpoints.down("sm")]: {
gridColumnGap: theme.spacing(1)
},
[theme.breakpoints.down("xs")]: {
gridTemplateColumns: "1fr"
}
},
icon: {
"& path": {
fill: theme.palette.primary.main
}
}
2019-12-03 15:28:40 +00:00
}),
{ name: "HomePage" }
);
2019-06-19 14:40:52 +00:00
2019-10-08 14:19:24 +00:00
export interface HomePageProps extends UserPermissionProps {
2019-06-19 14:40:52 +00:00
activities: Home_activities_edges_node[];
orders: number | null;
ordersToCapture: number | null;
ordersToFulfill: number | null;
2019-06-19 14:40:52 +00:00
productsOutOfStock: number;
sales: Home_salesToday_gross;
topProducts: Home_productTopToday_edges_node[] | null;
2019-06-19 14:40:52 +00:00
userName: string;
onCreateNewChannelClick: () => void;
2019-06-19 14:40:52 +00:00
onOrdersToCaptureClick: () => void;
onOrdersToFulfillClick: () => void;
onProductClick: (productId: string, variantId: string) => void;
onProductsOutOfStockClick: () => void;
noChannel: boolean;
2019-06-19 14:40:52 +00:00
}
2019-10-30 14:34:24 +00:00
const HomePage: React.FC<HomePageProps> = props => {
const {
2019-06-19 14:40:52 +00:00
userName,
orders,
sales,
topProducts,
onProductClick,
activities,
onCreateNewChannelClick,
2019-06-19 14:40:52 +00:00
onOrdersToCaptureClick,
onOrdersToFulfillClick,
onProductsOutOfStockClick,
ordersToCapture = 0,
ordersToFulfill = 0,
productsOutOfStock = 0,
userPermissions = [],
noChannel
2019-10-30 14:34:24 +00:00
} = props;
const classes = useStyles(props);
return (
2019-06-19 14:40:52 +00:00
<Container>
<HomeHeader userName={userName} />
2019-06-19 14:40:52 +00:00
<CardSpacer />
<Grid>
<div>
2019-10-08 14:19:24 +00:00
<RequirePermissions
userPermissions={userPermissions}
requiredPermissions={[PermissionEnum.MANAGE_ORDERS]}
>
<div className={classes.cardContainer}>
<HomeAnalyticsCard
title={"Sales"}
2021-02-11 12:20:00 +00:00
testId="sales-analytics"
icon={
<Sales
className={classes.icon}
fontSize={"inherit"}
viewBox="0 0 64 64"
/>
}
2019-10-08 14:19:24 +00:00
>
{noChannel ? (
0
) : sales ? (
2019-10-08 14:19:24 +00:00
<Money money={sales} />
) : (
<Skeleton style={{ width: "5em" }} />
)}
</HomeAnalyticsCard>
<HomeAnalyticsCard
title={"Orders"}
2021-02-11 12:20:00 +00:00
testId="orders-analytics"
icon={
<Orders
className={classes.icon}
fontSize={"inherit"}
viewBox="0 0 64 64"
/>
}
2019-10-08 14:19:24 +00:00
>
{noChannel ? (
0
) : orders !== undefined ? (
2019-10-08 14:19:24 +00:00
orders
) : (
<Skeleton style={{ width: "5em" }} />
2019-10-08 14:19:24 +00:00
)}
</HomeAnalyticsCard>
</div>
</RequirePermissions>
2019-06-19 14:40:52 +00:00
<HomeNotificationTable
onCreateNewChannelClick={onCreateNewChannelClick}
2019-06-19 14:40:52 +00:00
onOrdersToCaptureClick={onOrdersToCaptureClick}
onOrdersToFulfillClick={onOrdersToFulfillClick}
onProductsOutOfStockClick={onProductsOutOfStockClick}
ordersToCapture={ordersToCapture}
ordersToFulfill={ordersToFulfill}
productsOutOfStock={productsOutOfStock}
2019-10-08 14:19:24 +00:00
userPermissions={userPermissions}
noChannel={noChannel}
2019-06-19 14:40:52 +00:00
/>
<CardSpacer />
{topProducts && (
<RequirePermissions
userPermissions={userPermissions}
requiredPermissions={[
PermissionEnum.MANAGE_ORDERS,
PermissionEnum.MANAGE_PRODUCTS
]}
>
<HomeProductListCard
2021-02-11 12:20:00 +00:00
testId="top-products"
onRowClick={onProductClick}
topProducts={topProducts}
/>
<CardSpacer />
</RequirePermissions>
)}
2019-06-19 14:40:52 +00:00
</div>
{activities && (
<div>
<RequirePermissions
userPermissions={userPermissions}
requiredPermissions={[PermissionEnum.MANAGE_ORDERS]}
>
2021-02-11 12:20:00 +00:00
<HomeActivityCard
activities={activities}
testId="activity-card"
/>
</RequirePermissions>
</div>
)}
2019-06-19 14:40:52 +00:00
</Grid>
</Container>
2019-10-30 14:34:24 +00:00
);
};
2019-06-19 14:40:52 +00:00
HomePage.displayName = "HomePage";
export default HomePage;