saleor-dashboard/src/customers/components/CustomerListPage/CustomerListPage.tsx

92 lines
2.6 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import Button from "@material-ui/core/Button";
2019-09-11 14:39:52 +00:00
import Card from "@material-ui/core/Card";
2019-08-09 10:26:22 +00:00
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
2019-06-19 14:40:52 +00:00
import Container from "@saleor/components/Container";
import PageHeader from "@saleor/components/PageHeader";
import { sectionNames } from "@saleor/intl";
2019-09-11 14:39:52 +00:00
import {
ListActions,
PageListProps,
2019-12-17 17:13:56 +00:00
TabPageProps,
2020-01-02 12:22:12 +00:00
SortPage,
FilterPageProps
2019-09-11 14:39:52 +00:00
} from "@saleor/types";
2019-12-17 17:13:56 +00:00
import { CustomerListUrlSortField } from "@saleor/customers/urls";
2020-01-02 12:22:12 +00:00
import {
CustomerFilterKeys,
createFilterStructure
} from "@saleor/customers/views/CustomerList/filter";
import { CustomerListFilterOpts } from "@saleor/customers/types";
import FilterBar from "@saleor/components/FilterBar";
2019-06-19 14:40:52 +00:00
import CustomerList from "../CustomerList/CustomerList";
2020-01-02 12:22:12 +00:00
import { ListCustomers_customers_edges_node } from "../../types/ListCustomers";
2019-06-19 14:40:52 +00:00
2019-09-11 14:39:52 +00:00
export interface CustomerListPageProps
extends PageListProps,
ListActions,
2020-01-02 12:22:12 +00:00
FilterPageProps<CustomerFilterKeys, CustomerListFilterOpts>,
2019-12-17 17:13:56 +00:00
SortPage<CustomerListUrlSortField>,
2019-09-11 14:39:52 +00:00
TabPageProps {
2019-06-19 14:40:52 +00:00
customers: ListCustomers_customers_edges_node[];
}
const CustomerListPage: React.FC<CustomerListPageProps> = ({
2020-01-02 12:22:12 +00:00
currencySymbol,
2019-09-11 14:39:52 +00:00
currentTab,
2020-01-02 12:22:12 +00:00
filterOpts,
2019-09-11 14:39:52 +00:00
initialSearch,
2019-06-19 14:40:52 +00:00
onAdd,
2019-09-11 14:39:52 +00:00
onAll,
2020-01-02 12:22:12 +00:00
onFilterChange,
2019-09-11 14:39:52 +00:00
onSearchChange,
onTabChange,
onTabDelete,
onTabSave,
tabs,
2019-06-19 14:40:52 +00:00
...customerListProps
}) => {
const intl = useIntl();
2020-01-02 12:22:12 +00:00
const structure = createFilterStructure(intl, filterOpts);
return (
<Container>
<PageHeader title={intl.formatMessage(sectionNames.customers)}>
2019-12-17 17:13:56 +00:00
<Button color="primary" variant="contained" onClick={onAdd}>
<FormattedMessage
2019-11-26 14:34:56 +00:00
defaultMessage="Create customer"
description="button"
/>
</Button>
</PageHeader>
2019-09-11 14:39:52 +00:00
<Card>
2020-01-02 12:22:12 +00:00
<FilterBar
2019-09-11 15:56:00 +00:00
allTabLabel={intl.formatMessage({
defaultMessage: "All Customers",
description: "tab name"
})}
2020-01-02 12:22:12 +00:00
currencySymbol={currencySymbol}
2019-09-11 14:39:52 +00:00
currentTab={currentTab}
2020-01-02 12:22:12 +00:00
filterStructure={structure}
2019-09-11 14:39:52 +00:00
initialSearch={initialSearch}
searchPlaceholder={intl.formatMessage({
defaultMessage: "Search Customer"
})}
tabs={tabs}
onAll={onAll}
2020-01-02 12:22:12 +00:00
onFilterChange={onFilterChange}
2019-09-11 14:39:52 +00:00
onSearchChange={onSearchChange}
onTabChange={onTabChange}
onTabDelete={onTabDelete}
onTabSave={onTabSave}
/>
2019-12-17 17:13:56 +00:00
<CustomerList {...customerListProps} />
2019-09-11 14:39:52 +00:00
</Card>
</Container>
);
};
2019-06-19 14:40:52 +00:00
CustomerListPage.displayName = "CustomerListPage";
export default CustomerListPage;