diff --git a/src/customers/components/CustomerListPage/CustomerListPage.tsx b/src/customers/components/CustomerListPage/CustomerListPage.tsx index 371e2ec98..2c45b6f05 100644 --- a/src/customers/components/CustomerListPage/CustomerListPage.tsx +++ b/src/customers/components/CustomerListPage/CustomerListPage.tsx @@ -14,14 +14,14 @@ import { FilterPageProps } from "@saleor/types"; import { CustomerListUrlSortField } from "@saleor/customers/urls"; -import { - CustomerFilterKeys, - createFilterStructure -} from "@saleor/customers/views/CustomerList/filter"; -import { CustomerListFilterOpts } from "@saleor/customers/types"; import FilterBar from "@saleor/components/FilterBar"; import CustomerList from "../CustomerList/CustomerList"; import { ListCustomers_customers_edges_node } from "../../types/ListCustomers"; +import { + CustomerFilterKeys, + CustomerListFilterOpts, + createFilterStructure +} from "./filters"; export interface CustomerListPageProps extends PageListProps, diff --git a/src/customers/components/CustomerListPage/filters.ts b/src/customers/components/CustomerListPage/filters.ts new file mode 100644 index 000000000..71301bac9 --- /dev/null +++ b/src/customers/components/CustomerListPage/filters.ts @@ -0,0 +1,66 @@ +import { IntlShape, defineMessages } from "react-intl"; + +import { FilterOpts, MinMax } from "@saleor/types"; +import { IFilter } from "@saleor/components/Filter"; +import { + createDateField, + createNumberField +} from "@saleor/utils/filters/fields"; + +export enum CustomerFilterKeys { + joined = "joined", + moneySpent = "spent", + numberOfOrders = "orders" +} + +export interface CustomerListFilterOpts { + joined: FilterOpts; + moneySpent: FilterOpts; + numberOfOrders: FilterOpts; +} + +const messages = defineMessages({ + joinDate: { + defaultMessage: "Join Date", + description: "customer" + }, + moneySpent: { + defaultMessage: "Money Spent", + description: "customer" + }, + numberOfOrders: { + defaultMessage: "Number of Orders" + } +}); + +export function createFilterStructure( + intl: IntlShape, + opts: CustomerListFilterOpts +): IFilter { + return [ + { + ...createDateField( + CustomerFilterKeys.joined, + intl.formatMessage(messages.joinDate), + opts.joined.value + ), + active: opts.joined.active + }, + { + ...createNumberField( + CustomerFilterKeys.moneySpent, + intl.formatMessage(messages.moneySpent), + opts.moneySpent.value + ), + active: opts.moneySpent.active + }, + { + ...createNumberField( + CustomerFilterKeys.numberOfOrders, + intl.formatMessage(messages.numberOfOrders), + opts.numberOfOrders.value + ), + active: opts.numberOfOrders.active + } + ]; +} diff --git a/src/customers/components/CustomerListPage/index.ts b/src/customers/components/CustomerListPage/index.ts index 59481bef5..fe790fd4f 100644 --- a/src/customers/components/CustomerListPage/index.ts +++ b/src/customers/components/CustomerListPage/index.ts @@ -1,2 +1,3 @@ export { default } from "./CustomerListPage"; export * from "./CustomerListPage"; +export * from "./filters"; diff --git a/src/customers/types.ts b/src/customers/types.ts index dfe785f5e..a0398abbb 100644 --- a/src/customers/types.ts +++ b/src/customers/types.ts @@ -1,11 +1,3 @@ -import { FilterOpts, MinMax } from "@saleor/types"; - -export interface CustomerListFilterOpts { - joined: FilterOpts; - moneySpent: FilterOpts; - numberOfOrders: FilterOpts; -} - export interface AddressTypeInput { city: string; cityArea?: string; diff --git a/src/customers/views/CustomerList/CustomerList.tsx b/src/customers/views/CustomerList/CustomerList.tsx index 9f61f4f36..7a5161949 100644 --- a/src/customers/views/CustomerList/CustomerList.tsx +++ b/src/customers/views/CustomerList/CustomerList.tsx @@ -44,7 +44,7 @@ import { saveFilterTab, getFilterQueryParam, getFilterOpts -} from "./filter"; +} from "./filters"; import { getSortQueryVariables } from "./sort"; interface CustomerListProps { diff --git a/src/customers/views/CustomerList/filter.ts b/src/customers/views/CustomerList/filters.ts similarity index 75% rename from src/customers/views/CustomerList/filter.ts rename to src/customers/views/CustomerList/filters.ts index 44c238aa8..92c398ac7 100644 --- a/src/customers/views/CustomerList/filter.ts +++ b/src/customers/views/CustomerList/filters.ts @@ -1,12 +1,10 @@ -import { IntlShape } from "react-intl"; - import { CustomerFilterInput } from "@saleor/types/globalTypes"; import { maybe } from "@saleor/misc"; +import { IFilterElement } from "@saleor/components/Filter"; import { - createDateField, - createNumberField -} from "@saleor/utils/filters/fields"; -import { IFilter, IFilterElement } from "@saleor/components/Filter"; + CustomerFilterKeys, + CustomerListFilterOpts +} from "@saleor/customers/components/CustomerListPage"; import { createFilterTabUtils, createFilterUtils @@ -16,17 +14,9 @@ import { CustomerListUrlFiltersEnum, CustomerListUrlQueryParams } from "../../urls"; -import { CustomerListFilterOpts } from "../../types"; -import messages from "./messages"; export const CUSTOMER_FILTERS_KEY = "customerFilters"; -export enum CustomerFilterKeys { - joined = "joined", - moneySpent = "spent", - numberOfOrders = "orders" -} - export function getFilterOpts( params: CustomerListUrlFilters ): CustomerListFilterOpts { @@ -73,38 +63,6 @@ export function getFilterOpts( }; } -export function createFilterStructure( - intl: IntlShape, - opts: CustomerListFilterOpts -): IFilter { - return [ - { - ...createDateField( - CustomerFilterKeys.joined, - intl.formatMessage(messages.joinDate), - opts.joined.value - ), - active: opts.joined.active - }, - { - ...createNumberField( - CustomerFilterKeys.moneySpent, - intl.formatMessage(messages.moneySpent), - opts.moneySpent.value - ), - active: opts.moneySpent.active - }, - { - ...createNumberField( - CustomerFilterKeys.numberOfOrders, - intl.formatMessage(messages.numberOfOrders), - opts.numberOfOrders.value - ), - active: opts.numberOfOrders.active - } - ]; -} - export function getFilterVariables( params: CustomerListUrlFilters ): CustomerFilterInput { diff --git a/src/customers/views/CustomerList/messages.ts b/src/customers/views/CustomerList/messages.ts deleted file mode 100644 index 8ba6fd197..000000000 --- a/src/customers/views/CustomerList/messages.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { defineMessages } from "react-intl"; - -const messages = defineMessages({ - joinDate: { - defaultMessage: "Join Date", - description: "customer" - }, - moneySpent: { - defaultMessage: "Money Spent", - description: "customer" - }, - numberOfOrders: { - defaultMessage: "Number of Orders" - } -}); - -export default messages;