2022-01-28 12:34:20 +00:00
|
|
|
import { Card } from "@material-ui/core";
|
2019-06-19 14:40:52 +00:00
|
|
|
import Container from "@saleor/components/Container";
|
2022-02-02 08:48:12 +00:00
|
|
|
import { getByName } from "@saleor/components/Filter/utils";
|
2020-01-03 15:17:51 +00:00
|
|
|
import FilterBar from "@saleor/components/FilterBar";
|
2020-05-14 09:30:32 +00:00
|
|
|
import PageHeader from "@saleor/components/PageHeader";
|
|
|
|
import { VoucherListUrlSortField } from "@saleor/discounts/urls";
|
2019-08-26 13:59:32 +00:00
|
|
|
import { sectionNames } from "@saleor/intl";
|
2022-01-28 12:34:20 +00:00
|
|
|
import { Button } from "@saleor/macaw-ui";
|
2019-09-12 10:06:28 +00:00
|
|
|
import {
|
2020-11-23 09:39:24 +00:00
|
|
|
ChannelProps,
|
2020-05-14 09:30:32 +00:00
|
|
|
FilterPageProps,
|
2019-09-12 10:06:28 +00:00
|
|
|
ListActions,
|
|
|
|
PageListProps,
|
2020-01-03 15:17:51 +00:00
|
|
|
SortPage,
|
2020-05-14 09:30:32 +00:00
|
|
|
TabPageProps
|
2019-09-12 10:06:28 +00:00
|
|
|
} from "@saleor/types";
|
2020-05-14 09:30:32 +00:00
|
|
|
import React from "react";
|
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
import { VoucherList_vouchers_edges_node } from "../../types/VoucherList";
|
|
|
|
import VoucherList from "../VoucherList";
|
2020-01-10 13:01:26 +00:00
|
|
|
import {
|
2020-05-14 09:30:32 +00:00
|
|
|
createFilterStructure,
|
2020-01-10 13:01:26 +00:00
|
|
|
VoucherFilterKeys,
|
2020-05-14 09:30:32 +00:00
|
|
|
VoucherListFilterOpts
|
2020-01-10 13:01:26 +00:00
|
|
|
} from "./filters";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
2019-09-12 10:06:28 +00:00
|
|
|
export interface VoucherListPageProps
|
|
|
|
extends PageListProps,
|
|
|
|
ListActions,
|
2020-01-03 15:17:51 +00:00
|
|
|
FilterPageProps<VoucherFilterKeys, VoucherListFilterOpts>,
|
2019-12-17 17:13:56 +00:00
|
|
|
SortPage<VoucherListUrlSortField>,
|
2020-11-23 09:39:24 +00:00
|
|
|
TabPageProps,
|
|
|
|
ChannelProps {
|
2019-06-19 14:40:52 +00:00
|
|
|
vouchers: VoucherList_vouchers_edges_node[];
|
|
|
|
}
|
2019-11-07 11:34:54 +00:00
|
|
|
const VoucherListPage: React.FC<VoucherListPageProps> = ({
|
2019-09-12 10:06:28 +00:00
|
|
|
currentTab,
|
2020-01-03 15:17:51 +00:00
|
|
|
filterOpts,
|
2019-09-12 10:06:28 +00:00
|
|
|
initialSearch,
|
2019-06-19 14:40:52 +00:00
|
|
|
onAdd,
|
2019-09-12 10:06:28 +00:00
|
|
|
onAll,
|
2020-01-03 15:17:51 +00:00
|
|
|
onFilterChange,
|
2019-09-12 10:06:28 +00:00
|
|
|
onSearchChange,
|
|
|
|
onTabChange,
|
|
|
|
onTabDelete,
|
|
|
|
onTabSave,
|
|
|
|
tabs,
|
|
|
|
...listProps
|
2019-08-26 13:59:32 +00:00
|
|
|
}) => {
|
|
|
|
const intl = useIntl();
|
2020-01-03 15:17:51 +00:00
|
|
|
const structure = createFilterStructure(intl, filterOpts);
|
|
|
|
|
2022-02-02 08:48:12 +00:00
|
|
|
const filterDependency = structure.find(getByName("channel"));
|
|
|
|
|
2019-08-26 13:59:32 +00:00
|
|
|
return (
|
|
|
|
<Container>
|
|
|
|
<PageHeader title={intl.formatMessage(sectionNames.vouchers)}>
|
2022-01-28 12:34:20 +00:00
|
|
|
<Button onClick={onAdd} variant="primary" data-test-id="create-voucher">
|
2019-09-05 13:33:50 +00:00
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="Create voucher"
|
|
|
|
description="button"
|
|
|
|
/>
|
2019-08-26 13:59:32 +00:00
|
|
|
</Button>
|
|
|
|
</PageHeader>
|
2019-09-12 10:06:28 +00:00
|
|
|
<Card>
|
2020-01-03 15:17:51 +00:00
|
|
|
<FilterBar
|
2019-09-12 10:06:28 +00:00
|
|
|
allTabLabel={intl.formatMessage({
|
|
|
|
defaultMessage: "All Vouchers",
|
|
|
|
description: "tab name"
|
|
|
|
})}
|
|
|
|
currentTab={currentTab}
|
2020-01-03 15:17:51 +00:00
|
|
|
filterStructure={structure}
|
2019-09-12 10:06:28 +00:00
|
|
|
initialSearch={initialSearch}
|
|
|
|
searchPlaceholder={intl.formatMessage({
|
|
|
|
defaultMessage: "Search Voucher"
|
|
|
|
})}
|
|
|
|
tabs={tabs}
|
|
|
|
onAll={onAll}
|
2020-01-03 15:17:51 +00:00
|
|
|
onFilterChange={onFilterChange}
|
2019-09-12 10:06:28 +00:00
|
|
|
onSearchChange={onSearchChange}
|
|
|
|
onTabChange={onTabChange}
|
|
|
|
onTabDelete={onTabDelete}
|
|
|
|
onTabSave={onTabSave}
|
|
|
|
/>
|
2022-02-02 08:48:12 +00:00
|
|
|
<VoucherList filterDependency={filterDependency} {...listProps} />
|
2019-09-12 10:06:28 +00:00
|
|
|
</Card>
|
2019-08-26 13:59:32 +00:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
VoucherListPage.displayName = "VoucherListPage";
|
|
|
|
export default VoucherListPage;
|