saleor-dashboard/src/discounts/components/VoucherListPage/VoucherListPage.tsx

94 lines
2.5 KiB
TypeScript
Raw Normal View History

import { Button, Card } from "@material-ui/core";
2019-06-19 14:40:52 +00:00
import Container from "@saleor/components/Container";
2020-01-03 15:17:51 +00:00
import FilterBar from "@saleor/components/FilterBar";
import PageHeader from "@saleor/components/PageHeader";
import { VoucherListUrlSortField } from "@saleor/discounts/urls";
import { sectionNames } from "@saleor/intl";
2019-09-12 10:06:28 +00:00
import {
ChannelProps,
FilterPageProps,
2019-09-12 10:06:28 +00:00
ListActions,
PageListProps,
2020-01-03 15:17:51 +00:00
SortPage,
TabPageProps
2019-09-12 10:06:28 +00:00
} from "@saleor/types";
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";
import {
createFilterStructure,
VoucherFilterKeys,
VoucherListFilterOpts
} 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>,
TabPageProps,
ChannelProps {
2019-06-19 14:40:52 +00:00
vouchers: VoucherList_vouchers_edges_node[];
}
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
}) => {
const intl = useIntl();
2020-01-03 15:17:51 +00:00
const structure = createFilterStructure(intl, filterOpts);
return (
<Container>
<PageHeader title={intl.formatMessage(sectionNames.vouchers)}>
<Button
onClick={onAdd}
variant="contained"
color="primary"
data-test-id="create-voucher"
>
2019-09-05 13:33:50 +00:00
<FormattedMessage
defaultMessage="Create voucher"
description="button"
/>
</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}
/>
<VoucherList {...listProps} />
</Card>
</Container>
);
};
2019-06-19 14:40:52 +00:00
VoucherListPage.displayName = "VoucherListPage";
export default VoucherListPage;