
* 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>
145 lines
3.9 KiB
TypeScript
145 lines
3.9 KiB
TypeScript
import { Card } from "@material-ui/core";
|
|
import CardMenu from "@saleor/components/CardMenu";
|
|
import Container from "@saleor/components/Container";
|
|
import FilterBar from "@saleor/components/FilterBar";
|
|
import PageHeader from "@saleor/components/PageHeader";
|
|
import { OrderListQuery, RefreshLimitsQuery } from "@saleor/graphql";
|
|
import { sectionNames } from "@saleor/intl";
|
|
import { Button, makeStyles } from "@saleor/macaw-ui";
|
|
import { OrderListUrlSortField } from "@saleor/orders/urls";
|
|
import {
|
|
FilterPageProps,
|
|
PageListProps,
|
|
RelayToFlat,
|
|
SortPage
|
|
} from "@saleor/types";
|
|
import { hasLimits, isLimitReached } from "@saleor/utils/limits";
|
|
import React from "react";
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
|
|
|
import OrderLimitReached from "../OrderLimitReached";
|
|
import OrderList from "../OrderList";
|
|
import {
|
|
createFilterStructure,
|
|
OrderFilterKeys,
|
|
OrderListFilterOpts
|
|
} from "./filters";
|
|
|
|
export interface OrderListPageProps
|
|
extends PageListProps,
|
|
FilterPageProps<OrderFilterKeys, OrderListFilterOpts>,
|
|
SortPage<OrderListUrlSortField> {
|
|
limits: RefreshLimitsQuery["shop"]["limits"];
|
|
orders: RelayToFlat<OrderListQuery["orders"]>;
|
|
onSettingsOpen: () => void;
|
|
}
|
|
|
|
const useStyles = makeStyles(
|
|
theme => ({
|
|
settings: {
|
|
marginRight: theme.spacing(2)
|
|
}
|
|
}),
|
|
{ name: "OrderListPage" }
|
|
);
|
|
|
|
const OrderListPage: React.FC<OrderListPageProps> = ({
|
|
currentTab,
|
|
initialSearch,
|
|
filterOpts,
|
|
limits,
|
|
tabs,
|
|
onAdd,
|
|
onAll,
|
|
onSearchChange,
|
|
onSettingsOpen,
|
|
onFilterChange,
|
|
onTabChange,
|
|
onTabDelete,
|
|
onTabSave,
|
|
...listProps
|
|
}) => {
|
|
const intl = useIntl();
|
|
const classes = useStyles({});
|
|
const filterStructure = createFilterStructure(intl, filterOpts);
|
|
const limitsReached = isLimitReached(limits, "orders");
|
|
|
|
return (
|
|
<Container>
|
|
<PageHeader
|
|
title={intl.formatMessage(sectionNames.orders)}
|
|
limitText={
|
|
hasLimits(limits, "orders") &&
|
|
intl.formatMessage(
|
|
{
|
|
id: "zyceue",
|
|
defaultMessage: "{count}/{max} orders",
|
|
description: "placed order counter"
|
|
},
|
|
{
|
|
count: limits.currentUsage.orders,
|
|
max: limits.allowedUsage.orders
|
|
}
|
|
)
|
|
}
|
|
cardMenu={
|
|
!!onSettingsOpen && (
|
|
<CardMenu
|
|
className={classes.settings}
|
|
menuItems={[
|
|
{
|
|
label: intl.formatMessage({
|
|
id: "WbV1Xm",
|
|
defaultMessage: "Order Settings",
|
|
description: "button"
|
|
}),
|
|
onSelect: onSettingsOpen
|
|
}
|
|
]}
|
|
/>
|
|
)
|
|
}
|
|
>
|
|
<Button
|
|
disabled={limitsReached}
|
|
variant="primary"
|
|
onClick={onAdd}
|
|
data-test-id="create-order-button"
|
|
>
|
|
<FormattedMessage
|
|
id="LshEVn"
|
|
defaultMessage="Create order"
|
|
description="button"
|
|
/>
|
|
</Button>
|
|
</PageHeader>
|
|
{limitsReached && <OrderLimitReached />}
|
|
<Card>
|
|
<FilterBar
|
|
currentTab={currentTab}
|
|
initialSearch={initialSearch}
|
|
onAll={onAll}
|
|
onFilterChange={onFilterChange}
|
|
onSearchChange={onSearchChange}
|
|
onTabChange={onTabChange}
|
|
onTabDelete={onTabDelete}
|
|
onTabSave={onTabSave}
|
|
tabs={tabs}
|
|
allTabLabel={intl.formatMessage({
|
|
id: "WRkCFt",
|
|
defaultMessage: "All Orders",
|
|
description: "tab name"
|
|
})}
|
|
filterStructure={filterStructure}
|
|
searchPlaceholder={intl.formatMessage({
|
|
id: "wTHjt3",
|
|
defaultMessage: "Search Orders..."
|
|
})}
|
|
/>
|
|
<OrderList {...listProps} />
|
|
</Card>
|
|
</Container>
|
|
);
|
|
};
|
|
OrderListPage.displayName = "OrderListPage";
|
|
export default OrderListPage;
|