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

138 lines
3.9 KiB
TypeScript
Raw Normal View History

// @ts-strict-ignore
2023-03-06 09:57:25 +00:00
import {
extensionMountPoints,
mapToMenuItems,
mapToMenuItemsForCustomerOverviewActions,
useExtensions,
} from "@dashboard/apps/hooks/useExtensions";
import { useUserPermissions } from "@dashboard/auth/hooks/useUserPermissions";
import { TopNav } from "@dashboard/components/AppLayout/TopNav";
import ButtonWithSelect from "@dashboard/components/ButtonWithSelect";
import CardMenu from "@dashboard/components/CardMenu/CardMenu";
import FilterBar from "@dashboard/components/FilterBar";
import {
customerAddUrl,
CustomerListUrlSortField,
} 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 {
FilterPageProps,
2019-09-11 14:39:52 +00:00
ListActions,
PageListProps,
Use graphql-codegen (#1874) * Use generated hooks in apps * Remove unused files * Use proper types in apps * Use generated hooks in attributes * Use generated hooks in auth module * Use generated hooks in categories * Use generated hooks in channels * Use generated types in collections * Remove legacy types from background tasks * Use generated hooks in customers * Use generated hooks in discounts * Use generated hook in file upload * Use generated types in gift cards * Use generated types in home * Use generated hooks in navigation * Use generated hooks in orders * Use generated hooks in pages * Use generated hooks in page types * Use generated hooks in permission groups * Use generated hooks in plugins * Use generated hooks in products * Use fragment to mark product variants * Improve code a bit * Use generated hooks in page types * Use generated types in searches * Use generated hooks in shipping * Use generated hooks in site settings * Use generated hooks in staff members * Use generated hooks in taxes * Place all gql generated files in one directory * Use generated hooks in translations * Use global types from new generated module * Use generated hooks in warehouses * Use generated hooks in webhooks * Use generated fragment types * Unclutter types * Remove hoc components * Split hooks and types * Fetch introspection file * Delete obsolete schema file * Fix rebase artifacts * Fix autoreplace * Fix auth provider tests * Fix urls * Remove leftover types * Fix rebase artifacts
2022-03-09 08:56:55 +00:00
RelayToFlat,
2020-01-02 12:22:12 +00:00
SortPage,
TabPageProps,
} from "@dashboard/types";
import { Card } from "@material-ui/core";
import { makeStyles } from "@saleor/macaw-ui";
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
import CustomerList from "../CustomerList/CustomerList";
import {
createFilterStructure,
CustomerFilterKeys,
CustomerListFilterOpts,
} from "./filters";
2019-06-19 14:40:52 +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 {
Use graphql-codegen (#1874) * Use generated hooks in apps * Remove unused files * Use proper types in apps * Use generated hooks in attributes * Use generated hooks in auth module * Use generated hooks in categories * Use generated hooks in channels * Use generated types in collections * Remove legacy types from background tasks * Use generated hooks in customers * Use generated hooks in discounts * Use generated hook in file upload * Use generated types in gift cards * Use generated types in home * Use generated hooks in navigation * Use generated hooks in orders * Use generated hooks in pages * Use generated hooks in page types * Use generated hooks in permission groups * Use generated hooks in plugins * Use generated hooks in products * Use fragment to mark product variants * Improve code a bit * Use generated hooks in page types * Use generated types in searches * Use generated hooks in shipping * Use generated hooks in site settings * Use generated hooks in staff members * Use generated hooks in taxes * Place all gql generated files in one directory * Use generated hooks in translations * Use global types from new generated module * Use generated hooks in warehouses * Use generated hooks in webhooks * Use generated fragment types * Unclutter types * Remove hoc components * Split hooks and types * Fetch introspection file * Delete obsolete schema file * Fix rebase artifacts * Fix autoreplace * Fix auth provider tests * Fix urls * Remove leftover types * Fix rebase artifacts
2022-03-09 08:56:55 +00:00
customers: RelayToFlat<ListCustomersQuery["customers"]>;
selectedCustomerIds: string[];
2019-06-19 14:40:52 +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,
selectedCustomerIds,
2019-06-19 14:40:52 +00:00
...customerListProps
}) => {
const intl = useIntl();
const classes = useStyles({});
const navigate = useNavigator();
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);
const extensionMenuItems = mapToMenuItemsForCustomerOverviewActions(
CUSTOMER_OVERVIEW_MORE_ACTIONS,
selectedCustomerIds,
);
const extensionCreateButtonItems = mapToMenuItems(CUSTOMER_OVERVIEW_CREATE);
return (
<>
<TopNav title={intl.formatMessage(sectionNames.customers)}>
{extensionMenuItems.length > 0 && (
<CardMenu
className={classes.settings}
menuItems={extensionMenuItems}
/>
)}
<ButtonWithSelect
onClick={() => navigate(customerAddUrl)}
options={extensionCreateButtonItems}
data-test-id="create-customer"
>
<FormattedMessage
id="QLVddq"
2019-11-26 14:34:56 +00:00
defaultMessage="Create customer"
description="button"
/>
</ButtonWithSelect>
</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({
id: "xQK2EC",
2019-09-11 15:56:00 +00:00
defaultMessage: "All Customers",
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({
id: "2mRLis",
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>
</>
);
};
2019-06-19 14:40:52 +00:00
CustomerListPage.displayName = "CustomerListPage";
export default CustomerListPage;