Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add customer list view
dominik-zeglene12cee10376f
diff --git a/saleor/static/dashboard-next/customers/index.ts b/saleor/static/dashboard-next/customers/index.tsdeleted file mode 100644index e69de29bb2..0000000000diff --git a/saleor/static/dashboard-next/customers/index.tsx b/saleor/static/dashboard-next/customers/index.tsxnew file mode 100644index 0000000000..7e03a8c805--- /dev/null+++ b/saleor/static/dashboard-next/customers/index.tsx@@ -0,0 +1,23 @@+import { parse as parseQs } from "qs";+import * as React from "react";+import { Route, RouteComponentProps, Switch } from "react-router-dom";++import { customerListUrl } from "./urls";+import CustomerListViewComponent from "./views/CustomerList";++const CustomerListView: React.StatelessComponent<RouteComponentProps<{}>> = ({+ location+}) => {+ const qs = parseQs(location.search.substr(1));+ const params = {+ after: qs.after,+ before: qs.before+ };+ return <CustomerListViewComponent params={params} />;+};++export const CustomerSection: React.StatelessComponent<{}> = () => (+ <Switch>+ <Route path={customerListUrl} component={CustomerListView} />+ </Switch>+);diff --git a/saleor/static/dashboard-next/customers/queries.ts b/saleor/static/dashboard-next/customers/queries.tsindex 8c255d625d..769d93e400 100644--- a/saleor/static/dashboard-next/customers/queries.ts+++ b/saleor/static/dashboard-next/customers/queries.ts@@ -1,12 +1,12 @@import gql from "graphql-tag";+import { fragmentAddress } from "../orders/queries";import { TypedQuery } from "../queries";import {CustomerDetails,CustomerDetailsVariables} from "./types/CustomerDetails";import { ListCustomers, ListCustomersVariables } from "./types/ListCustomers";-import { fragmentAddress } from "../orders/queries";const customerList = gql`query ListCustomers(diff --git a/saleor/static/dashboard-next/customers/urls.ts b/saleor/static/dashboard-next/customers/urls.tsnew file mode 100644index 0000000000..48321b9003--- /dev/null+++ b/saleor/static/dashboard-next/customers/urls.ts@@ -0,0 +1,4 @@+export const customerSection = "/customers/";+export const customerListUrl = customerSection;+export const customerUrl = (id: string) => customerSection + id + "/";+export const customerAddUrl = customerSection + "add/";diff --git a/saleor/static/dashboard-next/customers/views/CustomerList.tsx b/saleor/static/dashboard-next/customers/views/CustomerList.tsxnew file mode 100644index 0000000000..3231dc9edc--- /dev/null+++ b/saleor/static/dashboard-next/customers/views/CustomerList.tsx@@ -0,0 +1,57 @@+import * as React from "react";++import Navigator from "../../components/Navigator";+import { createPaginationData, createPaginationState, maybe } from "../../misc";+import CustomerListPage from "../components/CustomerListPage";+import { TypedCustomerListQuery } from "../queries";+import { customerAddUrl, customerListUrl, customerUrl } from "../urls";++const PAGINATE_BY = 20;++interface CustomerListProps {+ params: {+ after?: string;+ before?: string;+ };+}++export const CustomerList: React.StatelessComponent<CustomerListProps> = ({+ params+}) => (+ <Navigator>+ {navigate => {+ const paginationState = createPaginationState(PAGINATE_BY, params);+ return (+ <TypedCustomerListQuery variables={paginationState}>+ {({ data, loading }) => {+ const {+ loadNextPage,+ loadPreviousPage,+ pageInfo+ } = createPaginationData(+ navigate,+ paginationState,+ customerListUrl,+ maybe(() => data.customers.pageInfo),+ loading+ );+ return (+ <CustomerListPage+ customers={maybe(() =>+ data.customers.edges.map(edge => edge.node)+ )}+ disabled={loading}+ pageInfo={pageInfo}+ onAdd={() => navigate(customerAddUrl)}+ onNextPage={loadNextPage}+ onPreviousPage={loadPreviousPage}+ onRowClick={id => navigate(customerUrl(encodeURIComponent(id)))}+ />+ );+ }}+ </TypedCustomerListQuery>+ );+ }}+ </Navigator>+);+export default CustomerList;diff --git a/saleor/static/dashboard-next/index.tsx b/saleor/static/dashboard-next/index.tsxindex a732971356..e1a9362108 100644--- a/saleor/static/dashboard-next/index.tsx+++ b/saleor/static/dashboard-next/index.tsx@@ -22,6 +22,7 @@ import { DateProvider } from "./components/DateFormatter";import { LocaleProvider } from "./components/Locale";import { MessageManager } from "./components/messages";import ConfigurationSection, { configurationMenu } from "./configuration";+import { CustomerSection } from "./customers";import HomePage from "./home";import "./i18n";import { NotFound } from "./NotFound";@@ -115,6 +116,11 @@ render(path="/collections"component={CollectionSection}/>+ <SectionRoute+ permissions={[PermissionEnum.MANAGE_USERS]}+ path="/customers"+ component={CustomerSection}+ /><SectionRoutepermissions={[PermissionEnum.MANAGE_PAGES]}path="/pages"