Skip to content

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

Rewrite analytics cards into one component

Lukasz Szewczyk56c5eba6b34b
diff --git a/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx b/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx
index 20db9470ca..b8f029d8c9 100644
--- a/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx
+++ b/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx
@@ -1,13 +1,15 @@
import { withStyles } from "@material-ui/core/styles";
import * as React from "react";
+import AttachMoney from "@material-ui/icons/AttachMoney";
+import LocalShipping from "@material-ui/icons/LocalShipping";
import CardSpacer from "../../../components/CardSpacer";
import Container from "../../../components/Container";
+import Money from "../../../components/Money";
import HomeActivityCard from "../HomeActivityCard";
+import HomeAnalyticsCard from "../HomeAnalyticsCard";
import HomeHeader from "../HomeHeader";
-import HomeOrdersCard from "../HomeOrdersCard";
import HomeProductListCard from "../HomeProductListCard";
-import HomeSalesCard from "../HomeSalesCard";
interface MoneyType {
amount: number;
@@ -46,10 +48,10 @@ const decorate = withStyles(theme => ({
display: "grid",
gridColumnGap: `${theme.spacing.unit * 3}px`,
gridTemplateColumns: "1fr 1fr",
- [theme.breakpoints.down("md")]: {
+ [theme.breakpoints.down("sm")]: {
gridColumnGap: `${theme.spacing.unit}px`
},
- [theme.breakpoints.down("sm")]: {
+ [theme.breakpoints.down("xs")]: {
gridTemplateColumns: "1fr"
}
},
@@ -58,7 +60,7 @@ const decorate = withStyles(theme => ({
display: "grid" as "grid",
gridColumnGap: `${theme.spacing.unit * 3}px`,
gridTemplateColumns: "2fr 1fr",
- [theme.breakpoints.down("md")]: {
+ [theme.breakpoints.down("sm")]: {
gridColumnGap: `${theme.spacing.unit}px`
},
[theme.breakpoints.down("sm")]: {
@@ -75,11 +77,27 @@ const Dashboard = decorate<DashboardProps>(
<div className={classes.root}>
<div>
<div className={classes.cardContainer}>
- <HomeSalesCard disabled={false} title={"Sales"} daily={daily} />
- <HomeOrdersCard disabled={false} title={"Orders"} daily={daily} />
+ <HomeAnalyticsCard
+ title={"Sales"}
+ icon={<AttachMoney fontSize={"inherit"} />}
+ >
+ {daily && daily.sales ? (
+ <Money
+ amount={daily.sales.amount}
+ currency={daily.sales.currency}
+ />
+ ) : (
+ undefined
+ )}
+ </HomeAnalyticsCard>
+ <HomeAnalyticsCard
+ title={"Orders"}
+ icon={<LocalShipping fontSize={"inherit"} />}
+ >
+ {daily && daily.orders ? daily.orders.amount : undefined}
+ </HomeAnalyticsCard>
</div>
- <CardSpacer />
<HomeProductListCard
onRowClick={onRowClick}
disabled={false}
diff --git a/saleor/static/dashboard-next/home/components/HomeAnalyticsCard/HomeAnalyticsCard.tsx b/saleor/static/dashboard-next/home/components/HomeAnalyticsCard/HomeAnalyticsCard.tsx
new file mode 100644
index 0000000000..9114f8bf49
--- /dev/null
+++ b/saleor/static/dashboard-next/home/components/HomeAnalyticsCard/HomeAnalyticsCard.tsx
@@ -0,0 +1,78 @@
+import Card from "@material-ui/core/Card";
+import CardContent from "@material-ui/core/CardContent";
+import { IconProps } from "@material-ui/core/Icon";
+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 {
+ icon: React.ReactElement<IconProps>;
+ title: string;
+ children?: React.ReactNode;
+}
+
+const decorate = withStyles(theme => ({
+ cardContent: {
+ "&:last-child": {
+ paddingBottom: 16
+ },
+ display: "grid" as "grid",
+ gridColumnGap: theme.spacing.unit * 1 + "px",
+ gridTemplateColumns: "1fr 64px"
+ },
+ cardSpacing: {
+ [theme.breakpoints.down("sm")]: {
+ marginBottom: theme.spacing.unit
+ },
+ marginBottom: theme.spacing.unit * 3
+ },
+ cardSubtitle: {
+ color: theme.palette.text.secondary,
+ height: "20px",
+ lineHeight: 0.9
+ },
+ cardTitle: {
+ fontWeight: 600 as 600
+ },
+ icon: {
+ color: theme.palette.primary.contrastText,
+ fontSize: 54,
+ margin: ".5rem .3rem"
+ },
+ iconBackground: {
+ backgroundColor: theme.palette.primary.main,
+ borderRadius: "8px",
+ color: "white",
+ fontSize: "54px",
+ height: "100%",
+ padding: "10px 5px 0px 5px",
+ width: "100%"
+ }
+}));
+const HomeAnalyticsCard = decorate<HomeAnalyticsCardProps>(
+ ({ children, classes, title, icon }) => (
+ <Card className={classes.cardSpacing}>
+ <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="headline">
+ {children ? children : <Skeleton style={{ width: "5em" }} />}
+ </Typography>
+ </div>
+ <div className={classes.iconBackground}>{icon}</div>
+ </CardContent>
+ </Card>
+ )
+);
+export default HomeAnalyticsCard;
diff --git a/saleor/static/dashboard-next/home/components/HomeAnalyticsCard/index.ts b/saleor/static/dashboard-next/home/components/HomeAnalyticsCard/index.ts
new file mode 100644
index 0000000000..209b4b54ea
--- /dev/null
+++ b/saleor/static/dashboard-next/home/components/HomeAnalyticsCard/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./HomeAnalyticsCard";
+export * from "./HomeAnalyticsCard";
diff --git a/saleor/static/dashboard-next/home/components/HomeOrdersCard/HomeOrdersCard.tsx b/saleor/static/dashboard-next/home/components/HomeOrdersCard/HomeOrdersCard.tsx
deleted file mode 100644
index 85fd42006b..0000000000
--- a/saleor/static/dashboard-next/home/components/HomeOrdersCard/HomeOrdersCard.tsx
+++ /dev/null
@@ -1,81 +0,0 @@
-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: {
- 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="headline">
- {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.ts
deleted file mode 100644
index f0b629bb2b..0000000000
--- a/saleor/static/dashboard-next/home/components/HomeOrdersCard/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { default } from "./HomeOrdersCard";
-export * from "./HomeOrdersCard";
diff --git a/saleor/static/dashboard-next/home/components/HomeSalesCard/HomeSalesCard.tsx b/saleor/static/dashboard-next/home/components/HomeSalesCard/HomeSalesCard.tsx
deleted file mode 100644
index 943e93a6e9..0000000000
--- a/saleor/static/dashboard-next/home/components/HomeSalesCard/HomeSalesCard.tsx
+++ /dev/null
@@ -1,94 +0,0 @@
-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 i18n from "../../../i18n";
-
-import Dollar from "@material-ui/icons/AttachMoney";
-import * as React from "react";
-
-import Money from "../../../components/Money";
-import Skeleton from "../../../components/Skeleton";
-
-interface MoneyType {
- amount: number;
- currency: string;
-}
-
-interface HomeSalesCardProps {
- disabled: boolean;
- title: string;
- daily: {
- sales: MoneyType;
- };
-}
-
-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: {
- 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 HomeSalesCard = decorate<HomeSalesCardProps>(
- ({ 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">
- {i18n.t("Today")}
- </Typography>
- <Typography color={"textPrimary"} variant="headline">
- {daily &&
- daily.sales &&
- daily.sales.amount !== undefined &&
- daily.sales.currency !== undefined ? (
- <Money
- amount={daily.sales.amount}
- currency={daily.sales.currency}
- />
- ) : (
- <Skeleton />
- )}
- </Typography>
- </div>
- <div className={classes.iconBackground}>
- <Dollar className={classes.icon} />
- </div>
- </CardContent>
- </Card>
- );
- }
-);
-export default HomeSalesCard;
diff --git a/saleor/static/dashboard-next/home/components/HomeSalesCard/index.ts b/saleor/static/dashboard-next/home/components/HomeSalesCard/index.ts
deleted file mode 100644
index c230853102..0000000000
--- a/saleor/static/dashboard-next/home/components/HomeSalesCard/index.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-export { default } from "./HomeSalesCard";
-export * from "./HomeSalesCard";