Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add draft order list

dominik-zeglen1a089bc2f1d1
diff --git a/saleor/static/dashboard-next/components/AppLayout/menuStructure.ts b/saleor/static/dashboard-next/components/AppLayout/menuStructure.ts
index 0177cc4560..7fafc5bf70 100644
--- a/saleor/static/dashboard-next/components/AppLayout/menuStructure.ts
+++ b/saleor/static/dashboard-next/components/AppLayout/menuStructure.ts
@@ -3,7 +3,7 @@ import { collectionListUrl } from "../../collections/urls";
import { customerListUrl } from "../../customers/urls";
import { saleListUrl, voucherListUrl } from "../../discounts/urls";
import i18n from "../../i18n";
-import { orderListUrl } from "../../orders/urls";
+import { orderDraftListUrl, orderListUrl } from "../../orders/urls";
import { productListUrl } from "../../products/urls";
import { PermissionEnum } from "../../types/globalTypes";
@@ -45,9 +45,22 @@ const menuStructure: IMenuItem[] = [
},
{
ariaLabel: "orders",
+ children: [
+ {
+ ariaLabel: "orders",
+ label: i18n.t("All Orders", { context: "Menu label" }),
+ permission: PermissionEnum.MANAGE_ORDERS,
+ url: orderListUrl()
+ },
+ {
+ ariaLabel: "order drafts",
+ label: i18n.t("Draft Orders", { context: "Menu label" }),
+ permission: PermissionEnum.MANAGE_ORDERS,
+ url: orderDraftListUrl()
+ }
+ ],
label: i18n.t("Orders", { context: "Menu label" }),
- permission: PermissionEnum.MANAGE_ORDERS,
- url: orderListUrl()
+ permission: PermissionEnum.MANAGE_ORDERS
},
{
ariaLabel: "customers",
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftList/OrderDraftList.tsx b/saleor/static/dashboard-next/orders/components/OrderDraftList/OrderDraftList.tsx
new file mode 100644
index 0000000000..7624dd346d
--- /dev/null
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftList/OrderDraftList.tsx
@@ -0,0 +1,144 @@
+import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";
+import Table from "@material-ui/core/Table";
+import TableBody from "@material-ui/core/TableBody";
+import TableCell from "@material-ui/core/TableCell";
+import TableFooter from "@material-ui/core/TableFooter";
+import TableHead from "@material-ui/core/TableHead";
+import TableRow from "@material-ui/core/TableRow";
+import * as React from "react";
+
+import { DateTime } from "../../../components/Date";
+import Money from "../../../components/Money";
+import Skeleton from "../../../components/Skeleton";
+import StatusLabel from "../../../components/StatusLabel";
+import TablePagination from "../../../components/TablePagination";
+import i18n from "../../../i18n";
+import {
+ maybe,
+ renderCollection,
+ transformOrderStatus,
+ transformPaymentStatus
+} from "../../../misc";
+import { ListProps } from "../../../types";
+import { OrderDraftList_draftOrders_edges_node } from "../../types/OrderDraftList";
+
+const styles = createStyles({
+ link: {
+ cursor: "pointer"
+ },
+ textRight: {
+ textAlign: "right"
+ }
+});
+
+interface OrderDraftListProps extends ListProps, WithStyles<typeof styles> {
+ orders: OrderDraftList_draftOrders_edges_node[];
+}
+
+export const OrderDraftList = withStyles(styles, { name: "OrderDraftList" })(
+ ({
+ classes,
+ disabled,
+ orders,
+ pageInfo,
+ onPreviousPage,
+ onNextPage,
+ onRowClick
+ }: OrderDraftListProps) => {
+ const orderDraftList = orders
+ ? orders.map(order => ({
+ ...order,
+ paymentStatus: transformPaymentStatus(order.paymentStatus),
+ status: transformOrderStatus(order.status)
+ }))
+ : undefined;
+ return (
+ <Table>
+ <TableHead>
+ <TableRow>
+ <TableCell padding="dense">
+ {i18n.t("No. of Order", { context: "table header" })}
+ </TableCell>
+ <TableCell padding="dense">
+ {i18n.t("Date", { context: "table header" })}
+ </TableCell>
+ <TableCell padding="dense">
+ {i18n.t("Customer", { context: "table header" })}
+ </TableCell>
+ <TableCell className={classes.textRight} padding="dense">
+ {i18n.t("Total", { context: "table header" })}
+ </TableCell>
+ </TableRow>
+ </TableHead>
+ <TableFooter>
+ <TableRow>
+ <TablePagination
+ colSpan={6}
+ hasNextPage={pageInfo && !disabled ? pageInfo.hasNextPage : false}
+ onNextPage={onNextPage}
+ hasPreviousPage={
+ pageInfo && !disabled ? pageInfo.hasPreviousPage : false
+ }
+ onPreviousPage={onPreviousPage}
+ />
+ </TableRow>
+ </TableFooter>
+ <TableBody>
+ {renderCollection(
+ orderDraftList,
+ order => (
+ <TableRow
+ hover={!!order}
+ className={!!order ? classes.link : undefined}
+ onClick={order ? onRowClick(order.id) : undefined}
+ key={order ? order.id : "skeleton"}
+ >
+ <TableCell padding="dense">
+ {maybe(() => order.number) ? (
+ "#" + order.number
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell padding="dense">
+ {maybe(() => order.created) ? (
+ <DateTime date={order.created} />
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell padding="dense">
+ {maybe(() => order.billingAddress) ? (
+ <>
+ {order.billingAddress.firstName}
+ &nbsp;
+ {order.billingAddress.lastName}
+ </>
+ ) : maybe(() => order.userEmail) !== undefined ? (
+ order.userEmail
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ <TableCell className={classes.textRight} padding="dense">
+ {maybe(() => order.total.gross) ? (
+ <Money money={order.total.gross} />
+ ) : (
+ <Skeleton />
+ )}
+ </TableCell>
+ </TableRow>
+ ),
+ () => (
+ <TableRow>
+ <TableCell colSpan={4}>{i18n.t("No orders found")}</TableCell>
+ </TableRow>
+ )
+ )}
+ </TableBody>
+ </Table>
+ );
+ }
+);
+OrderDraftList.displayName = "OrderDraftList";
+export default OrderDraftList;
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftList/index.ts b/saleor/static/dashboard-next/orders/components/OrderDraftList/index.ts
new file mode 100644
index 0000000000..96f0cae707
--- /dev/null
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftList/index.ts
@@ -0,0 +1,2 @@
+export { default } from './OrderDraftList';
+export * from './OrderDraftList';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftListPage/OrderDraftListPage.tsx b/saleor/static/dashboard-next/orders/components/OrderDraftListPage/OrderDraftListPage.tsx
new file mode 100644
index 0000000000..936913752c
--- /dev/null
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftListPage/OrderDraftListPage.tsx
@@ -0,0 +1,50 @@
+import Button from "@material-ui/core/Button";
+import Card from "@material-ui/core/Card";
+import AddIcon from "@material-ui/icons/Add";
+import * as React from "react";
+
+import Container from "../../../components/Container";
+import PageHeader from "../../../components/PageHeader";
+import i18n from "../../../i18n";
+import { PageListProps } from "../../../types";
+import { OrderDraftList_draftOrders_edges_node } from "../../types/OrderDraftList";
+import OrderDraftList from "../OrderDraftList";
+
+export interface OrderDraftListPageProps extends PageListProps {
+ orders: OrderDraftList_draftOrders_edges_node[];
+}
+
+const OrderDraftListPage: React.StatelessComponent<OrderDraftListPageProps> = ({
+ disabled,
+ orders,
+ pageInfo,
+ onAdd,
+ onNextPage,
+ onPreviousPage,
+ onRowClick
+}) => (
+ <Container>
+ <PageHeader title={i18n.t("Draft Orders")}>
+ <Button
+ color="secondary"
+ variant="contained"
+ disabled={disabled}
+ onClick={onAdd}
+ >
+ {i18n.t("Create order", { context: "button" })} <AddIcon />
+ </Button>
+ </PageHeader>
+ <Card>
+ <OrderDraftList
+ disabled={disabled}
+ onRowClick={onRowClick}
+ orders={orders}
+ pageInfo={pageInfo}
+ onNextPage={onNextPage}
+ onPreviousPage={onPreviousPage}
+ />
+ </Card>
+ </Container>
+);
+OrderDraftListPage.displayName = "OrderDraftListPage";
+export default OrderDraftListPage;
diff --git a/saleor/static/dashboard-next/orders/components/OrderDraftListPage/index.ts b/saleor/static/dashboard-next/orders/components/OrderDraftListPage/index.ts
new file mode 100644
index 0000000000..5814e7cb18
--- /dev/null
+++ b/saleor/static/dashboard-next/orders/components/OrderDraftListPage/index.ts
@@ -0,0 +1,2 @@
+export { default } from './OrderDraftListPage';
+export * from './OrderDraftListPage';
\ No newline at end of file
diff --git a/saleor/static/dashboard-next/orders/index.tsx b/saleor/static/dashboard-next/orders/index.tsx
index 8019ed2897..bd4865508c 100644
--- a/saleor/static/dashboard-next/orders/index.tsx
+++ b/saleor/static/dashboard-next/orders/index.tsx
@@ -4,8 +4,9 @@ import { Route, RouteComponentProps, Switch } from "react-router-dom";
import { WindowTitle } from "../components/WindowTitle";
import i18n from "../i18n";
-import { orderListPath, orderPath } from "./urls";
+import { orderDraftListPath, orderListPath, orderPath } from "./urls";
import OrderDetailsComponent from "./views/OrderDetails";
+import OrderDraftListComponent from "./views/OrderDraftList";
import OrderListComponent, { OrderListQueryParams } from "./views/OrderList";
const OrderList: React.StatelessComponent<RouteComponentProps<any>> = ({
@@ -19,6 +20,16 @@ const OrderList: React.StatelessComponent<RouteComponentProps<any>> = ({
};
return <OrderListComponent params={params} />;
};
+const OrderDraftList: React.StatelessComponent<RouteComponentProps<any>> = ({
+ location
+}) => {
+ const qs = parseQs(location.search.substr(1));
+ const params: OrderListQueryParams = {
+ after: qs.after,
+ before: qs.before
+ };
+ return <OrderDraftListComponent params={params} />;
+};
const OrderDetails: React.StatelessComponent<RouteComponentProps<any>> = ({
match
@@ -30,6 +41,7 @@ const Component = () => (
<>
<WindowTitle title={i18n.t("Orders")} />
<Switch>
+ <Route exact path={orderDraftListPath} component={OrderDraftList} />
<Route exact path={orderListPath} component={OrderList} />
<Route path={orderPath(":id")} component={OrderDetails} />
</Switch>
diff --git a/saleor/static/dashboard-next/orders/urls.ts b/saleor/static/dashboard-next/orders/urls.ts
index 2b18c8c13a..172bd7406e 100644
--- a/saleor/static/dashboard-next/orders/urls.ts
+++ b/saleor/static/dashboard-next/orders/urls.ts
@@ -3,11 +3,11 @@ import * as urlJoin from "url-join";
import { OrderListQueryParams } from "./views/OrderList";
-const orderSectionUrl = "/orders/";
+const orderSectionUrl = "/orders";
export const orderListPath = orderSectionUrl;
export const orderListUrl = (params?: OrderListQueryParams): string => {
- const orderList = orderSectionUrl;
+ const orderList = orderListPath;
if (params === undefined) {
return orderList;
} else {
@@ -15,5 +15,15 @@ export const orderListUrl = (params?: OrderListQueryParams): string => {
}
};
+export const orderDraftListPath = urlJoin(orderSectionUrl, "drafts");
+export const orderDraftListUrl = (params?: OrderListQueryParams): string => {
+ const orderDraftList = orderDraftListPath;
+ if (params === undefined) {
+ return orderDraftList;
+ } else {
+ return urlJoin(orderDraftList, "?" + stringifyQs(params));
+ }
+};
+
export const orderPath = (id: string) => urlJoin(orderSectionUrl, id);
export const orderUrl = (id: string) => orderPath(encodeURIComponent(id));
diff --git a/saleor/static/dashboard-next/orders/views/OrderDraftList.tsx b/saleor/static/dashboard-next/orders/views/OrderDraftList.tsx
index 0231133818..8fe255f4ef 100644
--- a/saleor/static/dashboard-next/orders/views/OrderDraftList.tsx
+++ b/saleor/static/dashboard-next/orders/views/OrderDraftList.tsx
@@ -1,4 +1,3 @@
-import { stringify as stringifyQs } from "qs";
import * as React from "react";
import Messages from "../../components/messages";
@@ -6,8 +5,7 @@ import Navigator from "../../components/Navigator";
import { createPaginationState, Paginator } from "../../components/Paginator";
import i18n from "../../i18n";
import { maybe } from "../../misc";
-import OrderListPage from "../components/OrderListPage/OrderListPage";
-import { getTabName } from "../misc";
+import OrderDraftListPage from "../components/OrderDraftListPage";
import { TypedOrderDraftCreateMutation } from "../mutations";
import { TypedOrderDraftListQuery } from "../queries";
import { OrderDraftCreate } from "../types/OrderDraftCreate";
@@ -38,15 +36,6 @@ export const OrderDraftList: React.StatelessComponent<OrderDraftListProps> = ({
navigate(orderUrl(data.draftOrderCreate.order.id));
};
- const changeFilters = (newParams: OrderDraftListQueryParams) =>
- navigate(
- "?" +
- stringifyQs({
- ...params,
- ...newParams
- })
- );
-
return (
<TypedOrderDraftCreateMutation
onCompleted={handleCreateOrderCreateSuccess}
@@ -56,7 +45,6 @@ export const OrderDraftList: React.StatelessComponent<OrderDraftListProps> = ({
PAGINATE_BY,
params
);
- const currentTab = getTabName(params);
return (
<TypedOrderDraftListQuery
@@ -70,9 +58,7 @@ export const OrderDraftList: React.StatelessComponent<OrderDraftListProps> = ({
queryString={params}
>
{({ loadNextPage, loadPreviousPage, pageInfo }) => (
- <OrderListPage
- filtersList={[]}
- currentTab={currentTab}
+ <OrderDraftListPage
disabled={loading}
orders={maybe(() =>
data.draftOrders.edges.map(edge => edge.node)
@@ -82,7 +68,6 @@ export const OrderDraftList: React.StatelessComponent<OrderDraftListProps> = ({
onNextPage={loadNextPage}
onPreviousPage={loadPreviousPage}
onRowClick={id => () => navigate(orderUrl(id))}
- onCustomFilter={() => undefined}
/>
)}
</Paginator>
diff --git a/saleor/static/dashboard-next/storybook/config.js b/saleor/static/dashboard-next/storybook/config.js
index 48b51865a1..2c60c002e5 100644
--- a/saleor/static/dashboard-next/storybook/config.js
+++ b/saleor/static/dashboard-next/storybook/config.js
@@ -76,8 +76,8 @@ function loadStories() {
require("./stories/staff/StaffDetailsPage");
// Pages
- require("./stories/pages/PageDetailsPage")
- require("./stories/pages/PageListPage")
+ require("./stories/pages/PageDetailsPage");
+ require("./stories/pages/PageListPage");
// Products
require("./stories/products/ProductCreatePage");
@@ -96,6 +96,7 @@ function loadStories() {
require("./stories/orders/OrderDetailsPage");
require("./stories/orders/OrderDraftCancelDialog");
require("./stories/orders/OrderDraftFinalizeDialog");
+ require("./stories/orders/OrderDraftListPage");
require("./stories/orders/OrderDraftPage");
require("./stories/orders/OrderFulfillmentCancelDialog");
require("./stories/orders/OrderFulfillmentDialog");
diff --git a/saleor/static/dashboard-next/storybook/stories/orders/OrderDraftListPage.tsx b/saleor/static/dashboard-next/storybook/stories/orders/OrderDraftListPage.tsx
new file mode 100644
index 0000000000..99f2a5b6eb
--- /dev/null
+++ b/saleor/static/dashboard-next/storybook/stories/orders/OrderDraftListPage.tsx
@@ -0,0 +1,23 @@
+import { storiesOf } from "@storybook/react";
+import * as React from "react";
+
+import { pageListProps } from "../../../fixtures";
+import OrderDraftListPage, {
+ OrderDraftListPageProps
+} from "../../../orders/components/OrderDraftListPage";
+import { orders } from "../../../orders/fixtures";
+import Decorator from "../../Decorator";
+
+const props: OrderDraftListPageProps = {
+ ...pageListProps.default,
+ onAdd: () => undefined,
+ orders
+};
+
+storiesOf("Views / Orders / Draft order list", module)
+ .addDecorator(Decorator)
+ .add("default", () => <OrderDraftListPage {...props} />)
+ .add("loading", () => (
+ <OrderDraftListPage {...props} disabled orders={undefined} />
+ ))
+ .add("when no data", () => <OrderDraftListPage {...props} orders={[]} />);