Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Connect homepage to API

dominik-zeglenaf135f30bfc4
diff --git a/saleor/static/dashboard-next/home/components/HomeActivityCard/HomeActivityCard.tsx b/saleor/static/dashboard-next/home/components/HomeActivityCard/HomeActivityCard.tsx
index 514aef964e..47964c9a74 100644
--- a/saleor/static/dashboard-next/home/components/HomeActivityCard/HomeActivityCard.tsx
+++ b/saleor/static/dashboard-next/home/components/HomeActivityCard/HomeActivityCard.tsx
@@ -11,14 +11,11 @@ import DateFormatter from "../../../components/DateFormatter";
import Skeleton from "../../../components/Skeleton";
import i18n from "../../../i18n";
import { renderCollection } from "../../../misc";
+import { Home_activities_edges_node } from "../../types/home";
+import { getActivityMessage } from "./activityMessages";
interface HomeProductListCardProps {
- activities?: Array<{
- action: string;
- admin: boolean;
- date: string;
- id: string;
- }>;
+ activities: Home_activities_edges_node[];
}
const decorate = withStyles({
@@ -40,20 +37,12 @@ const HomeProductListCard = decorate<HomeProductListCardProps>(
<List dense={true}>
{renderCollection(
activities,
- activity => (
- <ListItem key={activity ? activity.id : "skeleton"}>
+ (activity, activityId) => (
+ <ListItem key={activityId}>
{activity ? (
<ListItemText
primary={
- <Typography
- dangerouslySetInnerHTML={{
- __html: activity.admin
- ? i18n.t(`Saleor shop admin
- ${activity.action}`)
- : i18n.t(`${activity.action} a
- `)
- }}
- />
+ <Typography>{getActivityMessage(activity)}</Typography>
}
secondary={<DateFormatter date={activity.date} />}
/>
diff --git a/saleor/static/dashboard-next/home/components/HomeActivityCard/activityMessages.ts b/saleor/static/dashboard-next/home/components/HomeActivityCard/activityMessages.ts
new file mode 100644
index 0000000000..8cfa082bb5
--- /dev/null
+++ b/saleor/static/dashboard-next/home/components/HomeActivityCard/activityMessages.ts
@@ -0,0 +1,126 @@
+import i18n from "../../../i18n";
+import { OrderEvents, OrderEventsEmails } from "../../../types/globalTypes";
+import { Home_activities_edges_node } from "../../types/home";
+
+// FIXME: improve messages
+export const getActivityMessage = (activity: Home_activities_edges_node) => {
+ switch (activity.type) {
+ case OrderEvents.CANCELED:
+ return i18n.t("Order {{ id }} had been cancelled by {{ user }}", {
+ id: activity.id,
+ user: activity.user.email
+ });
+ case OrderEvents.EMAIL_SENT:
+ switch (activity.emailType) {
+ case OrderEventsEmails.FULFILLMENT:
+ return i18n.t("Fulfillment confirmation has been sent to customer", {
+ context: "order history message"
+ });
+ case OrderEventsEmails.ORDER:
+ return i18n.t("Order confirmation has been sent to customer", {
+ context: "order history message"
+ });
+ case OrderEventsEmails.PAYMENT:
+ return i18n.t("Payment confirmation has been sent to customer", {
+ context: "order history message"
+ });
+ case OrderEventsEmails.SHIPPING:
+ return i18n.t("Shipping details has been sent to customer", {
+ context: "order history message"
+ });
+ }
+ case OrderEvents.FULFILLMENT_CANCELED:
+ return i18n.t(
+ "Fulfillment {{ fulfillmentId }} in order {{ orderId }} had been cancelled by {{ user }}",
+ {
+ fulfillmentId: activity.composedId,
+ orderId: activity.id,
+ user: activity.user.email
+ }
+ );
+ case OrderEvents.FULFILLMENT_FULFILLED_ITEMS:
+ return i18n.t(
+ "Fulfilled {{ amount }} products in order {{ orderId }} by {{ user }}",
+ {
+ amount: activity.amount,
+ orderId: activity.id,
+ user: activity.user.email
+ }
+ );
+ case OrderEvents.FULFILLMENT_RESTOCKED_ITEMS:
+ return i18n.t(
+ "Restocked {{ amounts }} products in order {{ orderId }} by {{ user }}",
+ {
+ amount: activity.amount,
+ orderId: activity.id,
+ user: activity.user.email
+ }
+ );
+ case OrderEvents.NOTE_ADDED:
+ return i18n.t("Added note to order {{ orderId }} by {{ user }}", {
+ orderId: activity.id,
+ user: activity.user.email
+ });
+ case OrderEvents.ORDER_FULLY_PAID:
+ return i18n.t("Order {{ orderId }} had been fully paid by {{ user }}", {
+ orderId: activity.id
+ // user: activity.user.email
+ });
+ case OrderEvents.ORDER_MARKED_AS_PAID:
+ return i18n.t(
+ "Order {{ orderId }} had been marked as paid by {{ user }}",
+ {
+ orderId: activity.id,
+ user: activity.user.email
+ }
+ );
+ case OrderEvents.OVERSOLD_ITEMS:
+ return i18n.t("Oversold {{ amount }} products in order {{ orderId }}", {
+ amount: activity.amount,
+ orderId: activity.id
+ });
+ case OrderEvents.PAYMENT_CAPTURED:
+ return i18n.t("Captured payment for order {{ orderId }}", {
+ orderId: activity.id
+ });
+ case OrderEvents.PAYMENT_REFUNDED:
+ return i18n.t("Refunded payment for order {{ orderId }} by {{ user }}", {
+ orderId: activity.id,
+ user: activity.user.email
+ });
+ case OrderEvents.PAYMENT_RELEASED:
+ return i18n.t("Released payment for order {{ orderId }} by {{ user }}", {
+ orderId: activity.id,
+ user: activity.user.email
+ });
+ case OrderEvents.PLACED:
+ return i18n.t("Order {{ orderId }} had been placed by {{ user }}", {
+ orderId: activity.id
+ // user: activity.user.email
+ });
+ case OrderEvents.PLACED_FROM_DRAFT:
+ return i18n.t(
+ "Order {{ orderId }} had been placed from draft by {{ user }}",
+ {
+ orderId: activity.id,
+ user: activity.user.email
+ }
+ );
+ case OrderEvents.TRACKING_UPDATED:
+ return i18n.t(
+ "Updated tracking number in fulfillment {{ fulfillmentId }} in order {{ orderId }} by {{ user }}",
+ {
+ fulfillmentId: activity.composedId,
+ orderId: activity.id,
+ user: activity.user.email
+ }
+ );
+ case OrderEvents.UPDATED:
+ return i18n.t("Order {{ orderId }} had been updated by {{ user }}", {
+ orderId: activity.id,
+ user: activity.user.email
+ });
+ default:
+ return activity.message;
+ }
+};
diff --git a/saleor/static/dashboard-next/home/components/HomeAnalyticsCard/HomeAnalyticsCard.tsx b/saleor/static/dashboard-next/home/components/HomeAnalyticsCard/HomeAnalyticsCard.tsx
index 918480cf83..0689608441 100644
--- a/saleor/static/dashboard-next/home/components/HomeAnalyticsCard/HomeAnalyticsCard.tsx
+++ b/saleor/static/dashboard-next/home/components/HomeAnalyticsCard/HomeAnalyticsCard.tsx
@@ -5,7 +5,6 @@ import { withStyles } from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
import * as React from "react";
-import Skeleton from "../../../components/Skeleton";
import i18n from "../../../i18n";
interface HomeAnalyticsCardProps {
@@ -68,7 +67,7 @@ const HomeAnalyticsCard = decorate<HomeAnalyticsCardProps>(
{i18n.t("Today")}
</Typography>
<Typography color={"textPrimary"} variant="headline">
- {children ? children : <Skeleton style={{ width: "5em" }} />}
+ {children}
</Typography>
</div>
<div className={classes.iconBackground}>{icon}</div>
diff --git a/saleor/static/dashboard-next/home/components/HomeHeader/HomeHeader.tsx b/saleor/static/dashboard-next/home/components/HomeHeader/HomeHeader.tsx
index 322d5a515f..ad75f6a045 100644
--- a/saleor/static/dashboard-next/home/components/HomeHeader/HomeHeader.tsx
+++ b/saleor/static/dashboard-next/home/components/HomeHeader/HomeHeader.tsx
@@ -9,16 +9,20 @@ interface HomeOrdersCardProps {
userName: string;
}
-const decorate = withStyles({
+const decorate = withStyles(theme => ({
+ headerContainer: {
+ marginBottom: theme.spacing.unit * 3,
+ marginTop: theme.spacing.unit * 3
+ },
pageHeader: {
fontWeight: 600 as 600
}
-});
+}));
const HomeOrdersCard = decorate<HomeOrdersCardProps>(
({ classes, userName }) => {
return (
- <div>
+ <div className={classes.headerContainer}>
<Typography className={classes.pageHeader} variant={"headline"}>
{userName ? (
i18n.t("Hello there, {{userName}}", { userName })
@@ -26,7 +30,7 @@ const HomeOrdersCard = decorate<HomeOrdersCardProps>(
<Skeleton style={{ width: "10em" }} />
)}
</Typography>
- <Typography variant={"subheading"}>
+ <Typography>
{userName ? (
i18n.t("Here are some information we gathered about your store")
) : (
diff --git a/saleor/static/dashboard-next/home/components/HomePage/HomePage.tsx b/saleor/static/dashboard-next/home/components/HomePage/HomePage.tsx
index be294fa51c..ec0b7e00d9 100644
--- a/saleor/static/dashboard-next/home/components/HomePage/HomePage.tsx
+++ b/saleor/static/dashboard-next/home/components/HomePage/HomePage.tsx
@@ -6,38 +6,25 @@ import * as React from "react";
import CardSpacer from "../../../components/CardSpacer";
import Container from "../../../components/Container";
import Money from "../../../components/Money";
+import Skeleton from "../../../components/Skeleton";
+import { maybe } from "../../../misc";
+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 HomeProductListCard from "../HomeProductListCard";
-interface MoneyType {
- amount: number;
- currency: string;
-}
export interface HomePageProps {
- activities: Array<{
- action: string;
- admin: boolean;
- date: string;
- id: string;
- }>;
- daily: {
- orders: {
- amount: number;
- };
- sales: MoneyType;
- };
+ activities: Home_activities_edges_node[];
+ orders: number;
+ sales: Home_salesToday_gross;
userName: string;
- topProducts: Array<{
- id: string;
- name: string;
- orders: number;
- price: MoneyType;
- thumbnailUrl: string;
- variant: string;
- }>;
- onProductClick?(id: string): () => void;
+ topProducts: Home_productTopToday_edges_node[];
+ onProductClick: (productId: string, variantId: string) => void;
}
const decorate = withStyles(theme => ({
@@ -66,7 +53,15 @@ const decorate = withStyles(theme => ({
}
}));
const HomePage = decorate<HomePageProps>(
- ({ userName, classes, daily, topProducts, onProductClick, activities }) => (
+ ({
+ userName,
+ classes,
+ orders,
+ sales,
+ topProducts,
+ onProductClick,
+ activities
+ }) => (
<Container width="md">
<HomeHeader userName={userName} />
<CardSpacer />
@@ -77,23 +72,24 @@ const HomePage = decorate<HomePageProps>(
title={"Sales"}
icon={<AttachMoney fontSize={"inherit"} />}
>
- {daily && daily.sales ? (
- <Money
- amount={daily.sales.amount}
- currency={daily.sales.currency}
- />
- ) : (
- undefined
+ {maybe(
+ () => (
+ <Money amount={sales.amount} currency={sales.currency} />
+ ),
+ <Skeleton style={{ width: "5em" }} />
)}
</HomeAnalyticsCard>
<HomeAnalyticsCard
title={"Orders"}
icon={<LocalShipping fontSize={"inherit"} />}
>
- {daily && daily.orders ? daily.orders.amount : undefined}
+ {orders === undefined ? (
+ <Skeleton style={{ width: "5em" }} />
+ ) : (
+ orders
+ )}
</HomeAnalyticsCard>
</div>
-
<HomeProductListCard
onRowClick={onProductClick}
topProducts={topProducts}
diff --git a/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductListCard.tsx b/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductListCard.tsx
index 28b8ed9e79..f6c677fd1d 100644
--- a/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductListCard.tsx
+++ b/saleor/static/dashboard-next/home/components/HomeProductListCard/HomeProductListCard.tsx
@@ -13,36 +13,26 @@ import Money from "../../../components/Money";
import Skeleton from "../../../components/Skeleton";
import TableCellAvatar from "../../../components/TableCellAvatar";
import i18n from "../../../i18n";
-import { renderCollection } from "../../../misc";
+import { maybe, renderCollection } from "../../../misc";
+import { Home_productTopToday_edges_node } from "../../types/home";
-interface MoneyType {
- amount: number;
- currency: string;
-}
interface HomeProductListProps {
- topProducts: Array<{
- id: string;
- name: string;
- orders: number;
- price: MoneyType;
- thumbnailUrl: string;
- variant: string;
- }>;
- onRowClick: (id: string) => () => void;
+ topProducts: Home_productTopToday_edges_node[];
+ onRowClick: (productId: string, variantId: string) => void;
}
const decorate = withStyles(theme => ({
avatarProps: {
- height: "64px",
- width: "64px"
+ height: 64,
+ width: 64
},
avatarSpacing: {
paddingBottom: theme.spacing.unit * 2,
paddingTop: theme.spacing.unit * 2
},
noProducts: {
- paddingBottom: "20px",
- paddingTop: "20px"
+ paddingBottom: 20,
+ paddingTop: 20
},
tableRow: {
cursor: "pointer" as "pointer"
@@ -57,31 +47,45 @@ export const HomeProductList = decorate<HomeProductListProps>(
<TableBody>
{renderCollection(
topProducts,
- product => (
+ variant => (
<TableRow
- key={product ? product.id : "skeleton"}
- hover={!!product}
+ key={variant ? variant.id : "skeleton"}
+ hover={!!variant}
className={classNames({
- [classes.tableRow]: !!product
+ [classes.tableRow]: !!variant
})}
- onClick={!!product ? onRowClick(product.id) : undefined}
+ onClick={
+ !!variant
+ ? () => onRowClick(variant.product.id, variant.id)
+ : undefined
+ }
>
<TableCellAvatar
className={classes.avatarSpacing}
- thumbnail={product && product.thumbnailUrl}
+ thumbnail={maybe(() => variant.product.thumbnailUrl)}
avatarProps={classes.avatarProps}
/>
<TableCell>
- {product ? (
+ {variant ? (
<>
- <Typography color={"primary"}>{product.name}</Typography>
+ <Typography color={"primary"}>
+ {variant.product.name}
+ </Typography>
<Typography color={"textSecondary"}>
- {product.variant}
+ {maybe(() =>
+ variant.attributes
+ .map(attribute => attribute.value)
+ .sort(
+ (a, b) => (a.sortOrder > b.sortOrder ? 1 : -1)
+ )
+ .map(attribute => attribute.name)
+ .join(" / ")
+ )}
</Typography>
<Typography color={"textSecondary"}>
{i18n.t("{{ordersCount}} Orders", {
- ordersCount: product.orders
+ ordersCount: variant.quantityOrdered
})}
</Typography>
</>
@@ -92,15 +96,13 @@ export const HomeProductList = decorate<HomeProductListProps>(
<TableCell>
<Typography align={"right"}>
- {product &&
- product.price !== undefined &&
- product.price.amount !== undefined &&
- product.price.currency !== undefined ? (
- <Money
- amount={product.price.amount}
- currency={product.price.currency}
- />
- ) : (
+ {maybe(
+ () => (
+ <Money
+ amount={variant.product.price.amount}
+ currency={variant.product.price.currency}
+ />
+ ),
<Skeleton />
)}
</Typography>
diff --git a/saleor/static/dashboard-next/home/index.tsx b/saleor/static/dashboard-next/home/index.tsx
index 4b81dad399..e7520f23f5 100644
--- a/saleor/static/dashboard-next/home/index.tsx
+++ b/saleor/static/dashboard-next/home/index.tsx
@@ -1,6 +1,6 @@
import * as React from "react";
-import HomePage from "./views/HomePage";
+import HomePage from "./views";
const Component = () => <HomePage />;
diff --git a/saleor/static/dashboard-next/home/queries.ts b/saleor/static/dashboard-next/home/queries.ts
new file mode 100644
index 0000000000..951bf35e4a
--- /dev/null
+++ b/saleor/static/dashboard-next/home/queries.ts
@@ -0,0 +1,93 @@
+import gql from "graphql-tag";
+
+import { TypedQuery } from "../queries";
+import { Home } from "./types/Home";
+
+const home = gql`
+ query Home {
+ salesToday: ordersTotal(period: TODAY) {
+ gross {
+ amount
+ currency
+ }
+ }
+ ordersToday: orders(created: TODAY) {
+ totalCount
+ }
+ ordersToFulfill: orders(status: READY_TO_FULFILL, created: TODAY) {
+ edges {
+ node {
+ id
+ number
+ }
+ }
+ }
+ ordersToCapture: orders(status: READY_TO_CAPTURE, created: TODAY) {
+ edges {
+ node {
+ id
+ number
+ }
+ }
+ }
+ productsOutOfStock: products(stockAvailability: OUT_OF_STOCK) {
+ edges {
+ node {
+ id
+ name
+ }
+ }
+ }
+ productTopToday: reportProductSales(period: TODAY) {
+ edges {
+ node {
+ id
+ revenue(period: TODAY) {
+ gross {
+ amount
+ currency
+ }
+ }
+ attributes {
+ value {
+ id
+ name
+ sortOrder
+ }
+ }
+ product {
+ id
+ name
+ thumbnailUrl
+ price {
+ amount
+ currency
+ }
+ }
+ quantityOrdered
+ }
+ }
+ }
+ activities: homepageEvents {
+ edges {
+ node {
+ amount
+ composedId
+ date
+ email
+ emailType
+ id
+ message
+ oversoldItems
+ quantity
+ type
+ user {
+ id
+ email
+ }
+ }
+ }
+ }
+ }
+`;
+export const HomePageQuery = TypedQuery<Home, {}>(home);
diff --git a/saleor/static/dashboard-next/home/types/Home.ts b/saleor/static/dashboard-next/home/types/Home.ts
new file mode 100644
index 0000000000..5187a67e32
--- /dev/null
+++ b/saleor/static/dashboard-next/home/types/Home.ts
@@ -0,0 +1,169 @@
+/* tslint:disable */
+// This file was automatically generated and should not be edited.
+
+import { OrderEventsEmails, OrderEvents } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL query operation: Home
+// ====================================================
+
+export interface Home_salesToday_gross {
+ __typename: "Money";
+ amount: number;
+ currency: string;
+}
+
+export interface Home_salesToday {
+ __typename: "TaxedMoney";
+ gross: Home_salesToday_gross;
+}
+
+export interface Home_ordersToday {
+ __typename: "OrderCountableConnection";
+ totalCount: number | null;
+}
+
+export interface Home_ordersToFulfill_edges_node {
+ __typename: "Order";
+ id: string;
+ number: string | null;
+}
+
+export interface Home_ordersToFulfill_edges {
+ __typename: "OrderCountableEdge";
+ node: Home_ordersToFulfill_edges_node;
+}
+
+export interface Home_ordersToFulfill {
+ __typename: "OrderCountableConnection";
+ edges: Home_ordersToFulfill_edges[];
+}
+
+export interface Home_ordersToCapture_edges_node {
+ __typename: "Order";
+ id: string;
+ number: string | null;
+}
+
+export interface Home_ordersToCapture_edges {
+ __typename: "OrderCountableEdge";
+ node: Home_ordersToCapture_edges_node;
+}
+
+export interface Home_ordersToCapture {
+ __typename: "OrderCountableConnection";
+ edges: Home_ordersToCapture_edges[];
+}
+
+export interface Home_productsOutOfStock_edges_node {
+ __typename: "Product";
+ id: string;
+ name: string;
+}
+
+export interface Home_productsOutOfStock_edges {
+ __typename: "ProductCountableEdge";
+ node: Home_productsOutOfStock_edges_node;
+}
+
+export interface Home_productsOutOfStock {
+ __typename: "ProductCountableConnection";
+ edges: Home_productsOutOfStock_edges[];
+}
+
+export interface Home_productTopToday_edges_node_revenue_gross {
+ __typename: "Money";
+ amount: number;
+ currency: string;
+}
+
+export interface Home_productTopToday_edges_node_revenue {
+ __typename: "TaxedMoney";
+ gross: Home_productTopToday_edges_node_revenue_gross;
+}
+
+export interface Home_productTopToday_edges_node_attributes_value {
+ __typename: "AttributeValue";
+ id: string;
+ name: string | null;
+ sortOrder: number;
+}
+
+export interface Home_productTopToday_edges_node_attributes {
+ __typename: "SelectedAttribute";
+ value: Home_productTopToday_edges_node_attributes_value | null;
+}
+
+export interface Home_productTopToday_edges_node_product_price {
+ __typename: "Money";
+ amount: number;
+ currency: string;
+}
+
+export interface Home_productTopToday_edges_node_product {
+ __typename: "Product";
+ id: string;
+ name: string;
+ thumbnailUrl: string | null;
+ price: Home_productTopToday_edges_node_product_price | null;
+}
+
+export interface Home_productTopToday_edges_node {
+ __typename: "ProductVariant";
+ id: string;
+ revenue: Home_productTopToday_edges_node_revenue | null;
+ attributes: (Home_productTopToday_edges_node_attributes | null)[] | null;
+ product: Home_productTopToday_edges_node_product;
+ quantityOrdered: number | null;
+}
+
+export interface Home_productTopToday_edges {
+ __typename: "ProductVariantCountableEdge";
+ node: Home_productTopToday_edges_node;
+}
+
+export interface Home_productTopToday {
+ __typename: "ProductVariantCountableConnection";
+ edges: Home_productTopToday_edges[];
+}
+
+export interface Home_activities_edges_node_user {
+ __typename: "User";
+ id: string;
+ email: string;
+}
+
+export interface Home_activities_edges_node {
+ __typename: "OrderEvent";
+ amount: number | null;
+ composedId: string | null;
+ date: any | null;
+ email: string | null;
+ emailType: OrderEventsEmails | null;
+ id: string;
+ message: string | null;
+ oversoldItems: (string | null)[] | null;
+ quantity: number | null;
+ type: OrderEvents | null;
+ user: Home_activities_edges_node_user | null;
+}
+
+export interface Home_activities_edges {
+ __typename: "OrderEventCountableEdge";
+ node: Home_activities_edges_node;
+}
+
+export interface Home_activities {
+ __typename: "OrderEventCountableConnection";
+ edges: Home_activities_edges[];
+}
+
+export interface Home {
+ salesToday: Home_salesToday | null;
+ ordersToday: Home_ordersToday | null;
+ ordersToFulfill: Home_ordersToFulfill | null;
+ ordersToCapture: Home_ordersToCapture | null;
+ productsOutOfStock: Home_productsOutOfStock | null;
+ productTopToday: Home_productTopToday | null;
+ activities: Home_activities | null;
+}
diff --git a/saleor/static/dashboard-next/home/views/HomePage.tsx b/saleor/static/dashboard-next/home/views/HomePage.tsx
deleted file mode 100644
index 383d057728..0000000000
--- a/saleor/static/dashboard-next/home/views/HomePage.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import * as React from "react";
-
-import { UserContext } from "../../auth";
-import { HomeScreen } from "../components/HomeScreen";
-
-const HomePage = () => (
- <UserContext.Consumer>
- {({ user }) => <HomeScreen user={user} />}
- </UserContext.Consumer>
-);
-
-export default HomePage;
diff --git a/saleor/static/dashboard-next/home/views/index.tsx b/saleor/static/dashboard-next/home/views/index.tsx
new file mode 100644
index 0000000000..4068a32e83
--- /dev/null
+++ b/saleor/static/dashboard-next/home/views/index.tsx
@@ -0,0 +1,44 @@
+import * as React from "react";
+
+import { UserContext } from "../../auth";
+import Navigator from "../../components/Navigator";
+import { maybe } from "../../misc";
+import { productVariantEditUrl } from "../../products";
+import HomePage from "../components/HomePage";
+import { HomePageQuery } from "../queries";
+
+const HomeSection = () => (
+ <Navigator>
+ {navigate => (
+ <UserContext.Consumer>
+ {({ user }) => (
+ <HomePageQuery>
+ {({ data }) => (
+ <HomePage
+ activities={maybe(() =>
+ data.activities.edges.map(edge => edge.node).reverse()
+ )}
+ orders={maybe(() => data.ordersToday.totalCount)}
+ sales={maybe(() => data.salesToday.gross)}
+ topProducts={maybe(() =>
+ data.productTopToday.edges.map(edge => edge.node)
+ )}
+ onProductClick={(productId, variantId) =>
+ navigate(
+ productVariantEditUrl(
+ encodeURIComponent(productId),
+ encodeURIComponent(variantId)
+ )
+ )
+ }
+ userName={user.email}
+ />
+ )}
+ </HomePageQuery>
+ )}
+ </UserContext.Consumer>
+ )}
+ </Navigator>
+);
+
+export default HomeSection;