2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
import useNavigator from "@saleor/hooks/useNavigator";
|
|
|
|
import useUser from "@saleor/hooks/useUser";
|
|
|
|
import { getUserName, maybe } from "../../misc";
|
|
|
|
import { orderListUrl } from "../../orders/urls";
|
|
|
|
import { productListUrl, productVariantEditUrl } from "../../products/urls";
|
|
|
|
import { OrderStatusFilter, StockAvailability } from "../../types/globalTypes";
|
|
|
|
import HomePage from "../components/HomePage";
|
|
|
|
import { HomePageQuery } from "../queries";
|
|
|
|
|
|
|
|
const HomeSection = () => {
|
|
|
|
const navigate = useNavigator();
|
|
|
|
const { user } = useUser();
|
|
|
|
|
|
|
|
return (
|
|
|
|
<HomePageQuery displayLoader>
|
|
|
|
{({ 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(productId, variantId))
|
|
|
|
}
|
|
|
|
onOrdersToCaptureClick={() =>
|
|
|
|
navigate(
|
|
|
|
orderListUrl({
|
|
|
|
status: OrderStatusFilter.READY_TO_CAPTURE
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
onOrdersToFulfillClick={() =>
|
|
|
|
navigate(
|
|
|
|
orderListUrl({
|
|
|
|
status: OrderStatusFilter.READY_TO_FULFILL
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
onProductsOutOfStockClick={() =>
|
|
|
|
navigate(
|
|
|
|
productListUrl({
|
|
|
|
status: StockAvailability.OUT_OF_STOCK
|
|
|
|
})
|
|
|
|
)
|
|
|
|
}
|
|
|
|
ordersToCapture={maybe(() => data.ordersToCapture.totalCount)}
|
|
|
|
ordersToFulfill={maybe(() => data.ordersToFulfill.totalCount)}
|
|
|
|
productsOutOfStock={maybe(() => data.productsOutOfStock.totalCount)}
|
|
|
|
userName={getUserName(user, true)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</HomePageQuery>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default HomeSection;
|