Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add sales card component for home page
Lukasz Szewczyk17c03a0a68e4
diff --git a/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx b/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsxindex aae99fd007..5b4b2823a4 100644--- a/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx+++ b/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx@@ -6,8 +6,16 @@ import CardSpacer from "../../../components/CardSpacer";import Container from "../../../components/Container";import PageHeader from "../../../components/PageHeader";import i18n from "../../../i18n";+import HomeSalesCard from "../HomeSalesCard";+interface MoneyType {+ amount: number;+ currency: string;+}export interface DashboardProps {+ daily?: {+ sales?: MoneyType;+ };ownerName: string;}@@ -31,7 +39,7 @@ const decorate = withStyles(theme => ({}}}));-const Dashboard = decorate<DashboardProps>(({ ownerName, classes }) => {+const Dashboard = decorate<DashboardProps>(({ ownerName, classes, daily }) => {return (<Container width="md"><PageHeader@@ -46,7 +54,7 @@ const Dashboard = decorate<DashboardProps>(({ ownerName, classes }) => {<div className={classes.root}><div><div className={classes.flexbox}>- <Card>Sales</Card>+ <HomeSalesCard disabled={false} title={"Sales"} daily={daily} /><Card>Orders</Card></div>diff --git a/saleor/static/dashboard-next/home/components/HomeSalesCard/HomeSalesCard.tsx b/saleor/static/dashboard-next/home/components/HomeSalesCard/HomeSalesCard.tsxnew file mode 100644index 0000000000..5cb1f1f0fd--- /dev/null+++ b/saleor/static/dashboard-next/home/components/HomeSalesCard/HomeSalesCard.tsx@@ -0,0 +1,100 @@+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",+ minHeight: "0",+ minWidth: "0"+ },++ cardSubtitle: {+ color: theme.palette.text.secondary,+ fontSize: ".65rem",+ height: "16px",+ lineHeight: 0.5+ },+ cardTitle: {+ fontWeight: "bold" as "bold"+ },+ fullWidth: {+ marginRight: `${theme.spacing.unit * 1.5}px`,+ [theme.breakpoints.down("sm")]: {+ marginRight: `${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 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="display1">+ {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.tsnew file mode 100644index 0000000000..c230853102--- /dev/null+++ b/saleor/static/dashboard-next/home/components/HomeSalesCard/index.ts@@ -0,0 +1,2 @@+export { default } from "./HomeSalesCard";+export * from "./HomeSalesCard";diff --git a/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsx b/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsxindex 54b6b5ab9d..2c6f177e60 100644--- a/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsx+++ b/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsx@@ -8,11 +8,12 @@ import Decorator from "../../Decorator";const shop = shopFixture(placeholderImage);const dashboardProps: DashboardProps = {+ daily: shop.daily,ownerName: shop.ownerName};storiesOf("Views / Home / Dashboard", module).addDecorator(Decorator).add("default", () => <Dashbaord {...dashboardProps} />)- .add("loading", () => <Dashbaord {...dashboardProps} />)+ .add("loading", () => <Dashbaord {...dashboardProps} daily={undefined} />).add("no data", () => <Dashbaord {...dashboardProps} />);