Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add notification table for home page
Lukasz Szewczykce62b0e9ff07
diff --git a/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx b/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsxindex 5b4b2823a4..7039065b7e 100644--- a/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx+++ b/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx@@ -6,6 +6,8 @@ import CardSpacer from "../../../components/CardSpacer";import Container from "../../../components/Container";import PageHeader from "../../../components/PageHeader";import i18n from "../../../i18n";+import HomeNotificationTable from "../HomeNotificationTable";+import HomeOrdersCard from "../HomeOrdersCard";import HomeSalesCard from "../HomeSalesCard";interface MoneyType {@@ -13,10 +15,23 @@ interface MoneyType {currency: string;}export interface DashboardProps {- daily?: {- sales?: MoneyType;+ daily: {+ orders: {+ amount: number;+ };+ sales: MoneyType;+ };+ notifications: {+ orders: number;+ payments: number;+ problems: number;+ productsOut: number;};ownerName: string;+ toOrders: () => void;+ toPayments: () => void;+ toProblems: () => void;+ toProductsOut: () => void;}const decorate = withStyles(theme => ({@@ -39,36 +54,54 @@ const decorate = withStyles(theme => ({}}}));-const Dashboard = decorate<DashboardProps>(({ ownerName, classes, daily }) => {- return (- <Container width="md">- <PageHeader- className={classes.displayBlock}- title={i18n.t("Hello there, {{userName}}", { userName: ownerName })}- >- <Typography component="span">- {i18n.t("Here are some information we gathered about your store")}- </Typography>- </PageHeader>+const Dashboard = decorate<DashboardProps>(+ ({+ ownerName,+ classes,+ daily,+ notifications,+ toOrders,+ toPayments,+ toProblems,+ toProductsOut+ }) => {+ return (+ <Container width="md">+ <PageHeader+ className={classes.displayBlock}+ title={i18n.t("Hello there, {{userName}}", { userName: ownerName })}+ >+ <Typography component="span">+ {i18n.t("Here are some information we gathered about your store")}+ </Typography>+ </PageHeader>- <div className={classes.root}>- <div>- <div className={classes.flexbox}>- <HomeSalesCard disabled={false} title={"Sales"} daily={daily} />- <Card>Orders</Card>- </div>+ <div className={classes.root}>+ <div>+ <div className={classes.flexbox}>+ <HomeSalesCard disabled={false} title={"Sales"} daily={daily} />+ <HomeOrdersCard disabled={false} title={"Orders"} daily={daily} />+ </div>- <CardSpacer />- <Card>Notification</Card>- <CardSpacer />- <Card>ProductListCard</Card>- <CardSpacer />- </div>- <div>- <Card>HomeActivityCard</Card>+ <CardSpacer />+ <HomeNotificationTable+ disabled={false}+ notifications={notifications}+ toOrders={toOrders}+ toPayments={toPayments}+ toProblems={toProblems}+ toProductsOut={toProductsOut}+ />+ <CardSpacer />+ <Card>ProductListCard</Card>+ <CardSpacer />+ </div>+ <div>+ <Card>HomeActivityCard</Card>+ </div></div>- </div>- </Container>- );-});+ </Container>+ );+ }+);export default Dashboard;diff --git a/saleor/static/dashboard-next/home/components/HomeNotificationTable/HomeNotificationTable.tsx b/saleor/static/dashboard-next/home/components/HomeNotificationTable/HomeNotificationTable.tsxnew file mode 100644index 0000000000..234fe54110--- /dev/null+++ b/saleor/static/dashboard-next/home/components/HomeNotificationTable/HomeNotificationTable.tsx@@ -0,0 +1,153 @@+import Card from "@material-ui/core/Card";+import { withStyles } from "@material-ui/core/styles";+import Table from "@material-ui/core/Table";+import TableBody from "@material-ui/core/TableBody";+import TableCell from "@material-ui/core/TableCell";+import TableRow from "@material-ui/core/TableRow";+import Typography from "@material-ui/core/Typography";+import KeyboardArrowRight from "@material-ui/icons/KeyboardArrowRight";+import * as React from "react";+import Skeleton from "../../../components/Skeleton";+import i18n from "../../../i18n";++interface HomeNotificationTableProps {+ disabled: boolean;+ notifications?: {+ id?: number;+ orders?: number;+ payments?: number;+ problems?: number;+ productsOut?: number;+ };+ toOrders?();+ toPayments?();+ toProblems?();+ toProductsOut?();+}++const decorate = withStyles(theme => ({+ arrowIcon: {+ width: theme.spacing.unit * 4+ },+ tableRowPointer: {+ cursor: "pointer" as "pointer"+ }+}));+const HomeNotificationTable = decorate<HomeNotificationTableProps>(+ ({+ classes,+ notifications,+ toOrders,+ toPayments,+ toProblems,+ toProductsOut+ }) => {+ return (+ <Card>+ <Table>+ <TableBody className={classes.tableRowPointer}>+ <TableRow+ hover={true}+ onClick={!!notifications ? toOrders() : undefined}+ >+ <TableCell>+ {notifications === undefined ? (+ <Skeleton />+ ) : notifications && notifications.orders === 0 ? (+ <Typography>{i18n.t("No orders to fulfill")}</Typography>+ ) : (+ <Typography+ dangerouslySetInnerHTML={{+ __html: i18n.t(+ "<b>{{orders}} Orders</b> are ready to fulfill",+ { orders: notifications.orders }+ )+ }}+ />+ )}+ </TableCell>+ <TableCell className={classes.arrowIcon}>+ <KeyboardArrowRight />+ </TableCell>+ </TableRow>+ <TableRow+ hover={true}+ onClick={!!notifications ? toPayments() : undefined}+ >+ <TableCell>+ {notifications === undefined ? (+ <Skeleton />+ ) : notifications.payments === 0 ? (+ <Typography>+ {i18n.t("No payments waiting for capture")}+ </Typography>+ ) : (+ <Typography+ dangerouslySetInnerHTML={{+ __html: i18n.t(+ "<b>{{payments}} Payments </b>to capture",+ { payments: notifications.payments }+ )+ }}+ />+ )}+ </TableCell>+ <TableCell className={classes.arrowIcon}>+ <KeyboardArrowRight />+ </TableCell>+ </TableRow>+ <TableRow+ hover={true}+ onClick={!!notifications ? toProblems() : undefined}+ >+ <TableCell>+ {notifications === undefined ? (+ <Skeleton />+ ) : notifications.problems === 0 ? (+ <Typography>{i18n.t("No problem with orders")}</Typography>+ ) : (+ <Typography+ dangerouslySetInnerHTML={{+ __html: i18n.t(+ "<b>{{problems}} Problems</b> with orders",+ { problems: notifications.problems }+ )+ }}+ />+ )}+ </TableCell>+ <TableCell className={classes.arrowIcon}>+ <KeyboardArrowRight />+ </TableCell>+ </TableRow>+ <TableRow+ hover={true}+ onClick={!!notifications ? toProductsOut() : undefined}+ >+ <TableCell>+ {notifications === undefined ? (+ <Skeleton />+ ) : notifications.productsOut === 0 ? (+ <Typography>{i18n.t("No out of stock products")}</Typography>+ ) : (+ <Typography+ dangerouslySetInnerHTML={{+ __html: i18n.t(+ "<b>{{productsOut}} Products </b>out of stock",+ { productsOut: notifications.productsOut }+ )+ }}+ />+ )}+ </TableCell>+ <TableCell className={classes.arrowIcon}>+ <KeyboardArrowRight />+ </TableCell>+ </TableRow>+ </TableBody>+ </Table>+ </Card>+ );+ }+);+export default HomeNotificationTable;diff --git a/saleor/static/dashboard-next/home/components/HomeNotificationTable/index.ts b/saleor/static/dashboard-next/home/components/HomeNotificationTable/index.tsnew file mode 100644index 0000000000..5f13ce2da7--- /dev/null+++ b/saleor/static/dashboard-next/home/components/HomeNotificationTable/index.ts@@ -0,0 +1,2 @@+export { default } from "./HomeNotificationTable";+export * from "./HomeNotificationTable";diff --git a/saleor/static/dashboard-next/home/components/HomeOrdersCard/HomeOrdersCard.tsx b/saleor/static/dashboard-next/home/components/HomeOrdersCard/HomeOrdersCard.tsxnew file mode 100644index 0000000000..c10d3a1a71--- /dev/null+++ b/saleor/static/dashboard-next/home/components/HomeOrdersCard/HomeOrdersCard.tsx@@ -0,0 +1,85 @@+import Card from "@material-ui/core/Card";+import CardContent from "@material-ui/core/CardContent";+import { withStyles } from "@material-ui/core/styles";+import Typography from "@material-ui/core/Typography";+import LocalShipping from "@material-ui/icons/LocalShipping";+import * as React from "react";+import Skeleton from "../../../components/Skeleton";+import i18n from "../../../i18n";++interface HomeOrdersCardProps {+ disabled: boolean;+ title: string;+ daily: {+ orders: {+ amount: number;+ };+ };+}++const decorate = withStyles(theme => ({+ cardContent: {+ "&:last-child": {+ paddingBottom: 16+ },+ display: "grid" as "grid",+ gridColumnGap: theme.spacing.unit * 1 + "px",+ gridTemplateColumns: "minmax(min-content, 5fr) 70px"+ },+ cardSubtitle: {+ color: theme.palette.text.secondary,+ fontSize: ".65rem",+ height: "16px",+ lineHeight: 0.5+ },+ cardTitle: {+ fontWeight: "bold" as "bold"+ },+ fullWidth: {+ marginLeft: `${theme.spacing.unit * 1.5}px`,+ [theme.breakpoints.down("sm")]: {+ marginLeft: `${theme.spacing.unit * 0.5}px`+ },+ width: "100%"+ },+ icon: {+ color: theme.palette.primary.contrastText,+ fontSize: 54,+ margin: ".5rem .3rem"+ },+ iconBackground: {+ alignSelf: "center",+ backgroundColor: theme.palette.primary.main,+ borderRadius: "5px",+ justifySelf: "center"+ }+}));+const HomeOrdersCard = decorate<HomeOrdersCardProps>(+ ({ classes, title, daily }) => {+ return (+ <Card className={classes.fullWidth}>+ <CardContent className={classes.cardContent}>+ <div>+ <Typography className={classes.cardTitle} variant="subheading">+ {title}+ </Typography>+ <Typography+ className={classes.cardSubtitle}+ variant="caption"+ color="textSecondary"+ >+ {i18n.t("Today")}+ </Typography>+ <Typography color={"textPrimary"} variant="display1">+ {daily && daily.orders ? daily.orders.amount : <Skeleton />}+ </Typography>+ </div>+ <div className={classes.iconBackground}>+ <LocalShipping className={classes.icon} />+ </div>+ </CardContent>+ </Card>+ );+ }+);+export default HomeOrdersCard;diff --git a/saleor/static/dashboard-next/home/components/HomeOrdersCard/index.ts b/saleor/static/dashboard-next/home/components/HomeOrdersCard/index.tsnew file mode 100644index 0000000000..f0b629bb2b--- /dev/null+++ b/saleor/static/dashboard-next/home/components/HomeOrdersCard/index.ts@@ -0,0 +1,2 @@+export { default } from "./HomeOrdersCard";+export * from "./HomeOrdersCard";diff --git a/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsx b/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsxindex 2c6f177e60..315006fd2e 100644--- a/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsx+++ b/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsx@@ -9,11 +9,32 @@ const shop = shopFixture(placeholderImage);const dashboardProps: DashboardProps = {daily: shop.daily,- ownerName: shop.ownerName+ ownerName: shop.ownerName,+ notifications: shop.notifications,+ toOrders: () => undefined,+ toPayments: () => undefined,+ toProblems: () => undefined,+ toProductsOut: () => undefined};storiesOf("Views / Home / Dashboard", module).addDecorator(Decorator).add("default", () => <Dashbaord {...dashboardProps} />)- .add("loading", () => <Dashbaord {...dashboardProps} daily={undefined} />)- .add("no data", () => <Dashbaord {...dashboardProps} />);+ .add("loading", () => (+ <Dashbaord+ {...dashboardProps}+ daily={undefined}+ notifications={undefined}+ />+ ))+ .add("no data", () => (+ <Dashbaord+ {...dashboardProps}+ notifications={{+ orders: 0,+ payments: 0,+ problems: 0,+ productsOut: 0+ }}+ />+ ));