Skip to content

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

Add customer list

dominik-zeglen2a72f9524a1b
diff --git a/saleor/static/dashboard-next/customers/components/CustomerList/CustomerList.tsx b/saleor/static/dashboard-next/customers/components/CustomerList/CustomerList.tsx
new file mode 100644
index 0000000000..d1855e1170
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/components/CustomerList/CustomerList.tsx
@@ -0,0 +1,104 @@
+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 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";
+
+import { ListProps } from "../../..";
+import Skeleton from "../../../components/Skeleton";
+import TablePagination from "../../../components/TablePagination";
+import i18n from "../../../i18n";
+import { maybe, renderCollection } from "../../../misc";
+import { ListCustomers_customers_edges_node } from "../../types/ListCustomers";
+
+export interface CustomerListProps extends ListProps {
+ customers: ListCustomers_customers_edges_node[];
+}
+
+const decorate = withStyles({
+ tableRow: {
+ cursor: "pointer" as "pointer"
+ },
+ textRight: {
+ textAlign: "right" as "right"
+ },
+ wideCell: {
+ width: "60%"
+ }
+});
+const CustomerList = decorate<CustomerListProps>(
+ ({
+ classes,
+ disabled,
+ customers,
+ pageInfo,
+ onNextPage,
+ onPreviousPage,
+ onRowClick
+ }) => (
+ <Card>
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell className={classes.wideCell}>
+ {i18n.t("Customer e-mail", { context: "table header" })}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {i18n.t("Orders", { context: "table header" })}
+ </TableCell>
+ </TableRow>
+ </TableHead>
+ <TableFooter>
+ <TableRow>
+ <TablePagination
+ colSpan={2}
+ hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
+ onNextPage={onNextPage}
+ hasPreviousPage={
+ pageInfo && !disabled ? pageInfo.hasPreviousPage : false
+ }
+ onPreviousPage={onPreviousPage}
+ />
+ </TableRow>
+ </TableFooter>
+ <TableBody>
+ {renderCollection(
+ customers,
+ customer => (
+ <TableRow
+ className={!!customer ? classes.tableRow : undefined}
+ hover={!!customer}
+ key={customer ? customer.id : "skeleton"}
+ >
+ <TableCell
+ onClick={customer ? onRowClick(customer.id) : undefined}
+ >
+ {maybe<React.ReactNode>(() => customer.email, <Skeleton />)}
+ </TableCell>
+ <TableCell className={classes.textRight}>
+ {maybe<React.ReactNode>(
+ () => customer.orders.totalCount,
+ <Skeleton />
+ )}
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell colSpan={2}>
+ {i18n.t("No customers found")}
+ </TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ </Card>
+ )
+);
+CustomerList.displayName = "CustomerList";
+export default CustomerList;
diff --git a/saleor/static/dashboard-next/customers/components/CustomerList/index.ts b/saleor/static/dashboard-next/customers/components/CustomerList/index.ts
new file mode 100644
index 0000000000..c5517efd03
--- /dev/null
+++ b/saleor/static/dashboard-next/customers/components/CustomerList/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./CustomerList";
+export * from "./CustomerList";
diff --git a/saleor/static/dashboard-next/customers/components/CustomerListPage/CustomerListPage.tsx b/saleor/static/dashboard-next/customers/components/CustomerListPage/CustomerListPage.tsx
index cb12386a3b..5265f60308 100644
--- a/saleor/static/dashboard-next/customers/components/CustomerListPage/CustomerListPage.tsx
+++ b/saleor/static/dashboard-next/customers/components/CustomerListPage/CustomerListPage.tsx
@@ -1,136 +1,44 @@
import Button from "@material-ui/core/Button";
-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 TableFooter from "@material-ui/core/TableFooter";
-import TableHead from "@material-ui/core/TableHead";
-import TableRow from "@material-ui/core/TableRow";
import AddIcon from "@material-ui/icons/Add";
import * as React from "react";
import { PageListProps } from "../../..";
-import { Container } from "../../../components/Container";
+import Container from "../../../components/Container";
import PageHeader from "../../../components/PageHeader";
-import Skeleton from "../../../components/Skeleton";
-import TablePagination from "../../../components/TablePagination";
import i18n from "../../../i18n";
-import { renderCollection } from "../../../misc";
+import { ListCustomers_customers_edges_node } from "../../types/ListCustomers";
+import CustomerList from "../CustomerList/CustomerList";
-interface CustomerListPageProps extends PageListProps {
- customers?: Array<{
- id: string;
- email: string;
- defaultBillingAddress: {
- firstName: string;
- lastName: string;
- city: string;
- country: {
- code: string;
- country: string;
- };
- };
- }>;
+export interface CustomerListPageProps extends PageListProps {
+ customers: ListCustomers_customers_edges_node[];
}
-const decorate = withStyles(theme => ({
- link: {
- color: theme.palette.secondary.main,
- cursor: "pointer"
- }
-}));
-const CustomerListPage = decorate<CustomerListPageProps>(
- ({
- classes,
- customers,
- disabled,
- pageInfo,
- onAdd,
- onNextPage,
- onPreviousPage,
- onRowClick
- }) => (
- <Container width="md">
- <PageHeader title={i18n.t("Customers")}>
- <Button
- color="secondary"
- variant="contained"
- disabled={disabled}
- onClick={onAdd}
- >
- {i18n.t("Add customer")} <AddIcon />
- </Button>
- </PageHeader>
- <Card>
- <Table>
- <TableHead>
- <TableRow>
- <TableCell>{i18n.t("Name", { context: "object" })}</TableCell>
- <TableCell>{i18n.t("E-mail", { context: "object" })}</TableCell>
- <TableCell>
- {i18n.t("Localization", { context: "object" })}
- </TableCell>
- </TableRow>
- </TableHead>
- <TableFooter>
- <TableRow>
- <TablePagination
- colSpan={3}
- hasNextPage={pageInfo ? pageInfo.hasNextPage : undefined}
- onNextPage={onNextPage}
- hasPreviousPage={
- pageInfo ? pageInfo.hasPreviousPage : undefined
- }
- onPreviousPage={onPreviousPage}
- />
- </TableRow>
- </TableFooter>
- <TableBody>
- {renderCollection(
- customers,
- customer => (
- <TableRow key={customer ? customer.id : "skeleton"}>
- <TableCell>
- {customer ? (
- <span
- onClick={onRowClick && onRowClick(customer.id)}
- className={classes.link}
- >
- {customer.defaultBillingAddress.firstName +
- " " +
- customer.defaultBillingAddress.lastName}
- </span>
- ) : (
- <Skeleton />
- )}
- </TableCell>
- <TableCell>
- {customer ? customer.email : <Skeleton />}
- </TableCell>
- <TableCell>
- {customer && customer.defaultBillingAddress ? (
- customer.defaultBillingAddress.city +
- ", " +
- customer.defaultBillingAddress.country.country
- ) : (
- <Skeleton />
- )}
- </TableCell>
- </TableRow>
- ),
- () => (
- <TableRow>
- <TableCell colSpan={3}>
- {i18n.t("No customers found")}
- </TableCell>
- </TableRow>
- )
- )}
- </TableBody>
- </Table>
- </Card>
- </Container>
- )
+const CustomerListPage: React.StatelessComponent<CustomerListPageProps> = ({
+ customers,
+ disabled,
+ onAdd,
+ ...customerListProps
+}) => (
+ <Container width="md">
+ <PageHeader title={i18n.t("Product types")}>
+ <Button
+ color="secondary"
+ variant="contained"
+ disabled={disabled}
+ onClick={onAdd}
+ >
+ {i18n.t("Add customer", {
+ context: "button"
+ })}{" "}
+ <AddIcon />
+ </Button>
+ </PageHeader>
+ <CustomerList
+ customers={customers}
+ disabled={disabled}
+ {...customerListProps}
+ />
+ </Container>
);
+CustomerListPage.displayName = "CustomerListPage";
export default CustomerListPage;
diff --git a/saleor/static/dashboard-next/customers/fixtures.ts b/saleor/static/dashboard-next/customers/fixtures.ts
index 246a7752d9..b1dd3443a1 100644
--- a/saleor/static/dashboard-next/customers/fixtures.ts
+++ b/saleor/static/dashboard-next/customers/fixtures.ts
@@ -1,3 +1,5 @@
+import { ListCustomers_customers_edges_node } from "./types/ListCustomers";
+
export const customers = [
{
dateJoined: "2017-10-11T13:22:30.831Z",
@@ -673,3 +675,222 @@ export const customers = [
}
];
export const customer = customers[0];
+
+export const customerList: ListCustomers_customers_edges_node[] = [
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjox",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 2
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjox",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 2
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoy",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 1
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoz",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 1
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjo0",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 0
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjo1",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 0
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjo2",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 1
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjo3",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 2
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjo3",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 2
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjo4",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 1
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjo5",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 1
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoxMA==",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 0
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoxMQ==",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 0
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoxMg==",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 0
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoxMw==",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 0
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoxNA==",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 1
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoxNQ==",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 1
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoxNg==",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 2
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoxNg==",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 2
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoxNw==",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 0
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoxOA==",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 0
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoxOQ==",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 0
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoyMA==",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 0
+ }
+ },
+ {
+ __typename: "User",
+ email: "[email protected]",
+ id: "VXNlcjoyMQ==",
+ orders: {
+ __typename: "OrderCountableConnection",
+ totalCount: 6
+ }
+ }
+];
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index d18e7de340..9733df22aa 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -47,8 +47,7 @@ function loadStories() {
require("./stories/configuration/ConfigurationPage");
// Customers
- require("./stories/customers/CustomerDetailsPage");
- require("./stories/customers/CustomerEditPage");
+ // require("./stories/customers/CustomerDetailsPage");
require("./stories/customers/CustomerListPage");
// Homepage
diff --git a/saleor/static/dashboard-next/storybook/stories/customers/CustomerListPage.tsx b/saleor/static/dashboard-next/storybook/stories/customers/CustomerListPage.tsx
index 079be8c243..65db6132fa 100644
--- a/saleor/static/dashboard-next/storybook/stories/customers/CustomerListPage.tsx
+++ b/saleor/static/dashboard-next/storybook/stories/customers/CustomerListPage.tsx
@@ -1,14 +1,22 @@
import { storiesOf } from "@storybook/react";
import * as React from "react";
-import CustomerListPage from "../../../customers/components/CustomerListPage";
-import { customers } from "../../../customers/fixtures";
+import CustomerListPage, {
+ CustomerListPageProps
+} from "../../../customers/components/CustomerListPage";
+import { customerList } from "../../../customers/fixtures";
import { pageListProps } from "../../../fixtures";
import Decorator from "../../Decorator";
+const props: CustomerListPageProps = {
+ ...pageListProps.default,
+ customers: customerList
+};
+
storiesOf("Views / Customers / Customer list", module)
.addDecorator(Decorator)
- .add("default", () => (
- <CustomerListPage customers={customers} {...pageListProps.default} />
+ .add("default", () => <CustomerListPage {...props} />)
+ .add("loading", () => (
+ <CustomerListPage {...props} disabled={true} customers={undefined} />
))
- .add("when loading", () => <CustomerListPage {...pageListProps.loading} />);
+ .add("no data", () => <CustomerListPage {...props} customers={[]} />);