saleor-dashboard/src/discounts/components/VoucherListPage/VoucherListPage.tsx
Dominik Żegleń 7d9441a7ec
Use esbuild-loader (#1983)
* Minor fixes for intl messages

* Add esbuild-loader
* switch from babel to esbuild-loader
* use formatjs enforce-id linter

* Generate ids for intl messages

* id format defined by idInterpolationPattern

* Modify intl messages extraction

* remove react-intl-translations-manager
* remove transpile-tx.js
* use formatjs cli

* Modify defaultMessages.json

* modify ids in defaultMessages.json with defined idInterpolationPattern

* Fix errors

* Fix page crash

* Use babel to transpile tests

* Fix useStateFromProps

* Improve render count

* Add test to useStateFromProps

* Fix reloading state buh

* Do not check if form with channels is dirty

* Stop blocking save if form has not changed

* Remove debug code

* Fix form disabling

* Fix variant selection checkbox onClick

* Update translations

* Update messages

* Use esbuild to build storybook

Co-authored-by: Bartłomiej Wiaduch <tukan2can@gmail.com>
Co-authored-by: Jakub Majorek <majorek.jakub@gmail.com>
2022-05-05 09:54:28 +02:00

95 lines
2.6 KiB
TypeScript

import { Card } from "@material-ui/core";
import Container from "@saleor/components/Container";
import { getByName } from "@saleor/components/Filter/utils";
import FilterBar from "@saleor/components/FilterBar";
import PageHeader from "@saleor/components/PageHeader";
import { VoucherListUrlSortField } from "@saleor/discounts/urls";
import { VoucherFragment } from "@saleor/graphql";
import { sectionNames } from "@saleor/intl";
import { Button } from "@saleor/macaw-ui";
import {
ChannelProps,
FilterPageProps,
ListActions,
PageListProps,
SortPage,
TabPageProps
} from "@saleor/types";
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
import VoucherList from "../VoucherList";
import {
createFilterStructure,
VoucherFilterKeys,
VoucherListFilterOpts
} from "./filters";
export interface VoucherListPageProps
extends PageListProps,
ListActions,
FilterPageProps<VoucherFilterKeys, VoucherListFilterOpts>,
SortPage<VoucherListUrlSortField>,
TabPageProps,
ChannelProps {
vouchers: VoucherFragment[];
}
const VoucherListPage: React.FC<VoucherListPageProps> = ({
currentTab,
filterOpts,
initialSearch,
onAdd,
onAll,
onFilterChange,
onSearchChange,
onTabChange,
onTabDelete,
onTabSave,
tabs,
...listProps
}) => {
const intl = useIntl();
const structure = createFilterStructure(intl, filterOpts);
const filterDependency = structure.find(getByName("channel"));
return (
<Container>
<PageHeader title={intl.formatMessage(sectionNames.vouchers)}>
<Button onClick={onAdd} variant="primary" data-test-id="create-voucher">
<FormattedMessage
id="GbhZJ4"
defaultMessage="Create voucher"
description="button"
/>
</Button>
</PageHeader>
<Card>
<FilterBar
allTabLabel={intl.formatMessage({
id: "pNrF72",
defaultMessage: "All Vouchers",
description: "tab name"
})}
currentTab={currentTab}
filterStructure={structure}
initialSearch={initialSearch}
searchPlaceholder={intl.formatMessage({
id: "IruP2T",
defaultMessage: "Search Voucher"
})}
tabs={tabs}
onAll={onAll}
onFilterChange={onFilterChange}
onSearchChange={onSearchChange}
onTabChange={onTabChange}
onTabDelete={onTabDelete}
onTabSave={onTabSave}
/>
<VoucherList filterDependency={filterDependency} {...listProps} />
</Card>
</Container>
);
};
VoucherListPage.displayName = "VoucherListPage";
export default VoucherListPage;