Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add ability to create order draft
dominik-zeglend5be195d0fd8
diff --git a/saleor/static/dashboard-next/orders/mutations.ts b/saleor/static/dashboard-next/orders/mutations.tsindex 64c5edcf73..30c04a7561 100644--- a/saleor/static/dashboard-next/orders/mutations.ts+++ b/saleor/static/dashboard-next/orders/mutations.ts@@ -13,6 +13,7 @@ import {OrderCreateFulfillment,OrderCreateFulfillmentVariables} from "./types/OrderCreateFulfillment";+import { OrderDraftCreate } from "./types/OrderDraftCreate";import {OrderDraftUpdate,OrderDraftUpdateVariables@@ -210,3 +211,17 @@ export const TypedOrderShippingMethodUpdateMutation = TypedMutation<OrderShippingMethodUpdate,OrderShippingMethodUpdateVariables>(orderShippingMethodUpdateMutation);++const orderDraftCreateMutation = gql`+ mutation OrderDraftCreate {+ draftOrderCreate(input: {}) {+ order {+ id+ }+ }+ }+`;+export const TypedOrderDraftCreateMutation = TypedMutation<+ OrderDraftCreate,+ {}+>(orderDraftCreateMutation);diff --git a/saleor/static/dashboard-next/orders/types/OrderDraftCreate.ts b/saleor/static/dashboard-next/orders/types/OrderDraftCreate.tsnew file mode 100644index 0000000000..23f25b4e3e--- /dev/null+++ b/saleor/static/dashboard-next/orders/types/OrderDraftCreate.ts@@ -0,0 +1,20 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++// ====================================================+// GraphQL mutation operation: OrderDraftCreate+// ====================================================++export interface OrderDraftCreate_draftOrderCreate_order {+ __typename: "Order";+ id: string;+}++export interface OrderDraftCreate_draftOrderCreate {+ __typename: "DraftOrderCreate";+ order: OrderDraftCreate_draftOrderCreate_order | null;+}++export interface OrderDraftCreate {+ draftOrderCreate: OrderDraftCreate_draftOrderCreate | null;+}diff --git a/saleor/static/dashboard-next/orders/views/OrderList.tsx b/saleor/static/dashboard-next/orders/views/OrderList.tsxindex fedc651fb1..2f1e31acdf 100644--- a/saleor/static/dashboard-next/orders/views/OrderList.tsx+++ b/saleor/static/dashboard-next/orders/views/OrderList.tsx@@ -1,10 +1,14 @@import * as React from "react";import { orderListUrl, orderUrl } from "..";+import Messages from "../../components/messages";import Navigator from "../../components/Navigator";+import i18n from "../../i18n";import { createPaginationData, createPaginationState, maybe } from "../../misc";import OrderListPage from "../components/OrderListPage/OrderListPage";+import { TypedOrderDraftCreateMutation } from "../mutations";import { TypedOrderListQuery } from "../queries";+import { OrderDraftCreate } from "../types/OrderDraftCreate";interface OrderListProps {params: {@@ -19,37 +23,60 @@ export const OrderList: React.StatelessComponent<OrderListProps> = ({params}) => (<Navigator>- {navigate => {- const paginationState = createPaginationState(PAGINATE_BY, params);- return (- <TypedOrderListQuery variables={paginationState}>- {({ data, loading }) => {- const {- loadNextPage,- loadPreviousPage,- pageInfo- } = createPaginationData(- navigate,- paginationState,- orderListUrl,- maybe(() => data.orders.pageInfo),- loading- );- return (- <OrderListPage- disabled={loading}- orders={maybe(() => data.orders.edges.map(edge => edge.node))}- pageInfo={pageInfo}- onAdd={() => undefined}- onNextPage={loadNextPage}- onPreviousPage={loadPreviousPage}- onRowClick={id => () => navigate(orderUrl(id))}- />- );- }}- </TypedOrderListQuery>- );- }}+ {navigate => (+ <Messages>+ {pushMessage => {+ const handleCreateOrderCreateSuccess = (data: OrderDraftCreate) => {+ pushMessage({+ text: i18n.t("Order draft succesfully created")+ });+ navigate(orderUrl(data.draftOrderCreate.order.id));+ };+ return (+ <TypedOrderDraftCreateMutation+ onCompleted={handleCreateOrderCreateSuccess}+ >+ {createOrder => {+ const paginationState = createPaginationState(+ PAGINATE_BY,+ params+ );+ return (+ <TypedOrderListQuery variables={paginationState}>+ {({ data, loading }) => {+ const {+ loadNextPage,+ loadPreviousPage,+ pageInfo+ } = createPaginationData(+ navigate,+ paginationState,+ orderListUrl,+ maybe(() => data.orders.pageInfo),+ loading+ );+ return (+ <OrderListPage+ disabled={loading}+ orders={maybe(() =>+ data.orders.edges.map(edge => edge.node)+ )}+ pageInfo={pageInfo}+ onAdd={createOrder}+ onNextPage={loadNextPage}+ onPreviousPage={loadPreviousPage}+ onRowClick={id => () => navigate(orderUrl(id))}+ />+ );+ }}+ </TypedOrderListQuery>+ );+ }}+ </TypedOrderDraftCreateMutation>+ );+ }}+ </Messages>+ )}</Navigator>);