2019-06-19 14:40:52 +00:00
|
|
|
import {
|
|
|
|
createStyles,
|
|
|
|
Theme,
|
|
|
|
withStyles,
|
|
|
|
WithStyles
|
|
|
|
} from "@material-ui/core/styles";
|
2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
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";
|
2019-10-08 14:19:24 +00:00
|
|
|
import { UserPermissionProps } from "@saleor/types";
|
|
|
|
import { PermissionEnum } from "@saleor/types/globalTypes";
|
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-10-28 16:16:49 +00:00
|
|
|
const styles = theme =>
|
2019-06-19 14:40:52 +00:00
|
|
|
createStyles({
|
|
|
|
cardContainer: {
|
|
|
|
display: "grid",
|
2019-10-28 16:16:49 +00:00
|
|
|
gridColumnGap: theme.spacing(3),
|
2019-06-19 14:40:52 +00:00
|
|
|
gridTemplateColumns: "1fr 1fr",
|
|
|
|
[theme.breakpoints.down("sm")]: {
|
2019-10-28 16:16:49 +00:00
|
|
|
gridColumnGap: theme.spacing(1)
|
2019-06-19 14:40:52 +00:00
|
|
|
},
|
|
|
|
[theme.breakpoints.down("xs")]: {
|
|
|
|
gridTemplateColumns: "1fr"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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;
|
|
|
|
ordersToCapture: number;
|
|
|
|
ordersToFulfill: number;
|
|
|
|
productsOutOfStock: number;
|
|
|
|
sales: Home_salesToday_gross;
|
|
|
|
topProducts: Home_productTopToday_edges_node[];
|
|
|
|
userName: string;
|
|
|
|
onOrdersToCaptureClick: () => void;
|
|
|
|
onOrdersToFulfillClick: () => void;
|
|
|
|
onProductClick: (productId: string, variantId: string) => void;
|
|
|
|
onProductsOutOfStockClick: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const HomePage = withStyles(styles, { name: "HomePage" })(
|
|
|
|
({
|
|
|
|
classes,
|
|
|
|
userName,
|
|
|
|
orders,
|
|
|
|
sales,
|
|
|
|
topProducts,
|
|
|
|
onProductClick,
|
|
|
|
activities,
|
|
|
|
onOrdersToCaptureClick,
|
|
|
|
onOrdersToFulfillClick,
|
|
|
|
onProductsOutOfStockClick,
|
|
|
|
ordersToCapture,
|
|
|
|
ordersToFulfill,
|
2019-10-08 14:19:24 +00:00
|
|
|
productsOutOfStock,
|
|
|
|
userPermissions
|
|
|
|
}: HomePageProps & WithStyles<typeof styles>) => (
|
2019-06-19 14:40:52 +00:00
|
|
|
<Container>
|
|
|
|
<HomeHeader userName={userName} />
|
|
|
|
<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"}
|
|
|
|
icon={<Sales fontSize={"inherit"} viewBox="0 0 64 64" />}
|
|
|
|
>
|
|
|
|
{sales ? (
|
|
|
|
<Money money={sales} />
|
|
|
|
) : (
|
|
|
|
<Skeleton style={{ width: "5em" }} />
|
|
|
|
)}
|
|
|
|
</HomeAnalyticsCard>
|
|
|
|
<HomeAnalyticsCard
|
|
|
|
title={"Orders"}
|
|
|
|
icon={<Orders fontSize={"inherit"} viewBox="0 0 64 64" />}
|
|
|
|
>
|
|
|
|
{orders === undefined ? (
|
|
|
|
<Skeleton style={{ width: "5em" }} />
|
|
|
|
) : (
|
|
|
|
orders
|
|
|
|
)}
|
|
|
|
</HomeAnalyticsCard>
|
|
|
|
</div>
|
|
|
|
</RequirePermissions>
|
2019-06-19 14:40:52 +00:00
|
|
|
<HomeNotificationTable
|
|
|
|
onOrdersToCaptureClick={onOrdersToCaptureClick}
|
|
|
|
onOrdersToFulfillClick={onOrdersToFulfillClick}
|
|
|
|
onProductsOutOfStockClick={onProductsOutOfStockClick}
|
|
|
|
ordersToCapture={ordersToCapture}
|
|
|
|
ordersToFulfill={ordersToFulfill}
|
|
|
|
productsOutOfStock={productsOutOfStock}
|
2019-10-08 14:19:24 +00:00
|
|
|
userPermissions={userPermissions}
|
2019-06-19 14:40:52 +00:00
|
|
|
/>
|
|
|
|
<CardSpacer />
|
2019-10-08 14:19:24 +00:00
|
|
|
<RequirePermissions
|
|
|
|
userPermissions={userPermissions}
|
2019-10-08 15:05:31 +00:00
|
|
|
requiredPermissions={[
|
|
|
|
PermissionEnum.MANAGE_ORDERS,
|
|
|
|
PermissionEnum.MANAGE_PRODUCTS
|
|
|
|
]}
|
2019-10-08 14:19:24 +00:00
|
|
|
>
|
|
|
|
<HomeProductListCard
|
|
|
|
onRowClick={onProductClick}
|
|
|
|
topProducts={topProducts}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
</RequirePermissions>
|
2019-06-19 14:40:52 +00:00
|
|
|
</div>
|
|
|
|
<div>
|
2019-10-08 14:19:24 +00:00
|
|
|
<RequirePermissions
|
|
|
|
userPermissions={userPermissions}
|
|
|
|
requiredPermissions={[PermissionEnum.MANAGE_ORDERS]}
|
|
|
|
>
|
|
|
|
<HomeActivityCard activities={activities} />
|
|
|
|
</RequirePermissions>
|
2019-06-19 14:40:52 +00:00
|
|
|
</div>
|
|
|
|
</Grid>
|
|
|
|
</Container>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
HomePage.displayName = "HomePage";
|
|
|
|
export default HomePage;
|