2022-05-23 09:24:20 +00:00
|
|
|
import {
|
|
|
|
extensionMountPoints,
|
|
|
|
mapToMenuItems,
|
2022-06-21 09:36:55 +00:00
|
|
|
useExtensions,
|
2023-01-16 09:45:12 +00:00
|
|
|
} from "@dashboard/apps/useExtensions";
|
|
|
|
import { ButtonWithSelect } from "@dashboard/components/ButtonWithSelect";
|
|
|
|
import CardMenu from "@dashboard/components/CardMenu";
|
|
|
|
import Container from "@dashboard/components/Container";
|
|
|
|
import FilterBar from "@dashboard/components/FilterBar";
|
|
|
|
import PageHeader from "@dashboard/components/PageHeader";
|
|
|
|
import { OrderListQuery, RefreshLimitsQuery } from "@dashboard/graphql";
|
|
|
|
import { sectionNames } from "@dashboard/intl";
|
|
|
|
import { OrderListUrlSortField } from "@dashboard/orders/urls";
|
2022-03-09 08:56:55 +00:00
|
|
|
import {
|
|
|
|
FilterPageProps,
|
|
|
|
PageListProps,
|
|
|
|
RelayToFlat,
|
2022-06-21 09:36:55 +00:00
|
|
|
SortPage,
|
2023-01-16 09:45:12 +00:00
|
|
|
} from "@dashboard/types";
|
|
|
|
import { hasLimits, isLimitReached } from "@dashboard/utils/limits";
|
|
|
|
import { Card } from "@material-ui/core";
|
|
|
|
import { makeStyles } from "@saleor/macaw-ui";
|
2020-05-14 09:30:32 +00:00
|
|
|
import React from "react";
|
|
|
|
import { FormattedMessage, useIntl } from "react-intl";
|
|
|
|
|
2021-08-10 08:59:15 +00:00
|
|
|
import OrderLimitReached from "../OrderLimitReached";
|
2019-06-19 14:40:52 +00:00
|
|
|
import OrderList from "../OrderList";
|
2020-01-10 13:16:16 +00:00
|
|
|
import {
|
|
|
|
createFilterStructure,
|
2020-05-14 09:30:32 +00:00
|
|
|
OrderFilterKeys,
|
2022-06-21 09:36:55 +00:00
|
|
|
OrderListFilterOpts,
|
2020-01-10 13:16:16 +00:00
|
|
|
} 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> {
|
2022-03-09 08:56:55 +00:00
|
|
|
limits: RefreshLimitsQuery["shop"]["limits"];
|
|
|
|
orders: RelayToFlat<OrderListQuery["orders"]>;
|
2020-11-30 13:19:57 +00:00
|
|
|
onSettingsOpen: () => void;
|
2022-05-06 08:59:55 +00:00
|
|
|
onAdd: () => void;
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 13:19:57 +00:00
|
|
|
const useStyles = makeStyles(
|
|
|
|
theme => ({
|
|
|
|
settings: {
|
2022-06-21 09:36:55 +00:00
|
|
|
marginRight: theme.spacing(2),
|
|
|
|
},
|
2020-11-30 13:19:57 +00:00
|
|
|
}),
|
2022-06-21 09:36:55 +00:00
|
|
|
{ name: "OrderListPage" },
|
2020-11-30 13:19:57 +00:00
|
|
|
);
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
const OrderListPage: React.FC<OrderListPageProps> = ({
|
|
|
|
currentTab,
|
|
|
|
initialSearch,
|
2019-12-20 15:53:03 +00:00
|
|
|
filterOpts,
|
2021-04-13 09:59:16 +00:00
|
|
|
limits,
|
2019-09-10 15:14:11 +00:00
|
|
|
tabs,
|
2019-06-19 14:40:52 +00:00
|
|
|
onAdd,
|
|
|
|
onAll,
|
|
|
|
onSearchChange,
|
2020-11-30 13:19:57 +00:00
|
|
|
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
|
2019-08-26 17:44:42 +00:00
|
|
|
}) => {
|
|
|
|
const intl = useIntl();
|
2020-11-30 13:19:57 +00:00
|
|
|
const classes = useStyles({});
|
2019-12-20 15:53:03 +00:00
|
|
|
const filterStructure = createFilterStructure(intl, filterOpts);
|
2021-08-10 08:59:15 +00:00
|
|
|
const limitsReached = isLimitReached(limits, "orders");
|
2019-12-20 10:44:41 +00:00
|
|
|
|
2022-05-23 09:24:20 +00:00
|
|
|
const { ORDER_OVERVIEW_CREATE, ORDER_OVERVIEW_MORE_ACTIONS } = useExtensions(
|
2022-06-21 09:36:55 +00:00
|
|
|
extensionMountPoints.ORDER_LIST,
|
2022-05-23 09:24:20 +00:00
|
|
|
);
|
|
|
|
const extensionMenuItems = mapToMenuItems(ORDER_OVERVIEW_MORE_ACTIONS);
|
|
|
|
const extensionCreateButtonItems = mapToMenuItems(ORDER_OVERVIEW_CREATE);
|
|
|
|
|
2019-08-26 17:44:42 +00:00
|
|
|
return (
|
|
|
|
<Container>
|
2021-08-10 08:59:15 +00:00
|
|
|
<PageHeader
|
|
|
|
title={intl.formatMessage(sectionNames.orders)}
|
|
|
|
limitText={
|
|
|
|
hasLimits(limits, "orders") &&
|
|
|
|
intl.formatMessage(
|
|
|
|
{
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "zyceue",
|
2021-08-10 08:59:15 +00:00
|
|
|
defaultMessage: "{count}/{max} orders",
|
2022-06-21 09:36:55 +00:00
|
|
|
description: "placed order counter",
|
2021-08-10 08:59:15 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
count: limits.currentUsage.orders,
|
2022-06-21 09:36:55 +00:00
|
|
|
max: limits.allowedUsage.orders,
|
|
|
|
},
|
2021-08-10 08:59:15 +00:00
|
|
|
)
|
|
|
|
}
|
2022-02-03 12:59:36 +00:00
|
|
|
cardMenu={
|
|
|
|
!!onSettingsOpen && (
|
|
|
|
<CardMenu
|
|
|
|
className={classes.settings}
|
|
|
|
menuItems={[
|
|
|
|
{
|
|
|
|
label: intl.formatMessage({
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "WbV1Xm",
|
2022-02-03 12:59:36 +00:00
|
|
|
defaultMessage: "Order Settings",
|
2022-06-21 09:36:55 +00:00
|
|
|
description: "button",
|
2022-02-03 12:59:36 +00:00
|
|
|
}),
|
2022-06-21 09:36:55 +00:00
|
|
|
onSelect: onSettingsOpen,
|
2022-05-23 09:24:20 +00:00
|
|
|
},
|
2022-06-21 09:36:55 +00:00
|
|
|
...extensionMenuItems,
|
2022-02-03 12:59:36 +00:00
|
|
|
]}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2021-08-10 08:59:15 +00:00
|
|
|
>
|
2022-05-23 09:24:20 +00:00
|
|
|
<ButtonWithSelect
|
2021-08-10 08:59:15 +00:00
|
|
|
disabled={limitsReached}
|
2022-05-23 09:24:20 +00:00
|
|
|
options={extensionCreateButtonItems}
|
2021-01-26 10:21:54 +00:00
|
|
|
data-test-id="create-order-button"
|
2022-05-23 09:24:20 +00:00
|
|
|
onClick={onAdd}
|
2021-01-26 10:21:54 +00:00
|
|
|
>
|
2019-08-26 17:44:42 +00:00
|
|
|
<FormattedMessage
|
2022-05-05 07:54:28 +00:00
|
|
|
id="LshEVn"
|
2019-08-26 17:44:42 +00:00
|
|
|
defaultMessage="Create order"
|
|
|
|
description="button"
|
|
|
|
/>
|
2022-05-23 09:24:20 +00:00
|
|
|
</ButtonWithSelect>
|
2019-08-26 17:44:42 +00:00
|
|
|
</PageHeader>
|
2021-08-10 08:59:15 +00:00
|
|
|
{limitsReached && <OrderLimitReached />}
|
2019-08-26 17:44:42 +00:00
|
|
|
<Card>
|
2019-12-20 10:44:41 +00:00
|
|
|
<FilterBar
|
2019-08-26 17:44:42 +00:00
|
|
|
currentTab={currentTab}
|
|
|
|
initialSearch={initialSearch}
|
|
|
|
onAll={onAll}
|
2019-12-20 10:44:41 +00:00
|
|
|
onFilterChange={onFilterChange}
|
2019-08-26 17:44:42 +00:00
|
|
|
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({
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "WRkCFt",
|
2019-12-20 16:31:26 +00:00
|
|
|
defaultMessage: "All Orders",
|
2022-06-21 09:36:55 +00:00
|
|
|
description: "tab name",
|
2019-12-20 10:44:41 +00:00
|
|
|
})}
|
|
|
|
filterStructure={filterStructure}
|
|
|
|
searchPlaceholder={intl.formatMessage({
|
2022-05-05 07:54:28 +00:00
|
|
|
id: "wTHjt3",
|
2022-06-21 09:36:55 +00:00
|
|
|
defaultMessage: "Search Orders...",
|
2019-12-20 10:44:41 +00:00
|
|
|
})}
|
2019-08-26 17:44:42 +00:00
|
|
|
/>
|
|
|
|
<OrderList {...listProps} />
|
|
|
|
</Card>
|
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|
2019-06-19 14:40:52 +00:00
|
|
|
OrderListPage.displayName = "OrderListPage";
|
|
|
|
export default OrderListPage;
|