saleor-dashboard/src/orders/components/OrderListPage/OrderListPage.tsx

128 lines
3.7 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import Button from "@material-ui/core/Button";
import Card from "@material-ui/core/Card";
import Alert from "@saleor/components/Alert/Alert";
import CardMenu from "@saleor/components/CardMenu";
2019-06-19 14:40:52 +00:00
import Container from "@saleor/components/Container";
import FilterBar from "@saleor/components/FilterBar";
2019-06-19 14:40:52 +00:00
import PageHeader from "@saleor/components/PageHeader";
import { RefreshLimits_shop_limits } from "@saleor/components/Shop/types/RefreshLimits";
import { sectionNames } from "@saleor/intl";
2019-12-17 17:13:56 +00:00
import { OrderListUrlSortField } from "@saleor/orders/urls";
import { makeStyles } from "@saleor/theme";
import { FilterPageProps, PageListProps, SortPage } from "@saleor/types";
import { isLimitReached } from "@saleor/utils/limits";
import React from "react";
import { FormattedMessage, useIntl } from "react-intl";
2019-06-19 14:40:52 +00:00
import { OrderList_orders_edges_node } from "../../types/OrderList";
import OrderList from "../OrderList";
import {
createFilterStructure,
OrderFilterKeys,
OrderListFilterOpts
} from "./filters";
2019-06-19 14:40:52 +00:00
export interface OrderListPageProps
extends PageListProps,
2019-12-20 15:53:03 +00:00
FilterPageProps<OrderFilterKeys, OrderListFilterOpts>,
2019-12-17 17:13:56 +00:00
SortPage<OrderListUrlSortField> {
limits: RefreshLimits_shop_limits;
2019-06-19 14:40:52 +00:00
orders: OrderList_orders_edges_node[];
onSettingsOpen: () => void;
2019-06-19 14:40:52 +00:00
}
const useStyles = makeStyles(
theme => ({
settings: {
marginRight: theme.spacing(2)
}
}),
{ name: "OrderListPage" }
);
2019-06-19 14:40:52 +00:00
const OrderListPage: React.FC<OrderListPageProps> = ({
currentTab,
initialSearch,
2019-12-20 15:53:03 +00:00
filterOpts,
limits,
2019-09-10 15:14:11 +00:00
tabs,
2019-06-19 14:40:52 +00:00
onAdd,
onAll,
onSearchChange,
onSettingsOpen,
2019-12-20 10:44:41 +00:00
onFilterChange,
2019-06-19 14:40:52 +00:00
onTabChange,
2019-09-10 15:39:33 +00:00
onTabDelete,
onTabSave,
2019-06-19 14:40:52 +00:00
...listProps
}) => {
const intl = useIntl();
const classes = useStyles({});
2019-12-20 15:53:03 +00:00
const filterStructure = createFilterStructure(intl, filterOpts);
2019-12-20 10:44:41 +00:00
return (
<Container>
<PageHeader title={intl.formatMessage(sectionNames.orders)}>
{!!onSettingsOpen && (
<CardMenu
className={classes.settings}
menuItems={[
{
label: intl.formatMessage({
defaultMessage: "Order Settings",
description: "button"
}),
onSelect: onSettingsOpen
}
]}
/>
)}
<Button
color="primary"
variant="contained"
onClick={onAdd}
data-test-id="create-order-button"
>
<FormattedMessage
defaultMessage="Create order"
description="button"
/>
</Button>
</PageHeader>
<Alert
show={isLimitReached(limits, "orders")}
title={intl.formatMessage({
defaultMessage: "Order limit reached",
description: "alert"
})}
>
<FormattedMessage defaultMessage="You have reached your order limit, you will be billed extra for orders above limit. If you would like to up your limit, contact your administration staff about raising your limits." />
</Alert>
<Card>
2019-12-20 10:44:41 +00:00
<FilterBar
currentTab={currentTab}
initialSearch={initialSearch}
onAll={onAll}
2019-12-20 10:44:41 +00:00
onFilterChange={onFilterChange}
onSearchChange={onSearchChange}
onTabChange={onTabChange}
2019-09-10 15:39:33 +00:00
onTabDelete={onTabDelete}
onTabSave={onTabSave}
2019-12-20 10:44:41 +00:00
tabs={tabs}
allTabLabel={intl.formatMessage({
2019-12-20 16:31:26 +00:00
defaultMessage: "All Orders",
2019-12-20 10:44:41 +00:00
description: "tab name"
})}
filterStructure={filterStructure}
searchPlaceholder={intl.formatMessage({
2019-12-20 16:31:26 +00:00
defaultMessage: "Search Orders..."
2019-12-20 10:44:41 +00:00
})}
/>
<OrderList {...listProps} />
</Card>
</Container>
);
};
2019-06-19 14:40:52 +00:00
OrderListPage.displayName = "OrderListPage";
export default OrderListPage;