2022-01-28 12:34:20 +00:00
|
|
|
import { Card } from "@material-ui/core";
|
2022-03-01 08:38:23 +00:00
|
|
|
import { useUserPermissions } from "@saleor/auth/hooks/useUserPermissions";
|
2022-05-06 08:59:55 +00:00
|
|
|
import { Button } from "@saleor/components/Button";
|
2019-06-19 14:40:52 +00:00
|
|
|
import Container from "@saleor/components/Container";
|
2020-05-14 09:30:32 +00:00
|
|
|
import FilterBar from "@saleor/components/FilterBar";
|
2019-06-19 14:40:52 +00:00
|
|
|
import PageHeader from "@saleor/components/PageHeader";
|
2022-05-06 08:59:55 +00:00
|
|
|
import {
|
|
|
|
customerAddUrl,
|
|
|
|
CustomerListUrlSortField
|
|
|
|
} from "@saleor/customers/urls";
|
2022-03-09 08:56:55 +00:00
|
|
|
import { ListCustomersQuery } from "@saleor/graphql";
|
2019-08-23 12:23:59 +00:00
|
|
|
import { sectionNames } from "@saleor/intl";
|
2019-09-11 14:39:52 +00:00
|
|
|
import {
|
2020-05-14 09:30:32 +00:00
|
|
|
FilterPageProps,
|
2019-09-11 14:39:52 +00:00
|
|
|
ListActions,
|
|
|
|
PageListProps,
|
2022-03-09 08:56:55 +00:00
|
|
|
RelayToFlat,
|
2020-01-02 12:22:12 +00:00
|
|
|
SortPage,
|
2020-05-14 09:30:32 +00:00
|
|
|
TabPageProps
|
2019-09-11 14:39:52 +00:00
|
|
|
} from "@saleor/types";
|
2020-05-14 09:30:32 +00:00
|
|
|
import React from "react";
|
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
|
|
|
|
|
|
|
import CustomerList from "../CustomerList/CustomerList";
|
2020-01-10 12:50:28 +00:00
|
|
|
import {
|
2020-05-14 09:30:32 +00:00
|
|
|
createFilterStructure,
|
2020-01-10 12:50:28 +00:00
|
|
|
CustomerFilterKeys,
|
2020-05-14 09:30:32 +00:00
|
|
|
CustomerListFilterOpts
|
2020-01-10 12:50:28 +00:00
|
|
|
} from "./filters";
|
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 {
|
2022-03-09 08:56:55 +00:00
|
|
|
customers: RelayToFlat<ListCustomersQuery["customers"]>;
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
|
2019-11-07 11:34:54 +00:00
|
|
|
const CustomerListPage: React.FC<CustomerListPageProps> = ({
|
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,
|
|
|
|
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
|
2019-08-23 12:23:59 +00:00
|
|
|
}) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
2022-03-01 08:38:23 +00:00
|
|
|
const userPermissions = useUserPermissions();
|
|
|
|
const structure = createFilterStructure(intl, filterOpts, userPermissions);
|
2020-01-02 12:22:12 +00:00
|
|
|
|
2019-08-23 12:23:59 +00:00
|
|
|
return (
|
|
|
|
<Container>
|
|
|
|
<PageHeader title={intl.formatMessage(sectionNames.customers)}>
|
2022-02-11 11:28:55 +00:00
|
|
|
<Button
|
|
|
|
variant="primary"
|
2022-05-06 08:59:55 +00:00
|
|
|
href={customerAddUrl}
|
2022-02-11 11:28:55 +00:00
|
|
|
data-test-id="create-customer"
|
|
|
|
>
|
2019-08-23 12:23:59 +00:00
|
|
|
<FormattedMessage
|
2022-05-05 07:54:28 +00:00
|
|
|
id="QLVddq"
|
2019-11-26 14:34:56 +00:00
|
|
|
defaultMessage="Create customer"
|
2019-08-23 12:23:59 +00:00
|
|
|
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({
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "xQK2EC",
|
2019-09-11 15:56:00 +00:00
|
|
|
defaultMessage: "All Customers",
|
|
|
|
description: "tab name"
|
|
|
|
})}
|
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({
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "2mRLis",
|
2019-09-11 14:39:52 +00:00
|
|
|
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>
|
2019-08-23 12:23:59 +00:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
CustomerListPage.displayName = "CustomerListPage";
|
|
|
|
export default CustomerListPage;
|