2023-03-06 09:57:25 +00:00
|
|
|
import {
|
|
|
|
extensionMountPoints,
|
|
|
|
mapToMenuItems,
|
|
|
|
mapToMenuItemsForCustomerOverviewActions,
|
|
|
|
useExtensions,
|
|
|
|
} from "@dashboard/apps/hooks/useExtensions";
|
2023-01-16 09:45:12 +00:00
|
|
|
import { useUserPermissions } from "@dashboard/auth/hooks/useUserPermissions";
|
2023-02-20 15:21:28 +00:00
|
|
|
import { TopNav } from "@dashboard/components/AppLayout/TopNav";
|
2023-01-16 09:45:12 +00:00
|
|
|
import ButtonWithSelect from "@dashboard/components/ButtonWithSelect";
|
|
|
|
import CardMenu from "@dashboard/components/CardMenu/CardMenu";
|
|
|
|
import FilterBar from "@dashboard/components/FilterBar";
|
2022-05-06 08:59:55 +00:00
|
|
|
import {
|
|
|
|
customerAddUrl,
|
2022-06-21 09:36:55 +00:00
|
|
|
CustomerListUrlSortField,
|
2023-01-16 09:45:12 +00:00
|
|
|
} from "@dashboard/customers/urls";
|
|
|
|
import { ListCustomersQuery } from "@dashboard/graphql";
|
|
|
|
import useNavigator from "@dashboard/hooks/useNavigator";
|
|
|
|
import { sectionNames } from "@dashboard/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,
|
2022-06-21 09:36:55 +00:00
|
|
|
TabPageProps,
|
2023-01-16 09:45:12 +00:00
|
|
|
} from "@dashboard/types";
|
|
|
|
import { Card } from "@material-ui/core";
|
|
|
|
import { makeStyles } from "@saleor/macaw-ui";
|
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,
|
2022-06-21 09:36:55 +00:00
|
|
|
CustomerListFilterOpts,
|
2020-01-10 12:50:28 +00:00
|
|
|
} from "./filters";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2022-10-26 11:19:20 +00:00
|
|
|
const useStyles = makeStyles(
|
|
|
|
theme => ({
|
|
|
|
settings: {
|
|
|
|
marginRight: theme.spacing(2),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
{ name: "CustomerListPage" },
|
|
|
|
);
|
|
|
|
|
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"]>;
|
2022-10-26 11:19:20 +00:00
|
|
|
selectedCustomerIds: string[];
|
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,
|
2022-10-26 11:19:20 +00:00
|
|
|
selectedCustomerIds,
|
2019-06-19 14:40:52 +00:00
|
|
|
...customerListProps
|
2019-08-23 12:23:59 +00:00
|
|
|
}) => {
|
|
|
|
const intl = useIntl();
|
2022-10-26 11:19:20 +00:00
|
|
|
const classes = useStyles({});
|
|
|
|
const navigate = useNavigator();
|
2019-08-23 12:23:59 +00:00
|
|
|
|
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
|
|
|
|
2023-02-28 09:50:54 +00:00
|
|
|
const { CUSTOMER_OVERVIEW_CREATE, CUSTOMER_OVERVIEW_MORE_ACTIONS } =
|
|
|
|
useExtensions(extensionMountPoints.CUSTOMER_LIST);
|
2022-10-26 11:19:20 +00:00
|
|
|
const extensionMenuItems = mapToMenuItemsForCustomerOverviewActions(
|
|
|
|
CUSTOMER_OVERVIEW_MORE_ACTIONS,
|
|
|
|
selectedCustomerIds,
|
|
|
|
);
|
|
|
|
const extensionCreateButtonItems = mapToMenuItems(CUSTOMER_OVERVIEW_CREATE);
|
|
|
|
|
2019-08-23 12:23:59 +00:00
|
|
|
return (
|
2023-02-20 15:21:28 +00:00
|
|
|
<>
|
|
|
|
<TopNav title={intl.formatMessage(sectionNames.customers)}>
|
|
|
|
{extensionMenuItems.length > 0 && (
|
|
|
|
<CardMenu
|
|
|
|
className={classes.settings}
|
|
|
|
menuItems={extensionMenuItems}
|
|
|
|
/>
|
|
|
|
)}
|
2022-10-26 11:19:20 +00:00
|
|
|
<ButtonWithSelect
|
|
|
|
onClick={() => navigate(customerAddUrl)}
|
|
|
|
options={extensionCreateButtonItems}
|
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"
|
|
|
|
/>
|
2022-10-26 11:19:20 +00:00
|
|
|
</ButtonWithSelect>
|
2023-02-20 15:21:28 +00:00
|
|
|
</TopNav>
|
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",
|
2022-06-21 09:36:55 +00:00
|
|
|
description: "tab name",
|
2019-09-11 15:56:00 +00:00
|
|
|
})}
|
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",
|
2022-06-21 09:36:55 +00:00
|
|
|
defaultMessage: "Search Customer",
|
2019-09-11 14:39:52 +00:00
|
|
|
})}
|
|
|
|
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>
|
2023-02-20 15:21:28 +00:00
|
|
|
</>
|
2019-08-23 12:23:59 +00:00
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
CustomerListPage.displayName = "CustomerListPage";
|
|
|
|
export default CustomerListPage;
|