Skip to content

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

Add activity component for home page

Lukasz Szewczykb250b6d5d426
diff --git a/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx b/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx
index b154939b10..39fb6182c7 100644
--- a/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx
+++ b/saleor/static/dashboard-next/home/components/Dashbaord/Dashbaord.tsx
@@ -1,4 +1,3 @@
-import Card from "@material-ui/core/Card";
import { withStyles } from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
import * as React from "react";
@@ -6,6 +5,7 @@ import CardSpacer from "../../../components/CardSpacer";
import Container from "../../../components/Container";
import PageHeader from "../../../components/PageHeader";
import i18n from "../../../i18n";
+import HomeActivityCard from "../HomeActivityCard";
import HomeNotificationTable from "../HomeNotificationTable";
import HomeOrdersCard from "../HomeOrdersCard";
import HomeProductListCard from "../HomeProductListCard";
@@ -16,6 +16,15 @@ interface MoneyType {
currency: string;
}
export interface DashboardProps {
+ activities?: Array<{
+ action?: string;
+ admin?: boolean;
+ date?: string;
+ elementName?: string;
+ id: string;
+ newElement?: string;
+ user?: string;
+ }>;
daily: {
orders: {
amount: number;
@@ -30,7 +39,7 @@ export interface DashboardProps {
};
onRowClick: () => undefined;
ownerName: string;
- topProducts?: Array<{
+ topProducts: Array<{
id: string;
name: string;
orders: number;
@@ -75,7 +84,8 @@ const Dashboard = decorate<DashboardProps>(
toProblems,
toProductsOut,
topProducts,
- onRowClick
+ onRowClick,
+ activities
}) => {
return (
<Container width="md">
@@ -113,7 +123,7 @@ const Dashboard = decorate<DashboardProps>(
<CardSpacer />
</div>
<div>
- <Card>HomeActivityCard</Card>
+ <HomeActivityCard disabled={false} activities={activities} />
</div>
</div>
</Container>
diff --git a/saleor/static/dashboard-next/home/components/HomeActivityCard/HomeActivityCard.tsx b/saleor/static/dashboard-next/home/components/HomeActivityCard/HomeActivityCard.tsx
new file mode 100644
index 0000000000..28f9a71cd2
--- /dev/null
+++ b/saleor/static/dashboard-next/home/components/HomeActivityCard/HomeActivityCard.tsx
@@ -0,0 +1,88 @@
+import Card from "@material-ui/core/Card";
+import List from "@material-ui/core/List";
+import ListItem from "@material-ui/core/ListItem";
+import ListItemText from "@material-ui/core/ListItemText";
+import { withStyles } from "@material-ui/core/styles";
+import Typography from "@material-ui/core/Typography";
+import * as React from "react";
+import Moment from "react-moment";
+import CardTitle from "../../../components/CardTitle";
+import Skeleton from "../../../components/Skeleton";
+import i18n from "../../../i18n";
+import { renderCollection } from "../../../misc";
+
+interface HomeProductListCardProps {
+ activities?: Array<{
+ action?: string;
+ admin?: boolean;
+ date?: string;
+ elementName?: string;
+ id?: string;
+ newElement?: string;
+ user?: string;
+ }>;
+ disabled: boolean;
+}
+
+const decorate = withStyles({
+ noProducts: {
+ paddingBottom: "18px",
+ paddingTop: "18px"
+ }
+});
+
+const HomeProductListCard = decorate<HomeProductListCardProps>(
+ ({ classes, activities }) => {
+ return (
+ <Card>
+ <CardTitle title={i18n.t("Activity")} />
+ <List dense={true}>
+ {renderCollection(
+ activities,
+ activity => (
+ <ListItem key={activity ? activity.id : "skeleton"}>
+ {activity ? (
+ <ListItemText
+ primary={
+ <Typography
+ dangerouslySetInnerHTML={{
+ __html: activity.admin
+ ? i18n.t(`Saleor shop admin
+ ${activity.action} ${activity.newElement}:
+ ${activity.user}`)
+ : i18n.t(`
+ ${activity.user} ${activity.action} a
+ ${activity.newElement}: ${activity.elementName}
+ `)
+ }}
+ />
+ }
+ secondary={
+ <Moment format="MMM D, YYYY [at] HH:mm ">
+ {activity.date}
+ </Moment>
+ }
+ />
+ ) : (
+ <ListItemText>
+ <Skeleton />
+ </ListItemText>
+ )}
+ </ListItem>
+ ),
+ () => (
+ <ListItem dense={false} className={classes.noProducts}>
+ <ListItemText
+ primary={
+ <Typography>{i18n.t("No products found")}</Typography>
+ }
+ />
+ </ListItem>
+ )
+ )}
+ </List>
+ </Card>
+ );
+ }
+);
+export default HomeProductListCard;
diff --git a/saleor/static/dashboard-next/home/components/HomeActivityCard/index.ts b/saleor/static/dashboard-next/home/components/HomeActivityCard/index.ts
new file mode 100644
index 0000000000..bec23d02f5
--- /dev/null
+++ b/saleor/static/dashboard-next/home/components/HomeActivityCard/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./HomeActivityCard";
+export * from "./HomeActivityCard";
diff --git a/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsx b/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsx
index 5b6e4a5252..78587a2407 100644
--- a/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/home/dashboard.tsx
@@ -8,6 +8,7 @@ import Decorator from "../../Decorator";
const shop = shopFixture(placeholderImage);
const dashboardProps: DashboardProps = {
+ activities: shop.activities,
daily: shop.daily,
notifications: shop.notifications,
onRowClick: () => undefined,
@@ -28,6 +29,7 @@ storiesOf("Views / Home / Dashboard", module)
topProducts={undefined}
daily={undefined}
notifications={undefined}
+ activities={undefined}
/>
))
.add("no data", () => (
@@ -40,5 +42,6 @@ storiesOf("Views / Home / Dashboard", module)
problems: 0,
productsOut: 0
}}
+ activities={[]}
/>
));