Skip to content

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

Add sale details component

dominik-zeglend834e4fafc3f
diff --git a/saleor/static/dashboard-next/discounts/components/SaleCategories/SaleCategories.tsx b/saleor/static/dashboard-next/discounts/components/SaleCategories/SaleCategories.tsx
index 292f476a34..9d840dff89 100644
--- a/saleor/static/dashboard-next/discounts/components/SaleCategories/SaleCategories.tsx
+++ b/saleor/static/dashboard-next/discounts/components/SaleCategories/SaleCategories.tsx
@@ -1,9 +1,117 @@
-import { withStyles } from "@material-ui/core/styles";
+import Button from "@material-ui/core/Button";
+import Card from "@material-ui/core/Card";
+import { createStyles, withStyles, 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 TableFooter from "@material-ui/core/TableFooter";
+import TableHead from "@material-ui/core/TableHead";
+import TableRow from "@material-ui/core/TableRow";
import * as React from "react";
-export interface SaleCategoriesProps {}
+import CardTitle from "../../../components/CardTitle";
+import Skeleton from "../../../components/Skeleton";
+import TablePagination from "../../../components/TablePagination";
+import i18n from "../../../i18n";
+import { maybe, renderCollection } from "../../../misc";
+import { ListProps } from "../../../types";
+import { SaleDetails_sale } from "../../types/SaleDetails";
-const decorate = withStyles(theme => ({ root: {} }));
-const SaleCategories = decorate<SaleCategoriesProps>(({ classes }) => <div />);
+export interface SaleCategoriesProps extends ListProps {
+ sale: SaleDetails_sale;
+}
+
+const styles = createStyles({
+ tableRow: {
+ cursor: "pointer"
+ },
+ textRight: {
+ textAlign: "right"
+ },
+ wideColumn: {
+ width: "60%"
+ }
+});
+const SaleCategories = withStyles(styles, {
+ name: "SaleCategories"
+})(
+ ({
+ sale,
+ classes,
+ disabled,
+ pageInfo,
+ onRowClick,
+ onPreviousPage,
+ onNextPage
+ }: SaleCategoriesProps & WithStyles<typeof styles>) => (
+ <Card>
+ <CardTitle
+ title={i18n.t("Categories assigned to {{ saleName }}", {
+ saleName: maybe(() => sale.name)
+ })}
+ toolbar={
+ <Button variant="flat" color="secondary">
+ {i18n.t("Assign categories")}
+ </Button>
+ }
+ />
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell className={classes.wideColumn}>
+ {i18n.t("Category name")}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {i18n.t("Products")}
+ </TableCell>
+ </TableRow>
+ </TableHead>
+ <TableFooter>
+ <TableRow>
+ <TablePagination
+ colSpan={5}
+ hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
+ onNextPage={onNextPage}
+ hasPreviousPage={
+ pageInfo && !disabled ? pageInfo.hasPreviousPage : false
+ }
+ onPreviousPage={onPreviousPage}
+ />
+ </TableRow>
+ </TableFooter>
+ <TableBody>
+ {renderCollection(
+ maybe(() => sale.categories.edges.map(edge => edge.node)),
+ category => (
+ <TableRow
+ hover={!!category}
+ key={category ? category.id : "skeleton"}
+ onClick={category && onRowClick(category.id)}
+ className={classes.tableRow}
+ >
+ <TableCell>
+ {maybe<React.ReactNode>(() => category.name, <Skeleton />)}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {maybe<React.ReactNode>(
+ () => category.products.totalCount,
+ <Skeleton />
+ )}
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell colSpan={2}>
+ {i18n.t("No categories found")}
+ </TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+);
SaleCategories.displayName = "SaleCategories";
export default SaleCategories;
diff --git a/saleor/static/dashboard-next/discounts/components/SaleCollections/SaleCollections.tsx b/saleor/static/dashboard-next/discounts/components/SaleCollections/SaleCollections.tsx
index 2c9b5bc8c4..a5514e78d1 100644
--- a/saleor/static/dashboard-next/discounts/components/SaleCollections/SaleCollections.tsx
+++ b/saleor/static/dashboard-next/discounts/components/SaleCollections/SaleCollections.tsx
@@ -1,9 +1,117 @@
-import { withStyles } from "@material-ui/core/styles";
+import Button from "@material-ui/core/Button";
+import Card from "@material-ui/core/Card";
+import { createStyles, withStyles, 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 TableFooter from "@material-ui/core/TableFooter";
+import TableHead from "@material-ui/core/TableHead";
+import TableRow from "@material-ui/core/TableRow";
import * as React from "react";
-export interface SaleCollectionsProps {}
+import CardTitle from "../../../components/CardTitle";
+import Skeleton from "../../../components/Skeleton";
+import TablePagination from "../../../components/TablePagination";
+import i18n from "../../../i18n";
+import { maybe, renderCollection } from "../../../misc";
+import { ListProps } from "../../../types";
+import { SaleDetails_sale } from "../../types/SaleDetails";
-const decorate = withStyles(theme => ({ root: {} }));
-const SaleCollections = decorate<SaleCollectionsProps>(({ classes }) => <div />);
+export interface SaleCollectionsProps extends ListProps {
+ sale: SaleDetails_sale;
+}
+
+const styles = createStyles({
+ tableRow: {
+ cursor: "pointer"
+ },
+ textRight: {
+ textAlign: "right"
+ },
+ wideColumn: {
+ width: "60%"
+ }
+});
+const SaleCollections = withStyles(styles, {
+ name: "SaleCollections"
+})(
+ ({
+ sale,
+ classes,
+ disabled,
+ pageInfo,
+ onRowClick,
+ onPreviousPage,
+ onNextPage
+ }: SaleCollectionsProps & WithStyles<typeof styles>) => (
+ <Card>
+ <CardTitle
+ title={i18n.t("Collections assigned to {{ saleName }}", {
+ saleName: maybe(() => sale.name)
+ })}
+ toolbar={
+ <Button variant="flat" color="secondary">
+ {i18n.t("Assign collections")}
+ </Button>
+ }
+ />
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell className={classes.wideColumn}>
+ {i18n.t("Collection name")}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {i18n.t("Products")}
+ </TableCell>
+ </TableRow>
+ </TableHead>
+ <TableFooter>
+ <TableRow>
+ <TablePagination
+ colSpan={5}
+ hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
+ onNextPage={onNextPage}
+ hasPreviousPage={
+ pageInfo && !disabled ? pageInfo.hasPreviousPage : false
+ }
+ onPreviousPage={onPreviousPage}
+ />
+ </TableRow>
+ </TableFooter>
+ <TableBody>
+ {renderCollection(
+ maybe(() => sale.collections.edges.map(edge => edge.node)),
+ collection => (
+ <TableRow
+ hover={!!collection}
+ key={collection ? collection.id : "skeleton"}
+ onClick={collection && onRowClick(collection.id)}
+ className={classes.tableRow}
+ >
+ <TableCell>
+ {maybe<React.ReactNode>(() => collection.name, <Skeleton />)}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {maybe<React.ReactNode>(
+ () => collection.products.totalCount,
+ <Skeleton />
+ )}
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell colSpan={2}>
+ {i18n.t("No collections found")}
+ </TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+);
SaleCollections.displayName = "SaleCollections";
export default SaleCollections;
diff --git a/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx b/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx
index bb582b8125..add1cc5634 100644
--- a/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx
+++ b/saleor/static/dashboard-next/discounts/components/SaleDetailsPage/SaleDetailsPage.tsx
@@ -5,6 +5,8 @@ import Container from "../../../components/Container";
import Form from "../../../components/Form";
import Grid from "../../../components/Grid";
import PageHeader from "../../../components/PageHeader";
+import { Tab } from "../../../components/Tab";
+import TabContainer from "../../../components/Tab/TabContainer";
import i18n from "../../../i18n";
import { maybe } from "../../../misc";
import { ListProps } from "../../../types";
@@ -13,6 +15,9 @@ import { SaleDetails_sale } from "../../types/SaleDetails";
import SaleInfo from "../SaleInfo";
import SalePricing from "../SalePricing";
import SaleSummary from "../SaleSummary";
+import SaleCategories from "../SaleCategories";
+import SaleCollections from "../SaleCollections";
+import SaleProducts from "../SaleProducts";
export interface FormData {
name: string;
@@ -22,17 +27,29 @@ export interface FormData {
type: SaleType;
}
+export enum SaleDetailsPageTab {
+ "categories",
+ "collections",
+ "products"
+}
+
export interface SaleDetailsPageProps extends ListProps {
- activeTab: "categories" | "collections" | "products";
+ activeTab: SaleDetailsPageTab;
defaultCurrency: string;
sale: SaleDetails_sale;
onBack: () => void;
onRemove: () => void;
onSubmit: (data: FormData) => void;
+ onTabClick: (index: SaleDetailsPageTab) => void;
}
+const CategoriesTab = Tab(SaleDetailsPageTab.categories);
+const CollectionsTab = Tab(SaleDetailsPageTab.collections);
+const ProductsTab = Tab(SaleDetailsPageTab.products);
+
const SaleDetailsPage: React.StatelessComponent<SaleDetailsPageProps> = ({
activeTab,
+ onTabClick,
defaultCurrency,
disabled,
sale,
@@ -66,6 +83,56 @@ const SaleDetailsPage: React.StatelessComponent<SaleDetailsPageProps> = ({
disabled={disabled}
onChange={change}
/>
+ <CardSpacer />
+ <TabContainer>
+ <CategoriesTab
+ isActive={activeTab === SaleDetailsPageTab.categories}
+ changeTab={onTabClick}
+ >
+ {i18n.t("Categories")}
+ </CategoriesTab>
+ <CollectionsTab
+ isActive={activeTab === SaleDetailsPageTab.collections}
+ changeTab={onTabClick}
+ >
+ {i18n.t("Collections")}
+ </CollectionsTab>
+ <ProductsTab
+ isActive={activeTab === SaleDetailsPageTab.products}
+ changeTab={onTabClick}
+ >
+ {i18n.t("Products")}
+ </ProductsTab>
+ </TabContainer>
+ <CardSpacer />
+ {activeTab === SaleDetailsPageTab.categories ? (
+ <SaleCategories
+ disabled={disabled}
+ onNextPage={onNextPage}
+ onPreviousPage={onPreviousPage}
+ onRowClick={onRowClick}
+ pageInfo={pageInfo}
+ sale={sale}
+ />
+ ) : activeTab === SaleDetailsPageTab.collections ? (
+ <SaleCollections
+ disabled={disabled}
+ onNextPage={onNextPage}
+ onPreviousPage={onPreviousPage}
+ onRowClick={onRowClick}
+ pageInfo={pageInfo}
+ sale={sale}
+ />
+ ) : (
+ <SaleProducts
+ disabled={disabled}
+ onNextPage={onNextPage}
+ onPreviousPage={onPreviousPage}
+ onRowClick={onRowClick}
+ pageInfo={pageInfo}
+ sale={sale}
+ />
+ )}
</div>
<div>
<SaleSummary defaultCurrency={defaultCurrency} sale={sale} />
diff --git a/saleor/static/dashboard-next/discounts/components/SaleProducts/SaleProducts.tsx b/saleor/static/dashboard-next/discounts/components/SaleProducts/SaleProducts.tsx
index d2c413d0e1..cb5dec42e7 100644
--- a/saleor/static/dashboard-next/discounts/components/SaleProducts/SaleProducts.tsx
+++ b/saleor/static/dashboard-next/discounts/components/SaleProducts/SaleProducts.tsx
@@ -1,9 +1,140 @@
-import { withStyles } from "@material-ui/core/styles";
+import Button from "@material-ui/core/Button";
+import Card from "@material-ui/core/Card";
+import { createStyles, withStyles, 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 TableFooter from "@material-ui/core/TableFooter";
+import TableHead from "@material-ui/core/TableHead";
+import TableRow from "@material-ui/core/TableRow";
import * as React from "react";
-export interface SaleProductsProps {}
+import CardTitle from "../../../components/CardTitle";
+import Skeleton from "../../../components/Skeleton";
+import StatusLabel from "../../../components/StatusLabel";
+import TableCellAvatar from "../../../components/TableCellAvatar";
+import TablePagination from "../../../components/TablePagination";
+import i18n from "../../../i18n";
+import { maybe, renderCollection } from "../../../misc";
+import { ListProps } from "../../../types";
+import { SaleDetails_sale } from "../../types/SaleDetails";
-const decorate = withStyles(theme => ({ root: {} }));
-const SaleProducts = decorate<SaleProductsProps>(({ classes }) => <div />);
+export interface SaleProductsProps extends ListProps {
+ sale: SaleDetails_sale;
+}
+
+const styles = createStyles({
+ tableRow: {
+ cursor: "pointer"
+ },
+ textRight: {
+ textAlign: "right"
+ },
+ wideColumn: {
+ width: "40%"
+ }
+});
+const SaleProducts = withStyles(styles, {
+ name: "SaleProducts"
+})(
+ ({
+ sale,
+ classes,
+ disabled,
+ pageInfo,
+ onRowClick,
+ onPreviousPage,
+ onNextPage
+ }: SaleProductsProps & WithStyles<typeof styles>) => (
+ <Card>
+ <CardTitle
+ title={i18n.t("Products assigned to {{ saleName }}", {
+ saleName: maybe(() => sale.name)
+ })}
+ toolbar={
+ <Button variant="flat" color="secondary">
+ {i18n.t("Assign products")}
+ </Button>
+ }
+ />
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell />
+ <TableCell className={classes.wideColumn}>
+ {i18n.t("Product name")}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {i18n.t("Product Type")}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {i18n.t("Published")}
+ </TableCell>
+ </TableRow>
+ </TableHead>
+ <TableFooter>
+ <TableRow>
+ <TablePagination
+ colSpan={4}
+ hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
+ onNextPage={onNextPage}
+ hasPreviousPage={
+ pageInfo && !disabled ? pageInfo.hasPreviousPage : false
+ }
+ onPreviousPage={onPreviousPage}
+ />
+ </TableRow>
+ </TableFooter>
+ <TableBody>
+ {renderCollection(
+ maybe(() => sale.products.edges.map(edge => edge.node)),
+ product => (
+ <TableRow
+ hover={!!product}
+ key={product ? product.id : "skeleton"}
+ onClick={product && onRowClick(product.id)}
+ className={classes.tableRow}
+ >
+ <TableCellAvatar
+ thumbnail={maybe(() => product.thumbnail.url)}
+ />
+ <TableCell>
+ {maybe<React.ReactNode>(() => product.name, <Skeleton />)}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {maybe<React.ReactNode>(
+ () => product.productType.name,
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {product && product.isPublished !== undefined ? (
+ <StatusLabel
+ label={
+ product.isPublished
+ ? i18n.t("Published", { context: "product status" })
+ : i18n.t("Not published", {
+ context: "product status"
+ })
+ }
+ status={product.isPublished ? "success" : "error"}
+ />
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell colSpan={4}>{i18n.t("No products found")}</TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+);
SaleProducts.displayName = "SaleProducts";
export default SaleProducts;
diff --git a/saleor/static/dashboard-next/discounts/fixtures.ts b/saleor/static/dashboard-next/discounts/fixtures.ts
index 562e8dd542..eebd5dd251 100644
--- a/saleor/static/dashboard-next/discounts/fixtures.ts
+++ b/saleor/static/dashboard-next/discounts/fixtures.ts
@@ -1,3 +1,4 @@
+import * as placeholderImage from "../../images/placeholder60x60.png";
import { SaleType, VoucherDiscountValueType } from "../types/globalTypes";
import { SaleDetails_sale } from "./types/SaleDetails";
import { SaleList_sales_edges_node } from "./types/SaleList";
@@ -84,7 +85,20 @@ export const sale: SaleDetails_sale = {
__typename: "Sale",
categories: {
__typename: "CategoryCountableConnection",
- edges: [],
+ edges: [
+ {
+ __typename: "CategoryCountableEdge",
+ node: {
+ __typename: "Category",
+ id: "U2FsZTo1=",
+ name: "Apparel",
+ products: {
+ __typename: "ProductCountableConnection",
+ totalCount: 18
+ }
+ }
+ }
+ ],
pageInfo: {
__typename: "PageInfo",
endCursor: null,
@@ -95,7 +109,20 @@ export const sale: SaleDetails_sale = {
},
collections: {
__typename: "CollectionCountableConnection",
- edges: [],
+ edges: [
+ {
+ __typename: "CollectionCountableEdge",
+ node: {
+ __typename: "Collection",
+ id: "U2FsZBo4=",
+ name: "Winter Collection",
+ products: {
+ __typename: "ProductCountableConnection",
+ totalCount: 110
+ }
+ }
+ }
+ ],
pageInfo: {
__typename: "PageInfo",
endCursor: null,
@@ -121,6 +148,10 @@ export const sale: SaleDetails_sale = {
__typename: "ProductType",
id: "UHJvZHVjdFR5cGU6OQ==",
name: "Juice"
+ },
+ thumbnail: {
+ __typename: "Image",
+ url: placeholderImage
}
}
},
@@ -135,6 +166,10 @@ export const sale: SaleDetails_sale = {
__typename: "ProductType",
id: "UHJvZHVjdFR5cGU6OQ==",
name: "Juice"
+ },
+ thumbnail: {
+ __typename: "Image",
+ url: placeholderImage
}
}
},
@@ -149,6 +184,10 @@ export const sale: SaleDetails_sale = {
__typename: "ProductType",
id: "UHJvZHVjdFR5cGU6OQ==",
name: "Juice"
+ },
+ thumbnail: {
+ __typename: "Image",
+ url: placeholderImage
}
}
},
@@ -163,6 +202,10 @@ export const sale: SaleDetails_sale = {
__typename: "ProductType",
id: "UHJvZHVjdFR5cGU6MTQ=",
name: "Top (clothing)"
+ },
+ thumbnail: {
+ __typename: "Image",
+ url: placeholderImage
}
}
}
diff --git a/saleor/static/dashboard-next/discounts/queries.ts b/saleor/static/dashboard-next/discounts/queries.ts
index e24ce130aa..1e5cc5266c 100644
--- a/saleor/static/dashboard-next/discounts/queries.ts
+++ b/saleor/static/dashboard-next/discounts/queries.ts
@@ -79,6 +79,9 @@ export const saleDetails = gql`
id
name
}
+ thumbnail {
+ url
+ }
}
}
pageInfo {
diff --git a/saleor/static/dashboard-next/discounts/types/SaleDetails.ts b/saleor/static/dashboard-next/discounts/types/SaleDetails.ts
index 9de41f9bc6..b5bdf8c717 100644
--- a/saleor/static/dashboard-next/discounts/types/SaleDetails.ts
+++ b/saleor/static/dashboard-next/discounts/types/SaleDetails.ts
@@ -13,12 +13,18 @@ export interface SaleDetails_sale_products_edges_node_productType {
name: string;
}
+export interface SaleDetails_sale_products_edges_node_thumbnail {
+ __typename: "Image";
+ url: string;
+}
+
export interface SaleDetails_sale_products_edges_node {
__typename: "Product";
id: string;
name: string;
isPublished: boolean;
productType: SaleDetails_sale_products_edges_node_productType;
+ thumbnail: SaleDetails_sale_products_edges_node_thumbnail | null;
}
export interface SaleDetails_sale_products_edges {
diff --git a/saleor/static/dashboard-next/storybook/stories/discounts/SaleDetailsPage.tsx b/saleor/static/dashboard-next/storybook/stories/discounts/SaleDetailsPage.tsx
index bd3a01104c..0ea9d95733 100644
--- a/saleor/static/dashboard-next/storybook/stories/discounts/SaleDetailsPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/discounts/SaleDetailsPage.tsx
@@ -2,13 +2,14 @@ import { storiesOf } from "@storybook/react";
import * as React from "react";
import SaleDetailsPage, {
- SaleDetailsPageProps
+ SaleDetailsPageProps,
+ SaleDetailsPageTab
} from "../../../discounts/components/SaleDetailsPage";
import { sale } from "../../../discounts/fixtures";
import Decorator from "../../Decorator";
const props: SaleDetailsPageProps = {
- activeTab: "categories",
+ activeTab: SaleDetailsPageTab.categories,
defaultCurrency: "USD",
disabled: false,
onBack: () => undefined,
@@ -17,6 +18,7 @@ const props: SaleDetailsPageProps = {
onRemove: () => undefined,
onRowClick: () => () => undefined,
onSubmit: () => undefined,
+ onTabClick: () => undefined,
pageInfo: {
hasNextPage: true,
hasPreviousPage: false
@@ -29,4 +31,10 @@ storiesOf("Views / Discounts / Sale details", module)
.add("default", () => <SaleDetailsPage {...props} />)
.add("loading", () => (
<SaleDetailsPage {...props} sale={undefined} disabled={true} />
+ ))
+ .add("collections", () => (
+ <SaleDetailsPage {...props} activeTab={SaleDetailsPageTab.collections} />
+ ))
+ .add("products", () => (
+ <SaleDetailsPage {...props} activeTab={SaleDetailsPageTab.products} />
));