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

93 lines
2.6 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import Button from "@material-ui/core/Button";
2019-09-12 10:06:28 +00:00
import Card from "@material-ui/core/Card";
2019-08-09 10:26:22 +00:00
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
2019-06-19 14:40:52 +00:00
import Container from "@saleor/components/Container";
import PageHeader from "@saleor/components/PageHeader";
2020-01-03 15:17:51 +00:00
import FilterBar from "@saleor/components/FilterBar";
import { sectionNames } from "@saleor/intl";
2019-09-12 10:06:28 +00:00
import {
ListActions,
PageListProps,
2019-12-17 17:13:56 +00:00
TabPageProps,
2020-01-03 15:17:51 +00:00
SortPage,
FilterPageProps
2019-09-12 10:06:28 +00:00
} from "@saleor/types";
2019-12-17 17:13:56 +00:00
import { VoucherListUrlSortField } from "@saleor/discounts/urls";
2020-01-03 15:17:51 +00:00
import {
createFilterStructure,
VoucherFilterKeys
} from "@saleor/discounts/views/VoucherList/filter";
import { VoucherListFilterOpts } from "@saleor/discounts/types";
2019-06-19 14:40:52 +00:00
import { VoucherList_vouchers_edges_node } from "../../types/VoucherList";
import VoucherList from "../VoucherList";
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>,
2019-09-12 10:06:28 +00:00
TabPageProps {
2019-06-19 14:40:52 +00:00
defaultCurrency: string;
vouchers: VoucherList_vouchers_edges_node[];
}
const VoucherListPage: React.FC<VoucherListPageProps> = ({
2020-01-03 15:17:51 +00:00
currencySymbol,
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">
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"
})}
2020-01-03 15:17:51 +00:00
currencySymbol={currencySymbol}
2019-09-12 10:06:28 +00:00
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;