Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add customer fetching
dominik-zeglen7da7a8f54c51
diff --git a/saleor/static/dashboard-next/components/Form/Form.tsx b/saleor/static/dashboard-next/components/Form/Form.tsxindex 3fcc1513f8..1e97a8de7e 100644--- a/saleor/static/dashboard-next/components/Form/Form.tsx+++ b/saleor/static/dashboard-next/components/Form/Form.tsx@@ -9,7 +9,7 @@ export interface FormProps<T extends {}> {hasChanged: boolean;errors: { [key: string]: string };change(event: React.ChangeEvent<any>);- submit(event: React.FormEvent<any>);+ submit(event?: React.FormEvent<any>);}) => React.ReactElement<any>)| React.ReactNode;diff --git a/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx b/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsxindex 9fb2fffd57..ec226a4897 100644--- a/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderCustomer/OrderCustomer.tsx@@ -7,19 +7,26 @@ import * as React from "react";import CardTitle from "../../../components/CardTitle";import ExternalLink from "../../../components/ExternalLink";+import Form from "../../../components/Form";import Hr from "../../../components/Hr";import Link from "../../../components/Link";+import SingleAutocompleteSelectField from "../../../components/SingleAutocompleteSelectField";import Skeleton from "../../../components/Skeleton";+import Toggle from "../../../components/Toggle";import i18n from "../../../i18n";import { maybe } from "../../../misc";import { OrderDetails_order } from "../../types/OrderDetails";+import { UserSearch_customers_edges_node } from "../../types/UserSearch";export interface OrderCustomerProps {order: OrderDetails_order;- canEditCustomer?: boolean;- onCustomerEditClick();- onBillingAddressEdit();- onShippingAddressEdit();+ users?: UserSearch_customers_edges_node[];+ loading?: boolean;+ canEditCustomer: boolean;+ fetchUsers?: (query: string) => void;+ onCustomerEdit?: () => void;+ onBillingAddressEdit?: () => void;+ onShippingAddressEdit?: () => void;}const decorate = withStyles(@@ -49,8 +56,11 @@ const OrderCustomer = decorate<OrderCustomerProps>(({classes,canEditCustomer,+ fetchUsers,+ loading,order,- onCustomerEditClick,+ users,+ onCustomerEdit,onBillingAddressEdit,onShippingAddressEdit}) => {@@ -59,40 +69,77 @@ const OrderCustomer = decorate<OrderCustomerProps>(const user = maybe(() => order.user);return (<Card>- <CardTitle- title={i18n.t("Customer")}- toolbar={- !!canEditCustomer && (- <Button- color="secondary"- variant="flat"- disabled={!onCustomerEditClick}- onClick={onCustomerEditClick}- >- {i18n.t("Edit")}- </Button>- )- }- />- <CardContent>- {user === undefined ? (- <Skeleton />- ) : user === null ? (- <Typography>{i18n.t("Anonymous user")}</Typography>- ) : (+ <Toggle>+ {(editMode, { toggle: toggleEditMode }) => (<>- <Typography className={classes.userEmail}>- {user.email}- </Typography>- <div>- <Link underline={false}>{i18n.t("View Profile")}</Link>- </div>- <div>- <Link underline={false}>{i18n.t("View Orders")}</Link>- </div>+ <CardTitle+ title={i18n.t("Customer")}+ toolbar={+ !!canEditCustomer && (+ <Button+ color="secondary"+ variant="flat"+ disabled={!onCustomerEdit}+ onClick={toggleEditMode}+ >+ {i18n.t("Edit")}+ </Button>+ )+ }+ />+ <CardContent>+ {user === undefined ? (+ <Skeleton />+ ) : user === null ? (+ editMode && canEditCustomer ? (+ <Form+ initial={{ query: { label: "", value: "" } }}+ onSubmit={onCustomerEdit}+ >+ {({ change, data, submit }) => {+ const handleChange = (+ event: React.ChangeEvent<any>+ ) => {+ change(event);+ submit();+ };+ return (+ <SingleAutocompleteSelectField+ custom={true}+ choices={maybe(() => users, []).map(user => ({+ label: user.email,+ value: user.id+ }))}+ fetchChoices={fetchUsers}+ loading={loading}+ placeholder={i18n.t("Search Customers")}+ onChange={handleChange}+ name="query"+ value={data.query}+ />+ );+ }}+ </Form>+ ) : (+ <Typography>{i18n.t("Anonymous user")}</Typography>+ )+ ) : (+ <>+ <Typography className={classes.userEmail}>+ {user.email}+ </Typography>+ <div>+ <Link underline={false}>{i18n.t("View Profile")}</Link>+ </div>+ <div>+ <Link underline={false}>{i18n.t("View Orders")}</Link>+ </div>+ </>+ )}+ </CardContent></>)}- </CardContent>+ </Toggle><Hr /><CardContent><div className={classes.sectionHeader}>@@ -110,7 +157,7 @@ const OrderCustomer = decorate<OrderCustomerProps>(href={`mailto:${maybe(() => order.userEmail)}`}typographyProps={{ color: "primary" }}>- order.userEmail+ {maybe(() => order.userEmail)}</ExternalLink>)}</CardContent>diff --git a/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx b/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsxindex 9916615b1d..f7203a2f3d 100644--- a/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx+++ b/saleor/static/dashboard-next/orders/components/OrderDetailsPage/OrderDetailsPage.tsx@@ -22,7 +22,6 @@ import OrderCancelDialog, {FormData as OrderCancelFormData} from "../OrderCancelDialog";import OrderCustomer from "../OrderCustomer";-import OrderCustomerEditDialog from "../OrderCustomerEditDialog";import OrderFulfillment from "../OrderFulfillment";import OrderFulfillmentCancelDialog, {FormData as OrderFulfillmentCancelDialogFormData@@ -39,12 +38,6 @@ import OrderPaymentDialog, {FormData as OrderPaymentFormData} from "../OrderPaymentDialog";import OrderPaymentReleaseDialog from "../OrderPaymentReleaseDialog";-import OrderProductAddDialog, {- FormData as ProductAddFormData-} from "../OrderProductAddDialog";-import OrderShippingMethodEditDialog, {- FormData as ShippingMethodForm-} from "../OrderShippingMethodEditDialog";import OrderUnfulfilledItems from "../OrderUnfulfilledItems/OrderUnfulfilledItems";export interface OrderDetailsPageProps {@@ -53,56 +46,35 @@ export interface OrderDetailsPageProps {id: string;name: string;}>;- users?: Array<{- id: string;- email: string;- }>;countries?: Array<{code: string;label: string;}>;- variants?: Array<{- id: string;- name: string;- sku: string;- stockQuantity: number;- }>;- variantsLoading?: boolean;errors: UserError[];- fetchUsers?(value: string);- fetchVariants?(value: string);onBack();onBillingAddressEdit(data: AddressTypeInput);- onCreate?();onFulfillmentCancel(id: string, data: OrderFulfillmentCancelDialogFormData);onFulfillmentTrackingNumberUpdate(id: string,data: OrderFulfillmentTrackingDialogFormData);onOrderFulfill(data: OrderFulfillFormData);- onOrderLineChange(id: string): (value: string) => void;- onOrderLineRemove(id: string);- onProductAdd(data: ProductAddFormData);onProductClick?(id: string);onPaymentCapture(data: OrderPaymentFormData);onPaymentRefund(data: OrderPaymentFormData);onPaymentRelease?();onShippingAddressEdit(data: AddressTypeInput);- onShippingMethodEdit(data: ShippingMethodForm);onOrderCancel(data: OrderCancelFormData);onNoteAdd(data: HistoryFormData);}interface OrderDetailsPageState {openedBillingAddressEditDialog: boolean;- openedCustomerEditDialog: boolean;openedFulfillmentDialog: boolean;openedOrderCancelDialog: boolean;- openedOrderProductAddDialog: boolean;openedPaymentCaptureDialog: boolean;openedPaymentRefundDialog: boolean;openedPaymentReleaseDialog: boolean;openedShippingAddressEditDialog: boolean;- openedShippingMethodEditDialog: boolean;}const decorate = withStyles(theme => ({@@ -128,15 +100,12 @@ class OrderDetailsPageComponent extends React.Component<> {state = {openedBillingAddressEditDialog: false,- openedCustomerEditDialog: false,openedFulfillmentDialog: false,openedOrderCancelDialog: false,- openedOrderProductAddDialog: false,openedPaymentCaptureDialog: false,openedPaymentRefundDialog: false,openedPaymentReleaseDialog: false,- openedShippingAddressEditDialog: false,- openedShippingMethodEditDialog: false+ openedShippingAddressEditDialog: false};toggleFulfillmentDialog = () =>@@ -159,14 +128,6 @@ class OrderDetailsPageComponent extends React.Component<this.setState(prevState => ({openedOrderCancelDialog: !prevState.openedOrderCancelDialog}));- toggleOrderProductAddDialog = () =>- this.setState(prevState => ({- openedOrderProductAddDialog: !prevState.openedOrderProductAddDialog- }));- toggleCustomerEditDialog = () =>- this.setState(prevState => ({- openedCustomerEditDialog: !prevState.openedCustomerEditDialog- }));toggleShippingAddressEditDialog = () =>this.setState(prevState => ({openedShippingAddressEditDialog: !prevState.openedShippingAddressEditDialog@@ -175,10 +136,6 @@ class OrderDetailsPageComponent extends React.Component<this.setState(prevState => ({openedBillingAddressEditDialog: !prevState.openedBillingAddressEditDialog}));- toggleShippingMethodEditDialog = () =>- this.setState(prevState => ({- openedShippingMethodEditDialog: !prevState.openedShippingMethodEditDialog- }));render() {const {@@ -186,12 +143,6 @@ class OrderDetailsPageComponent extends React.Component<countries,errors,order,- shippingMethods,- users,- variants,- variantsLoading,- fetchUsers,- fetchVariants,onBack,onBillingAddressEdit,onFulfillmentCancel,@@ -202,21 +153,16 @@ class OrderDetailsPageComponent extends React.Component<onPaymentCapture,onPaymentRefund,onPaymentRelease,- onProductAdd,- onShippingAddressEdit,- onShippingMethodEdit+ onShippingAddressEdit} = this.props;const {openedBillingAddressEditDialog,- openedCustomerEditDialog,openedFulfillmentDialog,openedOrderCancelDialog,- openedOrderProductAddDialog,openedPaymentCaptureDialog,openedPaymentRefundDialog,openedPaymentReleaseDialog,- openedShippingAddressEditDialog,- openedShippingMethodEditDialog+ openedShippingAddressEditDialog} = this.state;const canCancel = maybe(() => order.status) !== OrderStatus.CANCELED;const unfulfilled = maybe(() => order.lines.edges, [])@@ -328,29 +274,10 @@ class OrderDetailsPageComponent extends React.Component<canEditCustomer={false}order={order}onBillingAddressEdit={this.toggleBillingAddressEditDialog}- onCustomerEditClick={this.toggleCustomerEditDialog}onShippingAddressEdit={this.toggleShippingAddressEditDialog}/>{order && (<>- <Form- initial={{- email: order.user- ? { label: order.user.email, value: order.user.id }- : { label: "", value: "" }- }}- >- {({ change, data }) => (- <OrderCustomerEditDialog- open={openedCustomerEditDialog}- user={data.email}- users={users}- fetchUsers={fetchUsers}- onChange={change}- onClose={this.toggleCustomerEditDialog}- />- )}- </Form><Forminitial={transformAddressToForm(maybe(() => order.shippingAddress)@@ -412,21 +339,6 @@ class OrderDetailsPageComponent extends React.Component<onClose={this.togglePaymentRefundDialog}onSubmit={onPaymentRefund}/>- <OrderProductAddDialog- loading={variantsLoading}- open={openedOrderProductAddDialog}- variants={variants}- fetchVariants={fetchVariants}- onClose={this.toggleOrderProductAddDialog}- onSubmit={onProductAdd}- />- <OrderShippingMethodEditDialog- open={openedShippingMethodEditDialog}- shippingMethod={maybe(() => order.shippingMethod.id, "")}- shippingMethods={shippingMethods}- onClose={this.toggleShippingMethodEditDialog}- onSubmit={onShippingMethodEdit}- /><OrderCancelDialognumber={maybe(() => order.number)}open={openedOrderCancelDialog}diff --git a/saleor/static/dashboard-next/orders/containers/UserSearch.tsx b/saleor/static/dashboard-next/orders/containers/UserSearch.tsxnew file mode 100644index 0000000000..ee780eb859--- /dev/null+++ b/saleor/static/dashboard-next/orders/containers/UserSearch.tsx@@ -0,0 +1,42 @@+import * as React from "react";+import { QueryResult } from "react-apollo";+import { TypedUserSearch } from "../queries";+import { UserSearch, UserSearchVariables } from "../types/UserSearch";++interface UserSearchProviderProps {+ children:+ | ((+ props: {+ search: (query: string) => void;+ searchOpts: QueryResult<UserSearch, UserSearchVariables>;+ }+ ) => React.ReactElement<any>)+ | React.ReactNode;+}+interface UserSearchProviderState {+ query: string;+}++export class UserSearchProvider extends React.Component<+ UserSearchProviderProps,+ UserSearchProviderState+> {+ state: UserSearchProviderState = { query: "" };++ search = (query: string) => this.setState({ query });++ render() {+ const { children } = this.props;+ if (typeof children === "function") {+ return (+ <TypedUserSearch+ variables={{ search: this.state.query }}+ skip={!this.state.query}+ >+ {searchOpts => children({ search: this.search, searchOpts })}+ </TypedUserSearch>+ );+ }+ return this.props.children;+ }+}diff --git a/saleor/static/dashboard-next/orders/fixtures.ts b/saleor/static/dashboard-next/orders/fixtures.tsindex 683a7e2ddf..a0dc709ba2 100644--- a/saleor/static/dashboard-next/orders/fixtures.ts+++ b/saleor/static/dashboard-next/orders/fixtures.ts@@ -7,21 +7,26 @@ import {import { transformOrderStatus, transformPaymentStatus } from "./";import { OrderDetails_order } from "./types/OrderDetails";import { OrderList_orders_edges_node } from "./types/OrderList";+import { UserSearch_customers_edges_node } from "./types/UserSearch";-export const clients = [+export const clients: UserSearch_customers_edges_node[] = [{+ __typename: "User" as "User",email: "[email protected]",id: "c1"},{+ __typename: "User" as "User",email: "[email protected]",id: "c2"},{+ __typename: "User" as "User",email: "[email protected]",id: "c3"},{+ __typename: "User" as "User",email: "[email protected]",id: "c4"}diff --git a/saleor/static/dashboard-next/orders/queries.ts b/saleor/static/dashboard-next/orders/queries.tsindex 317942499f..0f89b21646 100644--- a/saleor/static/dashboard-next/orders/queries.ts+++ b/saleor/static/dashboard-next/orders/queries.ts@@ -7,6 +7,7 @@ import {OrderVariantSearch,OrderVariantSearchVariables} from "./types/OrderVariantSearch";+import { UserSearch, UserSearchVariables } from "./types/UserSearch";export const fragmentOrderEvent = gql`fragment OrderEventFragment on OrderEvent {@@ -238,3 +239,19 @@ export const TypedOrderVariantSearch = TypedQuery<OrderVariantSearch,OrderVariantSearchVariables>(orderVariantSearchQuery);++export const userSearchQuery = gql`+ query UserSearch($search: String!) {+ customers(query: $search, first: 20) {+ edges {+ node {+ id+ }+ }+ }+ }+`;+export const TypedUserSearch = TypedQuery<UserSearch, UserSearchVariables>(+ userSearchQuery+);diff --git a/saleor/static/dashboard-next/orders/types/UserSearch.ts b/saleor/static/dashboard-next/orders/types/UserSearch.tsnew file mode 100644index 0000000000..3546e62b7b--- /dev/null+++ b/saleor/static/dashboard-next/orders/types/UserSearch.ts@@ -0,0 +1,30 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++// ====================================================+// GraphQL query operation: UserSearch+// ====================================================++export interface UserSearch_customers_edges_node {+ __typename: "User";+ id: string;+ email: string;+}++export interface UserSearch_customers_edges {+ __typename: "UserCountableEdge";+ node: UserSearch_customers_edges_node;+}++export interface UserSearch_customers {+ __typename: "UserCountableConnection";+ edges: UserSearch_customers_edges[];+}++export interface UserSearch {+ customers: UserSearch_customers | null;+}++export interface UserSearchVariables {+ search: string;+}diff --git a/saleor/static/dashboard-next/orders/views/OrderDetails.tsx b/saleor/static/dashboard-next/orders/views/OrderDetails.tsxindex 118a14c749..c8c76cf15f 100644--- a/saleor/static/dashboard-next/orders/views/OrderDetails.tsx+++ b/saleor/static/dashboard-next/orders/views/OrderDetails.tsx@@ -12,19 +12,20 @@ import OrderDetailsPage from "../components/OrderDetailsPage";import OrderDraftPage from "../components/OrderDraftPage";import OrderOperations from "../containers/OrderOperations";import { OrderVariantSearchProvider } from "../containers/OrderVariantSearch";+import { UserSearchProvider } from "../containers/UserSearch";import { TypedOrderDetailsQuery } from "../queries";import { OrderAddNote } from "../types/OrderAddNote";import { OrderCapture } from "../types/OrderCapture";import { OrderCreateFulfillment } from "../types/OrderCreateFulfillment";import { OrderDraftUpdate } from "../types/OrderDraftUpdate";+import { OrderFulfillmentCancel } from "../types/OrderFulfillmentCancel";+import { OrderFulfillmentUpdateTracking } from "../types/OrderFulfillmentUpdateTracking";import { OrderLineAdd } from "../types/OrderLineAdd";import { OrderLineDelete } from "../types/OrderLineDelete";import { OrderLineUpdate } from "../types/OrderLineUpdate";import { OrderRefund } from "../types/OrderRefund";import { OrderShippingMethodUpdate } from "../types/OrderShippingMethodUpdate";import { OrderUpdate } from "../types/OrderUpdate";-import { OrderFulfillmentCancel } from "../types/OrderFulfillmentCancel";-import { OrderFulfillmentUpdateTracking } from "../types/OrderFulfillmentUpdateTracking";interface OrderDetailsProps {id: string;@@ -44,501 +45,504 @@ export const OrderDetails: React.StatelessComponent<OrderDetailsProps> = ({}const order = maybe(() => data.order);return (- <OrderVariantSearchProvider>- {({ variants: { search, searchOpts } }) => {- const handlePaymentCapture = (data: OrderCapture) => {- if (!maybe(() => data.orderCapture.errors.length)) {- pushMessage({- text: i18n.t("Payment successfully captured", {- context: "notification"- })- });- } else {- pushMessage({- text: i18n.t(- "Payment not captured: {{ errorMessage }}",- {- context: "notification",- errorMessage: data.orderCapture.errors.filter(- error => error.field === "payment"- )[0].message- }- )- });- }- };- const handlePaymentRefund = (data: OrderRefund) => {- if (!maybe(() => data.orderRefund.errors.length)) {- pushMessage({- text: i18n.t("Payment successfully refunded", {- context: "notification"- })- });- } else {- pushMessage({- text: i18n.t(- "Payment not refunded: {{ errorMessage }}",- {- context: "notification",- errorMessage: data.orderRefund.errors.filter(- error => error.field === "payment"- )[0].message- }- )- });- }- };- const handleOrderFulfillmentCreate = (- data: OrderCreateFulfillment- ) => {- if (- !maybe(() => data.orderFulfillmentCreate.errors.length)- ) {- pushMessage({- text: i18n.t("Items successfully fulfilled", {- context: "notification"- })- });- } else {- pushMessage({- text: i18n.t("Could not fulfill items", {- context: "notification"- })- });- }- };- const handleOrderCancel = () => {- pushMessage({- text: i18n.t("Order successfully cancelled", {- context: "notification"- })- });- };- const handleOrderRelease = () => {- pushMessage({- text: i18n.t("Order payment successfully released", {- context: "notification"- })- });- };- const handleNoteAdd = (data: OrderAddNote) => {- if (!maybe(() => data.orderAddNote.errors.length)) {- pushMessage({- text: i18n.t("Note successfully added", {- context: "notification"- })- });- } else {- pushMessage({- text: i18n.t("Could not add note", {- context: "notification"- })- });- }- };- const handleUpdate = (data: OrderUpdate) => {- if (!maybe(() => data.orderUpdate.errors.length)) {- pushMessage({- text: i18n.t("Order successfully updated", {- context: "notification"- })- });- }- };- const handleDraftUpdate = (data: OrderDraftUpdate) => {- if (!maybe(() => data.draftOrderUpdate.errors.length)) {- pushMessage({- text: i18n.t("Order successfully updated", {- context: "notification"- })- });- }- };- const handleShippingMethodUpdate = (- data: OrderShippingMethodUpdate- ) => {- if (- !maybe(() => data.orderUpdateShipping.errors.length)- ) {- pushMessage({- text: i18n.t("Shipping method successfully updated", {- context: "notification"- })- });- } else {- pushMessage({- text: i18n.t("Could not update shipping method", {- context: "notification"- })- });- }- };- const handleLineDelete = (data: OrderLineDelete) => {- if (- !maybe(() => data.draftOrderLineDelete.errors.length)- ) {- pushMessage({- text: i18n.t("Order line deleted", {- context: "notification"- })- });- } else {- pushMessage({- text: i18n.t("Could not delete order line", {- context: "notification"- })- });- }- };- const handleLineAdd = (data: OrderLineAdd) => {- if (- !maybe(() => data.draftOrderLineCreate.errors.length)- ) {- pushMessage({- text: i18n.t("Order line added", {- context: "notification"- })- });- } else {- pushMessage({- text: i18n.t("Could not create order line", {- context: "notification"- })- });- }- };- const handleLineUpdate = (data: OrderLineUpdate) => {- if (- !maybe(() => data.draftOrderLineUpdate.errors.length)- ) {- pushMessage({- text: i18n.t("Order line updated", {- context: "notification"- })- });- } else {- pushMessage({- text: i18n.t("Could not update order line", {- context: "notification"- })- });- }- };- const handleFulfillmentCancel = (- data: OrderFulfillmentCancel- ) => {- if (- !maybe(() => data.orderFulfillmentCancel.errors.length)- ) {- pushMessage({- text: i18n.t("Fulfillment successfully cancelled", {- context: "notification"- })- });- } else {- pushMessage({- text: i18n.t("Could not cancel fulfillment", {- context: "notification"- })- });- }- };- const handleFulfillmentUpdate = (- data: OrderFulfillmentUpdateTracking- ) => {- if (- !maybe(- () =>- data.orderFulfillmentUpdateTracking.errors.length- )- ) {- pushMessage({- text: i18n.t("Fulfillment successfully updated", {- context: "notification"- })- });- } else {- pushMessage({- text: i18n.t("Could not update fulfillment", {- context: "notification"- })- });- }- };- return (- <OrderOperations- order={id}- onError={undefined}- onOrderFulfillmentCreate={handleOrderFulfillmentCreate}- onNoteAdd={handleNoteAdd}- onOrderCancel={handleOrderCancel}- onOrderRelease={handleOrderRelease}- onPaymentCapture={handlePaymentCapture}- onPaymentRefund={handlePaymentRefund}- onUpdate={handleUpdate}- onDraftUpdate={handleDraftUpdate}- onShippingMethodUpdate={handleShippingMethodUpdate}- onOrderLineDelete={handleLineDelete}- onOrderLineAdd={handleLineAdd}- onOrderLineUpdate={handleLineUpdate}- onOrderFulfillmentCancel={handleFulfillmentCancel}- onOrderFulfillmentUpdate={handleFulfillmentUpdate}- >- {({- errors,- orderAddNote,- orderCancel,- orderCreateFulfillment,- orderLineAdd,- orderLineDelete,- orderLineUpdate,- orderPaymentCapture,- orderPaymentRefund,- orderRelease,- orderShippingMethodUpdate,- orderUpdate,- orderFulfillmentCancel,- orderFulfillmentUpdateTracking- }) =>- maybe(() => order.status !== OrderStatus.DRAFT) ? (- <OrderDetailsPage- errors={errors}- onNoteAdd={variables =>- orderAddNote.mutate({- input: variables,- order: id- })- }- fetchVariants={search}- variants={maybe(() =>- searchOpts.data.products.edges- .map(edge => edge.node)- .map(product => ({- ...product,- variants: product.variants.edges.map(- edge => edge.node- )- }))- .map(product =>- product.variants.map(variant => ({- ...variant,- name: `${product.name}(${variant.name})`- }))- )- .reduce((prev, curr) => prev.concat(curr), [])- )}- onBack={() => navigate(orderListUrl)}- order={order}- countries={maybe(- () => data.shop.countries,- []- ).map(country => ({- code: country.code,- label: country.country- }))}- shippingMethods={maybe(- () => data.order.availableShippingMethods,- []- )}- onOrderCancel={variables =>- orderCancel.mutate({- id,- ...variables- })- }- onOrderFulfill={variables =>- orderCreateFulfillment.mutate({- input: {- ...variables,- lines: maybe(() => order.lines.edges, [])- .map(edge => edge.node)- .filter(- line =>- line.quantityFulfilled < line.quantity- )- .map((line, lineIndex) => ({- orderLineId: line.id,- quantity: variables.lines[lineIndex]- }))- .filter(line => line.quantity > 0)- },- order: order.id- })+ <UserSearchProvider>+ {users => (+ <OrderVariantSearchProvider>+ {({ variants: { search, searchOpts } }) => {+ const handlePaymentCapture = (data: OrderCapture) => {+ if (!maybe(() => data.orderCapture.errors.length)) {+ pushMessage({+ text: i18n.t("Payment successfully captured", {+ context: "notification"+ })+ });+ } else {+ pushMessage({+ text: i18n.t(+ "Payment not captured: {{ errorMessage }}",+ {+ context: "notification",+ errorMessage: data.orderCapture.errors.filter(+ error => error.field === "payment"+ )[0].message+ }+ )+ });+ }+ };+ const handlePaymentRefund = (data: OrderRefund) => {+ if (!maybe(() => data.orderRefund.errors.length)) {+ pushMessage({+ text: i18n.t("Payment successfully refunded", {+ context: "notification"+ })+ });+ } else {+ pushMessage({+ text: i18n.t(+ "Payment not refunded: {{ errorMessage }}",+ {+ context: "notification",+ errorMessage: data.orderRefund.errors.filter(+ error => error.field === "payment"+ )[0].message+ }+ )+ });+ }+ };+ const handleOrderFulfillmentCreate = (+ data: OrderCreateFulfillment+ ) => {+ if (+ !maybe(+ () => data.orderFulfillmentCreate.errors.length+ )+ ) {+ pushMessage({+ text: i18n.t("Items successfully fulfilled", {+ context: "notification"+ })+ });+ } else {+ pushMessage({+ text: i18n.t("Could not fulfill items", {+ context: "notification"+ })+ });+ }+ };+ const handleOrderCancel = () => {+ pushMessage({+ text: i18n.t("Order successfully cancelled", {+ context: "notification"+ })+ });+ };+ const handleOrderRelease = () => {+ pushMessage({+ text: i18n.t(+ "Order payment successfully released",+ {+ context: "notification"}- onFulfillmentCancel={(id, variables) =>- orderFulfillmentCancel.mutate({- id,- input: variables- })- }- onFulfillmentTrackingNumberUpdate={(- id,- variables- ) =>- orderFulfillmentUpdateTracking.mutate({- id,- input: {- ...variables,- notifyCustomer: true+ )+ });+ };+ const handleNoteAdd = (data: OrderAddNote) => {+ if (!maybe(() => data.orderAddNote.errors.length)) {+ pushMessage({+ text: i18n.t("Note successfully added", {+ context: "notification"+ })+ });+ } else {+ pushMessage({+ text: i18n.t("Could not add note", {+ context: "notification"+ })+ });+ }+ };+ const handleUpdate = (data: OrderUpdate) => {+ if (!maybe(() => data.orderUpdate.errors.length)) {+ pushMessage({+ text: i18n.t("Order successfully updated", {+ context: "notification"+ })+ });+ }+ };+ const handleDraftUpdate = (data: OrderDraftUpdate) => {+ if (+ !maybe(() => data.draftOrderUpdate.errors.length)+ ) {+ pushMessage({+ text: i18n.t("Order successfully updated", {+ context: "notification"+ })+ });+ }+ };+ const handleShippingMethodUpdate = (+ data: OrderShippingMethodUpdate+ ) => {+ if (+ !maybe(() => data.orderUpdateShipping.errors.length)+ ) {+ pushMessage({+ text: i18n.t(+ "Shipping method successfully updated",+ {+ context: "notification"+ }+ )+ });+ } else {+ pushMessage({+ text: i18n.t("Could not update shipping method", {+ context: "notification"+ })+ });+ }+ };+ const handleLineDelete = (data: OrderLineDelete) => {+ if (+ !maybe(+ () => data.draftOrderLineDelete.errors.length+ )+ ) {+ pushMessage({+ text: i18n.t("Order line deleted", {+ context: "notification"+ })+ });+ } else {+ pushMessage({+ text: i18n.t("Could not delete order line", {+ context: "notification"+ })+ });+ }+ };+ const handleLineAdd = (data: OrderLineAdd) => {+ if (+ !maybe(+ () => data.draftOrderLineCreate.errors.length+ )+ ) {+ pushMessage({+ text: i18n.t("Order line added", {+ context: "notification"+ })+ });+ } else {+ pushMessage({+ text: i18n.t("Could not create order line", {+ context: "notification"+ })+ });+ }+ };+ const handleLineUpdate = (data: OrderLineUpdate) => {+ if (+ !maybe(+ () => data.draftOrderLineUpdate.errors.length+ )+ ) {+ pushMessage({+ text: i18n.t("Order line updated", {+ context: "notification"+ })+ });+ } else {+ pushMessage({+ text: i18n.t("Could not update order line", {+ context: "notification"+ })+ });+ }+ };+ const handleFulfillmentCancel = (+ data: OrderFulfillmentCancel+ ) => {+ if (+ !maybe(+ () => data.orderFulfillmentCancel.errors.length+ )+ ) {+ pushMessage({+ text: i18n.t(+ "Fulfillment successfully cancelled",+ {+ context: "notification"+ }+ )+ });+ } else {+ pushMessage({+ text: i18n.t("Could not cancel fulfillment", {+ context: "notification"+ })+ });+ }+ };+ const handleFulfillmentUpdate = (+ data: OrderFulfillmentUpdateTracking+ ) => {+ if (+ !maybe(+ () =>+ data.orderFulfillmentUpdateTracking.errors+ .length+ )+ ) {+ pushMessage({+ text: i18n.t("Fulfillment successfully updated", {+ context: "notification"+ })+ });+ } else {+ pushMessage({+ text: i18n.t("Could not update fulfillment", {+ context: "notification"+ })+ });+ }+ };+ return (+ <OrderOperations+ order={id}+ onError={undefined}+ onOrderFulfillmentCreate={+ handleOrderFulfillmentCreate+ }+ onNoteAdd={handleNoteAdd}+ onOrderCancel={handleOrderCancel}+ onOrderRelease={handleOrderRelease}+ onPaymentCapture={handlePaymentCapture}+ onPaymentRefund={handlePaymentRefund}+ onUpdate={handleUpdate}+ onDraftUpdate={handleDraftUpdate}+ onShippingMethodUpdate={handleShippingMethodUpdate}+ onOrderLineDelete={handleLineDelete}+ onOrderLineAdd={handleLineAdd}+ onOrderLineUpdate={handleLineUpdate}+ onOrderFulfillmentCancel={handleFulfillmentCancel}+ onOrderFulfillmentUpdate={handleFulfillmentUpdate}+ >+ {({+ errors,+ orderAddNote,+ orderCancel,+ orderCreateFulfillment,+ orderLineAdd,+ orderLineDelete,+ orderLineUpdate,+ orderPaymentCapture,+ orderPaymentRefund,+ orderRelease,+ orderShippingMethodUpdate,+ orderUpdate,+ orderFulfillmentCancel,+ orderFulfillmentUpdateTracking+ }) =>+ maybe(+ () => order.status !== OrderStatus.DRAFT+ ) ? (+ <OrderDetailsPage+ errors={errors}+ onNoteAdd={variables =>+ orderAddNote.mutate({+ input: variables,+ order: id+ })}- })- }- onPaymentCapture={variables =>- orderPaymentCapture.mutate({- ...variables,- id- })- }- onPaymentRelease={() =>- orderRelease.mutate({ id })- }- onPaymentRefund={variables =>- orderPaymentRefund.mutate({- ...variables,- id- })- }- onProductAdd={variables =>- orderLineAdd.mutate({- id,- input: {- quantity: variables.quantity,- variantId: variables.variant.value+ onBack={() => navigate(orderListUrl)}+ order={order}+ countries={maybe(+ () => data.shop.countries,+ []+ ).map(country => ({+ code: country.code,+ label: country.country+ }))}+ shippingMethods={maybe(+ () => data.order.availableShippingMethods,+ []+ )}+ onOrderCancel={variables =>+ orderCancel.mutate({+ id,+ ...variables+ })}- })- }- onProductClick={id => () =>- navigate(productUrl(id))}- onBillingAddressEdit={variables =>- orderUpdate.mutate({- id,- input: {- billingAddress: variables+ onOrderFulfill={variables =>+ orderCreateFulfillment.mutate({+ input: {+ ...variables,+ lines: maybe(+ () => order.lines.edges,+ []+ )+ .map(edge => edge.node)+ .filter(+ line =>+ line.quantityFulfilled <+ line.quantity+ )+ .map((line, lineIndex) => ({+ orderLineId: line.id,+ quantity: variables.lines[lineIndex]+ }))+ .filter(line => line.quantity > 0)+ },+ order: order.id+ })}- })- }- onShippingAddressEdit={variables =>- orderUpdate.mutate({- id,- input: {- shippingAddress: variables+ onFulfillmentCancel={(id, variables) =>+ orderFulfillmentCancel.mutate({+ id,+ input: variables+ })}- })- }- onShippingMethodEdit={variables =>- orderShippingMethodUpdate.mutate({- id,- input: {- shippingMethod: variables.shippingMethod+ onFulfillmentTrackingNumberUpdate={(+ id,+ variables+ ) =>+ orderFulfillmentUpdateTracking.mutate({+ id,+ input: {+ ...variables,+ notifyCustomer: true+ }+ })}- })- }- onOrderLineRemove={id =>- orderLineDelete.mutate({ id })- }- onOrderLineChange={id => quantity =>- orderLineUpdate.mutate({- id,- input: { quantity: parseInt(quantity, 10) }- })}- />- ) : (- <OrderDraftPage- errors={errors}- onNoteAdd={variables =>- orderAddNote.mutate({- input: variables,- order: id- })- }- fetchVariants={search}- variants={maybe(() =>- searchOpts.data.products.edges- .map(edge => edge.node)- .map(product => ({- ...product,- variants: product.variants.edges.map(- edge => edge.node- )- }))- .map(product =>- product.variants.map(variant => ({- ...variant,- name: `${product.name}(${variant.name})`- }))- )- .reduce((prev, curr) => prev.concat(curr), [])- )}- variantsLoading={searchOpts.loading}- fetchUsers={() => undefined}- onCustomerEdit={() => undefined}- onDraftFinalize={() => undefined}- onDraftRemove={() => undefined}- onOrderLineAdd={variables =>- orderLineAdd.mutate({- id,- input: {- quantity: variables.quantity,- variantId: variables.variant.value+ onPaymentCapture={variables =>+ orderPaymentCapture.mutate({+ ...variables,+ id+ })}- })- }- onBack={() => navigate(orderListUrl)}- order={order}- countries={maybe(- () => data.shop.countries,- []- ).map(country => ({- code: country.code,- label: country.country- }))}- shippingMethods={maybe(- () => data.order.availableShippingMethods,- []- )}- onProductClick={id => () =>- navigate(productUrl(id))}- onBillingAddressEdit={variables =>- orderUpdate.mutate({- id,- input: {- billingAddress: variables+ onPaymentRelease={() =>+ orderRelease.mutate({ id })}- })- }- onShippingAddressEdit={variables =>- orderUpdate.mutate({- id,- input: {- shippingAddress: variables+ onPaymentRefund={variables =>+ orderPaymentRefund.mutate({+ ...variables,+ id+ })}- })- }- onShippingMethodEdit={variables =>- orderShippingMethodUpdate.mutate({- id,- input: {- shippingMethod: variables.shippingMethod+ onProductClick={id => () =>+ navigate(productUrl(id))}+ onBillingAddressEdit={variables =>+ orderUpdate.mutate({+ id,+ input: {+ billingAddress: variables+ }+ })}- })- }- onOrderLineRemove={id =>- orderLineDelete.mutate({ id })- }- onOrderLineChange={(id, data) =>- orderLineUpdate.mutate({- id,- input: data- })- }- users={[]}- />- )- }- </OrderOperations>- );- }}- </OrderVariantSearchProvider>+ onShippingAddressEdit={variables =>+ orderUpdate.mutate({+ id,+ input: {+ shippingAddress: variables+ }+ })+ }+ />+ ) : (+ <OrderDraftPage+ errors={errors}+ onNoteAdd={variables =>+ orderAddNote.mutate({+ input: variables,+ order: id+ })+ }+ fetchVariants={search}+ variants={maybe(() =>+ searchOpts.data.products.edges+ .map(edge => edge.node)+ .map(product => ({+ ...product,+ variants: product.variants.edges.map(+ edge => edge.node+ )+ }))+ .map(product =>+ product.variants.map(variant => ({+ ...variant,+ name: `${product.name}(${+ variant.name+ })`+ }))+ )+ .reduce(+ (prev, curr) => prev.concat(curr),+ []+ )+ )}+ users={maybe(+ () =>+ users.searchOpts.data.customers.edges.map(+ edge => edge.node+ ),+ []+ )}+ variantsLoading={searchOpts.loading}+ fetchUsers={users.search}+ usersLoading={users.searchOpts.loading}+ onCustomerEdit={() => undefined}+ onDraftFinalize={() => undefined}+ onDraftRemove={() => undefined}+ onOrderLineAdd={variables =>+ orderLineAdd.mutate({+ id,+ input: {+ quantity: variables.quantity,+ variantId: variables.variant.value+ }+ })+ }+ onBack={() => navigate(orderListUrl)}+ order={order}+ countries={maybe(+ () => data.shop.countries,+ []+ ).map(country => ({+ code: country.code,+ label: country.country+ }))}+ shippingMethods={maybe(+ () => data.order.availableShippingMethods,+ []+ )}+ onProductClick={id => () =>+ navigate(productUrl(id))}+ onBillingAddressEdit={variables =>+ orderUpdate.mutate({+ id,+ input: {+ billingAddress: variables+ }+ })+ }+ onShippingAddressEdit={variables =>+ orderUpdate.mutate({+ id,+ input: {+ shippingAddress: variables+ }+ })+ }+ onShippingMethodEdit={variables =>+ orderShippingMethodUpdate.mutate({+ id,+ input: {+ shippingMethod: variables.shippingMethod+ }+ })+ }+ onOrderLineRemove={id =>+ orderLineDelete.mutate({ id })+ }+ onOrderLineChange={(id, data) =>+ orderLineUpdate.mutate({+ id,+ input: data+ })+ }+ />+ )+ }+ </OrderOperations>+ );+ }}+ </OrderVariantSearchProvider>+ )}+ </UserSearchProvider>);}}</TypedOrderDetailsQuery>diff --git a/saleor/static/dashboard-next/storybook/stories/orders/OrderCustomer.tsx b/saleor/static/dashboard-next/storybook/stories/orders/OrderCustomer.tsxindex 3fb8fd1a5b..32c3628520 100644--- a/saleor/static/dashboard-next/storybook/stories/orders/OrderCustomer.tsx+++ b/saleor/static/dashboard-next/storybook/stories/orders/OrderCustomer.tsx@@ -4,16 +4,19 @@ import * as React from "react";import OrderCustomer, {OrderCustomerProps} from "../../../orders/components/OrderCustomer";-import { order as orderFixture } from "../../../orders/fixtures";+import { clients, order as orderFixture } from "../../../orders/fixtures";import Decorator from "../../Decorator";const order = orderFixture("");const props: OrderCustomerProps = {+ canEditCustomer: true,+ fetchUsers: () => undefined,onBillingAddressEdit: undefined,- onCustomerEditClick: undefined,+ onCustomerEdit: undefined,onShippingAddressEdit: undefined,- order+ order,+ users: clients};storiesOf("Orders / OrderCustomer", module)