saleor-dashboard/src/collections/components/CollectionListPage/CollectionListPage.tsx

98 lines
2.7 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import Button from "@material-ui/core/Button";
2019-09-11 14:00:02 +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-07 13:34:45 +00:00
import FilterBar from "@saleor/components/FilterBar";
import { sectionNames } from "@saleor/intl";
2019-09-11 14:00:02 +00:00
import {
ListActions,
PageListProps,
2020-01-07 13:34:45 +00:00
FilterPageProps,
2019-12-17 17:13:56 +00:00
TabPageProps,
SortPage
2019-09-11 14:00:02 +00:00
} from "@saleor/types";
2019-12-17 17:13:56 +00:00
import { CollectionListUrlSortField } from "@saleor/collections/urls";
import { CollectionList_collections_edges_node } from "../../types/CollectionList";
import CollectionList from "../CollectionList/CollectionList";
2020-01-07 13:34:45 +00:00
import {
CollectionFilterKeys,
CollectionListFilterOpts,
2020-01-07 13:34:45 +00:00
createFilterStructure
} from "./filters";
2019-06-19 14:40:52 +00:00
2019-09-11 14:00:02 +00:00
export interface CollectionListPageProps
extends PageListProps,
ListActions,
2020-01-07 13:34:45 +00:00
FilterPageProps<CollectionFilterKeys, CollectionListFilterOpts>,
2019-12-17 17:13:56 +00:00
SortPage<CollectionListUrlSortField>,
2019-09-11 14:00:02 +00:00
TabPageProps {
2019-06-19 14:40:52 +00:00
collections: CollectionList_collections_edges_node[];
}
const CollectionListPage: React.FC<CollectionListPageProps> = ({
2020-01-07 13:34:45 +00:00
currencySymbol,
2019-09-11 14:00:02 +00:00
currentTab,
2019-06-19 14:40:52 +00:00
disabled,
2020-01-07 13:34:45 +00:00
filterOpts,
2019-09-11 14:00:02 +00:00
initialSearch,
2019-06-19 14:40:52 +00:00
onAdd,
2019-09-11 14:00:02 +00:00
onAll,
2020-01-07 13:34:45 +00:00
onFilterChange,
2019-09-11 14:00:02 +00:00
onSearchChange,
onTabChange,
onTabDelete,
onTabSave,
tabs,
2019-06-19 14:40:52 +00:00
...listProps
}) => {
const intl = useIntl();
2020-01-07 13:34:45 +00:00
const structure = createFilterStructure(intl, filterOpts);
return (
<Container>
<PageHeader title={intl.formatMessage(sectionNames.collections)}>
<Button
color="primary"
disabled={disabled}
variant="contained"
onClick={onAdd}
>
2019-08-22 16:25:55 +00:00
<FormattedMessage
2019-09-05 13:33:50 +00:00
defaultMessage="Create collection"
description="button"
2019-08-22 16:25:55 +00:00
/>
</Button>
</PageHeader>
2019-09-11 14:00:02 +00:00
<Card>
2020-01-07 13:34:45 +00:00
<FilterBar
2019-09-11 15:56:00 +00:00
allTabLabel={intl.formatMessage({
defaultMessage: "All Collections",
description: "tab name"
})}
2020-01-07 13:34:45 +00:00
currencySymbol={currencySymbol}
2019-09-11 14:00:02 +00:00
currentTab={currentTab}
2020-01-07 13:34:45 +00:00
filterStructure={structure}
2019-09-11 14:00:02 +00:00
initialSearch={initialSearch}
searchPlaceholder={intl.formatMessage({
defaultMessage: "Search Collection"
})}
tabs={tabs}
onAll={onAll}
2020-01-07 13:34:45 +00:00
onFilterChange={onFilterChange}
2019-09-11 14:00:02 +00:00
onSearchChange={onSearchChange}
onTabChange={onTabChange}
onTabDelete={onTabDelete}
onTabSave={onTabSave}
/>
<CollectionList disabled={disabled} {...listProps} />
</Card>
</Container>
);
};
2019-06-19 14:40:52 +00:00
CollectionListPage.displayName = "CollectionListPage";
export default CollectionListPage;