2023-02-20 15:21:28 +00:00
|
|
|
import { Content } from "@dashboard/components/AppLayout/Content";
|
|
|
|
import { DetailedContent } from "@dashboard/components/AppLayout/DetailedContent";
|
|
|
|
import { RightSidebar } from "@dashboard/components/AppLayout/RightSidebar";
|
|
|
|
import { TopNav } from "@dashboard/components/AppLayout/TopNav";
|
2023-01-16 09:45:12 +00:00
|
|
|
import CardSpacer from "@dashboard/components/CardSpacer";
|
|
|
|
import Money from "@dashboard/components/Money";
|
|
|
|
import RequirePermissions from "@dashboard/components/RequirePermissions";
|
|
|
|
import Skeleton from "@dashboard/components/Skeleton";
|
|
|
|
import { HomeQuery, PermissionEnum } from "@dashboard/graphql";
|
|
|
|
import { RelayToFlat } from "@dashboard/types";
|
2021-07-21 08:59:52 +00:00
|
|
|
import { makeStyles } from "@saleor/macaw-ui";
|
2023-02-20 15:21:28 +00:00
|
|
|
import { Box } from "@saleor/macaw-ui/next";
|
2020-05-14 09:30:32 +00:00
|
|
|
import React from "react";
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
import Orders from "../../../icons/Orders";
|
|
|
|
import Sales from "../../../icons/Sales";
|
|
|
|
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")]: {
|
2022-06-21 09:36:55 +00:00
|
|
|
gridColumnGap: theme.spacing(1),
|
2019-12-03 15:28:40 +00:00
|
|
|
},
|
|
|
|
[theme.breakpoints.down("xs")]: {
|
2022-06-21 09:36:55 +00:00
|
|
|
gridTemplateColumns: "1fr",
|
|
|
|
},
|
2020-04-15 18:08:14 +00:00
|
|
|
},
|
|
|
|
icon: {
|
2020-05-14 09:30:32 +00:00
|
|
|
"& path": {
|
2022-06-21 09:36:55 +00:00
|
|
|
fill: theme.palette.primary.main,
|
|
|
|
},
|
|
|
|
},
|
2019-12-03 15:28:40 +00:00
|
|
|
}),
|
2022-06-21 09:36:55 +00:00
|
|
|
{ name: "HomePage" },
|
2019-12-03 15:28:40 +00:00
|
|
|
);
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2022-03-01 08:38:23 +00:00
|
|
|
export interface HomePageProps {
|
2022-03-09 08:56:55 +00:00
|
|
|
activities: RelayToFlat<HomeQuery["activities"]>;
|
2021-01-13 09:33:38 +00:00
|
|
|
orders: number | null;
|
|
|
|
ordersToCapture: number | null;
|
|
|
|
ordersToFulfill: number | null;
|
2019-06-19 14:40:52 +00:00
|
|
|
productsOutOfStock: number;
|
2022-03-09 08:56:55 +00:00
|
|
|
sales: HomeQuery["salesToday"]["gross"];
|
|
|
|
topProducts: RelayToFlat<HomeQuery["productTopToday"]> | null;
|
2019-06-19 14:40:52 +00:00
|
|
|
userName: string;
|
2022-05-06 08:59:55 +00:00
|
|
|
createNewChannelHref: string;
|
|
|
|
ordersToFulfillHref: string;
|
|
|
|
ordersToCaptureHref: string;
|
|
|
|
productsOutOfStockHref: string;
|
2021-01-13 09:33:38 +00:00
|
|
|
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,
|
|
|
|
activities,
|
2022-05-06 08:59:55 +00:00
|
|
|
createNewChannelHref,
|
|
|
|
ordersToFulfillHref,
|
|
|
|
ordersToCaptureHref,
|
|
|
|
productsOutOfStockHref,
|
2021-01-13 09:33:38 +00:00
|
|
|
ordersToCapture = 0,
|
|
|
|
ordersToFulfill = 0,
|
|
|
|
productsOutOfStock = 0,
|
2022-06-21 09:36:55 +00:00
|
|
|
noChannel,
|
2019-10-30 14:34:24 +00:00
|
|
|
} = props;
|
|
|
|
|
|
|
|
const classes = useStyles(props);
|
|
|
|
|
|
|
|
return (
|
2023-02-20 15:21:28 +00:00
|
|
|
<DetailedContent>
|
|
|
|
<TopNav title={<HomeHeader userName={userName} />} />
|
2023-02-22 13:00:03 +00:00
|
|
|
<Content noSavebar>
|
2023-02-20 15:21:28 +00:00
|
|
|
<Box paddingLeft={9} paddingRight={11}>
|
|
|
|
<CardSpacer />
|
2019-10-08 14:19:24 +00:00
|
|
|
<RequirePermissions
|
|
|
|
requiredPermissions={[PermissionEnum.MANAGE_ORDERS]}
|
|
|
|
>
|
|
|
|
<div className={classes.cardContainer}>
|
|
|
|
<HomeAnalyticsCard
|
|
|
|
title={"Sales"}
|
2021-02-11 12:20:00 +00:00
|
|
|
testId="sales-analytics"
|
2020-05-14 09:30:32 +00:00
|
|
|
icon={
|
|
|
|
<Sales
|
|
|
|
className={classes.icon}
|
|
|
|
fontSize={"inherit"}
|
|
|
|
viewBox="0 0 64 64"
|
|
|
|
/>
|
|
|
|
}
|
2019-10-08 14:19:24 +00:00
|
|
|
>
|
2021-01-13 09:33:38 +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"
|
2020-05-14 09:30:32 +00:00
|
|
|
icon={
|
|
|
|
<Orders
|
|
|
|
className={classes.icon}
|
|
|
|
fontSize={"inherit"}
|
|
|
|
viewBox="0 0 64 64"
|
|
|
|
/>
|
|
|
|
}
|
2019-10-08 14:19:24 +00:00
|
|
|
>
|
2021-01-13 09:33:38 +00:00
|
|
|
{noChannel ? (
|
|
|
|
0
|
|
|
|
) : orders !== undefined ? (
|
2019-10-08 14:19:24 +00:00
|
|
|
orders
|
2021-01-13 09:33:38 +00:00
|
|
|
) : (
|
|
|
|
<Skeleton style={{ width: "5em" }} />
|
2019-10-08 14:19:24 +00:00
|
|
|
)}
|
|
|
|
</HomeAnalyticsCard>
|
|
|
|
</div>
|
|
|
|
</RequirePermissions>
|
2019-06-19 14:40:52 +00:00
|
|
|
<HomeNotificationTable
|
2022-05-06 08:59:55 +00:00
|
|
|
createNewChannelHref={createNewChannelHref}
|
|
|
|
ordersToFulfillHref={ordersToFulfillHref}
|
|
|
|
ordersToCaptureHref={ordersToCaptureHref}
|
|
|
|
productsOutOfStockHref={productsOutOfStockHref}
|
2019-06-19 14:40:52 +00:00
|
|
|
ordersToCapture={ordersToCapture}
|
|
|
|
ordersToFulfill={ordersToFulfill}
|
|
|
|
productsOutOfStock={productsOutOfStock}
|
2021-01-13 09:33:38 +00:00
|
|
|
noChannel={noChannel}
|
2019-06-19 14:40:52 +00:00
|
|
|
/>
|
|
|
|
<CardSpacer />
|
2021-01-13 09:33:38 +00:00
|
|
|
{topProducts && (
|
|
|
|
<RequirePermissions
|
|
|
|
requiredPermissions={[
|
|
|
|
PermissionEnum.MANAGE_ORDERS,
|
2022-06-21 09:36:55 +00:00
|
|
|
PermissionEnum.MANAGE_PRODUCTS,
|
2021-01-13 09:33:38 +00:00
|
|
|
]}
|
|
|
|
>
|
|
|
|
<HomeProductListCard
|
2021-02-11 12:20:00 +00:00
|
|
|
testId="top-products"
|
2021-01-13 09:33:38 +00:00
|
|
|
topProducts={topProducts}
|
|
|
|
/>
|
|
|
|
<CardSpacer />
|
|
|
|
</RequirePermissions>
|
|
|
|
)}
|
2023-02-20 15:21:28 +00:00
|
|
|
</Box>
|
|
|
|
</Content>
|
|
|
|
{activities && (
|
2023-02-22 13:00:03 +00:00
|
|
|
<RightSidebar noSavebar>
|
2023-02-20 15:21:28 +00:00
|
|
|
<RequirePermissions
|
|
|
|
requiredPermissions={[PermissionEnum.MANAGE_ORDERS]}
|
|
|
|
>
|
|
|
|
<HomeActivityCard activities={activities} testId="activity-card" />
|
|
|
|
</RequirePermissions>
|
|
|
|
</RightSidebar>
|
|
|
|
)}
|
|
|
|
</DetailedContent>
|
2019-10-30 14:34:24 +00:00
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
HomePage.displayName = "HomePage";
|
|
|
|
export default HomePage;
|