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

128 lines
3.8 KiB
TypeScript
Raw Normal View History

import { Button, Card } from "@material-ui/core";
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";
Use MacawUI (#1229) * Replace withStyleswith useStyles (#1100) * Replace withStyleswith useStyles * Update messages * Use rem as a spacing unit (#1101) * Use rems as spacing units * Fix visual bugs * Update stories * Use macaw-ui as theme provider (#1108) * Use macaw ui as a theme provider * Add react-dom to aliases * Fix jest module resolution * Update useTheme hook usage * Fix test wrapper * Use macaw from git repo * Fix CI * Update stories * Fix aliasing * Extract savebar to macaw ui (#1146) * wip * Use savebar from macaw * Use confirm button from macaw * Improve file structure * Use sidebar context from macaw * Update macaw * Update macaw version * Remove savebar from storybook * Update stories * Use alerts and notifications from macaw (#1166) * Use alerts from macaw * Add notifications from macaw * Update stories * Pin macaw version * Encapsulate limit reached in one component * Remove unused imports * Use backlinks from macaw (#1183) * Use backlink from macaw * Update macaw version * Use macaw sidebar (#1148) * Use sidebar from macaw * Use shipped logo * Use lowercase * Update stories * Use user chip from macaw (#1191) * Use user chip from macaw * Use dedicated components for menu items * Simplify code * Bump version and fix types (#1210) * Rename onBack to onClick * Rename UserChip to UserChipMenu * Rename IMenuItem to SidebarMenuItem * Update macaw version * Fix tables after changes in macaw (#1220) * Update macaw version * Update changelog * Update stories * Fix after rebase * Update to macaw 0.2.0 * Lint files * Update macaw to 0.2.2
2021-07-21 08:59:52 +00:00
import LimitReachedAlert from "@saleor/components/LimitReachedAlert";
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";
Use MacawUI (#1229) * Replace withStyleswith useStyles (#1100) * Replace withStyleswith useStyles * Update messages * Use rem as a spacing unit (#1101) * Use rems as spacing units * Fix visual bugs * Update stories * Use macaw-ui as theme provider (#1108) * Use macaw ui as a theme provider * Add react-dom to aliases * Fix jest module resolution * Update useTheme hook usage * Fix test wrapper * Use macaw from git repo * Fix CI * Update stories * Fix aliasing * Extract savebar to macaw ui (#1146) * wip * Use savebar from macaw * Use confirm button from macaw * Improve file structure * Use sidebar context from macaw * Update macaw * Update macaw version * Remove savebar from storybook * Update stories * Use alerts and notifications from macaw (#1166) * Use alerts from macaw * Add notifications from macaw * Update stories * Pin macaw version * Encapsulate limit reached in one component * Remove unused imports * Use backlinks from macaw (#1183) * Use backlink from macaw * Update macaw version * Use macaw sidebar (#1148) * Use sidebar from macaw * Use shipped logo * Use lowercase * Update stories * Use user chip from macaw (#1191) * Use user chip from macaw * Use dedicated components for menu items * Simplify code * Bump version and fix types (#1210) * Rename onBack to onClick * Rename UserChip to UserChipMenu * Rename IMenuItem to SidebarMenuItem * Update macaw version * Fix tables after changes in macaw (#1220) * Update macaw version * Update changelog * Update stories * Fix after rebase * Update to macaw 0.2.0 * Lint files * Update macaw to 0.2.2
2021-07-21 08:59:52 +00:00
import { makeStyles } from "@saleor/macaw-ui";
2019-12-17 17:13:56 +00:00
import { OrderListUrlSortField } from "@saleor/orders/urls";
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>
Use MacawUI (#1229) * Replace withStyleswith useStyles (#1100) * Replace withStyleswith useStyles * Update messages * Use rem as a spacing unit (#1101) * Use rems as spacing units * Fix visual bugs * Update stories * Use macaw-ui as theme provider (#1108) * Use macaw ui as a theme provider * Add react-dom to aliases * Fix jest module resolution * Update useTheme hook usage * Fix test wrapper * Use macaw from git repo * Fix CI * Update stories * Fix aliasing * Extract savebar to macaw ui (#1146) * wip * Use savebar from macaw * Use confirm button from macaw * Improve file structure * Use sidebar context from macaw * Update macaw * Update macaw version * Remove savebar from storybook * Update stories * Use alerts and notifications from macaw (#1166) * Use alerts from macaw * Add notifications from macaw * Update stories * Pin macaw version * Encapsulate limit reached in one component * Remove unused imports * Use backlinks from macaw (#1183) * Use backlink from macaw * Update macaw version * Use macaw sidebar (#1148) * Use sidebar from macaw * Use shipped logo * Use lowercase * Update stories * Use user chip from macaw (#1191) * Use user chip from macaw * Use dedicated components for menu items * Simplify code * Bump version and fix types (#1210) * Rename onBack to onClick * Rename UserChip to UserChipMenu * Rename IMenuItem to SidebarMenuItem * Update macaw version * Fix tables after changes in macaw (#1220) * Update macaw version * Update changelog * Update stories * Fix after rebase * Update to macaw 0.2.0 * Lint files * Update macaw to 0.2.2
2021-07-21 08:59:52 +00:00
{isLimitReached(limits, "orders") && (
<LimitReachedAlert
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." />
</LimitReachedAlert>
)}
<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;