2023-02-20 15:21:28 +00:00
|
|
|
import { TopNav } from "@dashboard/components/AppLayout/TopNav";
|
2023-01-16 09:45:12 +00:00
|
|
|
import CardSpacer from "@dashboard/components/CardSpacer";
|
2023-02-28 09:33:16 +00:00
|
|
|
import { DetailPageLayout } from "@dashboard/components/Layouts";
|
2023-01-16 09:45:12 +00:00
|
|
|
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";
|
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";
|
2023-03-30 07:58:19 +00:00
|
|
|
import { useIntl } from "react-intl";
|
2020-05-14 09:30:32 +00:00
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
import HomeActivityCard from "../HomeActivityCard";
|
|
|
|
import HomeAnalyticsCard from "../HomeAnalyticsCard";
|
|
|
|
import HomeHeader from "../HomeHeader";
|
|
|
|
import HomeNotificationTable from "../HomeNotificationTable/HomeNotificationTable";
|
|
|
|
import HomeProductListCard from "../HomeProductListCard";
|
2023-03-30 07:58:19 +00:00
|
|
|
import { homePageMessages } from "./messages";
|
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;
|
2023-03-30 07:58:19 +00:00
|
|
|
const intl = useIntl();
|
2019-10-30 14:34:24 +00:00
|
|
|
|
|
|
|
return (
|
2023-02-28 09:33:16 +00:00
|
|
|
<DetailPageLayout withSavebar={false}>
|
2023-02-20 15:21:28 +00:00
|
|
|
<TopNav title={<HomeHeader userName={userName} />} />
|
2023-02-28 09:33:16 +00:00
|
|
|
<DetailPageLayout.Content>
|
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]}
|
|
|
|
>
|
2023-03-30 07:58:19 +00:00
|
|
|
<Box
|
|
|
|
display="grid"
|
|
|
|
__gridTemplateColumns="repeat(2, 1fr)"
|
|
|
|
gap={8}
|
|
|
|
marginBottom={8}
|
|
|
|
>
|
2019-10-08 14:19:24 +00:00
|
|
|
<HomeAnalyticsCard
|
2023-03-30 07:58:19 +00:00
|
|
|
title={intl.formatMessage(homePageMessages.salesCardTitle)}
|
2021-02-11 12:20:00 +00:00
|
|
|
testId="sales-analytics"
|
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
|
2023-03-30 07:58:19 +00:00
|
|
|
title={intl.formatMessage(homePageMessages.ordersCardTitle)}
|
2021-02-11 12:20:00 +00:00
|
|
|
testId="orders-analytics"
|
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>
|
2023-03-30 07:58:19 +00:00
|
|
|
</Box>
|
2019-10-08 14:19:24 +00:00
|
|
|
</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>
|
2023-02-28 09:33:16 +00:00
|
|
|
</DetailPageLayout.Content>
|
2023-02-20 15:21:28 +00:00
|
|
|
{activities && (
|
2023-02-28 09:33:16 +00:00
|
|
|
<DetailPageLayout.RightSidebar>
|
2023-02-20 15:21:28 +00:00
|
|
|
<RequirePermissions
|
|
|
|
requiredPermissions={[PermissionEnum.MANAGE_ORDERS]}
|
|
|
|
>
|
|
|
|
<HomeActivityCard activities={activities} testId="activity-card" />
|
|
|
|
</RequirePermissions>
|
2023-02-28 09:33:16 +00:00
|
|
|
</DetailPageLayout.RightSidebar>
|
2023-02-20 15:21:28 +00:00
|
|
|
)}
|
2023-02-28 09:33:16 +00:00
|
|
|
</DetailPageLayout>
|
2019-10-30 14:34:24 +00:00
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
HomePage.displayName = "HomePage";
|
|
|
|
export default HomePage;
|