Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add customer update mutation
dominik-zeglenf5496325c70f
diff --git a/saleor/static/dashboard-next/customers/mutations.ts b/saleor/static/dashboard-next/customers/mutations.tsnew file mode 100644index 0000000000..846c3db4fd--- /dev/null+++ b/saleor/static/dashboard-next/customers/mutations.ts@@ -0,0 +1,27 @@+import gql from "graphql-tag";++import { TypedMutation } from "../mutations";+import { customerDetailsFragment } from "./queries";+import {+ UpdateCustomer,+ UpdateCustomerVariables+} from "./types/UpdateCustomer";++const updateCustomer = gql`+ ${customerDetailsFragment}+ mutation UpdateCustomer($id: ID!, $input: CustomerInput!) {+ customerUpdate(id: $id, input: $input) {+ errors {+ field+ message+ }+ user {+ ...CustomerDetailsFragment+ }+ }+ }+`;+export const TypedUpdateCustomerMutation = TypedMutation<+ UpdateCustomer,+ UpdateCustomerVariables+>(updateCustomer);diff --git a/saleor/static/dashboard-next/customers/queries.ts b/saleor/static/dashboard-next/customers/queries.tsindex ebc84106f0..d7f6b28eff 100644--- a/saleor/static/dashboard-next/customers/queries.ts+++ b/saleor/static/dashboard-next/customers/queries.ts@@ -8,7 +8,33 @@ import {} from "./types/CustomerDetails";import { ListCustomers, ListCustomersVariables } from "./types/ListCustomers";+export const customerFragment = gql`+ fragment CustomerFragment on User {+ id+ }+`;++export const customerDetailsFragment = gql`+ ${customerFragment}+ ${fragmentAddress}+ fragment CustomerDetailsFragment on User {+ ...CustomerFragment+ dateJoined+ lastLogin+ defaultShippingAddress {+ ...AddressFragment+ }+ defaultBillingAddress {+ ...AddressFragment+ }+ note+ isActive+ }+`;+const customerList = gql`+ ${customerFragment}query ListCustomers($after: String$before: String@@ -18,8 +44,7 @@ const customerList = gql`customers(after: $after, before: $before, first: $first, last: $last) {edges {node {- id+ ...CustomerFragmentorders {totalCount}@@ -40,21 +65,10 @@ export const TypedCustomerListQuery = TypedQuery<>(customerList);const customerDetails = gql`- ${fragmentAddress}+ ${customerDetailsFragment}query CustomerDetails($id: ID!) {user(id: $id) {- id- dateJoined- lastLogin- defaultShippingAddress {- ...AddressFragment- }- defaultBillingAddress {- ...AddressFragment- }- note- isActive+ ...CustomerDetailsFragmentorders(last: 5) {edges {node {diff --git a/saleor/static/dashboard-next/customers/types/CustomerDetailsFragment.ts b/saleor/static/dashboard-next/customers/types/CustomerDetailsFragment.tsnew file mode 100644index 0000000000..4dfdb25e70--- /dev/null+++ b/saleor/static/dashboard-next/customers/types/CustomerDetailsFragment.ts@@ -0,0 +1,62 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++// ====================================================+// GraphQL fragment: CustomerDetailsFragment+// ====================================================++export interface CustomerDetailsFragment_defaultShippingAddress_country {+ __typename: "CountryDisplay";+ code: string;+ country: string;+}++export interface CustomerDetailsFragment_defaultShippingAddress {+ __typename: "Address";+ city: string;+ cityArea: string;+ companyName: string;+ country: CustomerDetailsFragment_defaultShippingAddress_country;+ countryArea: string;+ firstName: string;+ id: string;+ lastName: string;+ phone: string | null;+ postalCode: string;+ streetAddress1: string;+ streetAddress2: string;+}++export interface CustomerDetailsFragment_defaultBillingAddress_country {+ __typename: "CountryDisplay";+ code: string;+ country: string;+}++export interface CustomerDetailsFragment_defaultBillingAddress {+ __typename: "Address";+ city: string;+ cityArea: string;+ companyName: string;+ country: CustomerDetailsFragment_defaultBillingAddress_country;+ countryArea: string;+ firstName: string;+ id: string;+ lastName: string;+ phone: string | null;+ postalCode: string;+ streetAddress1: string;+ streetAddress2: string;+}++export interface CustomerDetailsFragment {+ __typename: "User";+ id: string;+ email: string;+ dateJoined: any;+ lastLogin: any | null;+ defaultShippingAddress: CustomerDetailsFragment_defaultShippingAddress | null;+ defaultBillingAddress: CustomerDetailsFragment_defaultBillingAddress | null;+ note: string | null;+ isActive: boolean;+}diff --git a/saleor/static/dashboard-next/customers/types/CustomerFragment.ts b/saleor/static/dashboard-next/customers/types/CustomerFragment.tsnew file mode 100644index 0000000000..68ed59e640--- /dev/null+++ b/saleor/static/dashboard-next/customers/types/CustomerFragment.ts@@ -0,0 +1,12 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++// ====================================================+// GraphQL fragment: CustomerFragment+// ====================================================++export interface CustomerFragment {+ __typename: "User";+ id: string;+ email: string;+}diff --git a/saleor/static/dashboard-next/customers/types/ListCustomers.ts b/saleor/static/dashboard-next/customers/types/ListCustomers.tsindex 44eed85517..9d3388b1d0 100644--- a/saleor/static/dashboard-next/customers/types/ListCustomers.ts+++ b/saleor/static/dashboard-next/customers/types/ListCustomers.ts@@ -12,8 +12,8 @@ export interface ListCustomers_customers_edges_node_orders {export interface ListCustomers_customers_edges_node {__typename: "User";- email: string;id: string;+ email: string;orders: ListCustomers_customers_edges_node_orders | null;}diff --git a/saleor/static/dashboard-next/customers/types/UpdateCustomer.ts b/saleor/static/dashboard-next/customers/types/UpdateCustomer.tsnew file mode 100644index 0000000000..8e0bd370ea--- /dev/null+++ b/saleor/static/dashboard-next/customers/types/UpdateCustomer.ts@@ -0,0 +1,85 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++import { CustomerInput } from "./../../types/globalTypes";++// ====================================================+// GraphQL mutation operation: UpdateCustomer+// ====================================================++export interface UpdateCustomer_customerUpdate_errors {+ __typename: "Error";+ field: string | null;+ message: string | null;+}++export interface UpdateCustomer_customerUpdate_user_defaultShippingAddress_country {+ __typename: "CountryDisplay";+ code: string;+ country: string;+}++export interface UpdateCustomer_customerUpdate_user_defaultShippingAddress {+ __typename: "Address";+ city: string;+ cityArea: string;+ companyName: string;+ country: UpdateCustomer_customerUpdate_user_defaultShippingAddress_country;+ countryArea: string;+ firstName: string;+ id: string;+ lastName: string;+ phone: string | null;+ postalCode: string;+ streetAddress1: string;+ streetAddress2: string;+}++export interface UpdateCustomer_customerUpdate_user_defaultBillingAddress_country {+ __typename: "CountryDisplay";+ code: string;+ country: string;+}++export interface UpdateCustomer_customerUpdate_user_defaultBillingAddress {+ __typename: "Address";+ city: string;+ cityArea: string;+ companyName: string;+ country: UpdateCustomer_customerUpdate_user_defaultBillingAddress_country;+ countryArea: string;+ firstName: string;+ id: string;+ lastName: string;+ phone: string | null;+ postalCode: string;+ streetAddress1: string;+ streetAddress2: string;+}++export interface UpdateCustomer_customerUpdate_user {+ __typename: "User";+ id: string;+ email: string;+ dateJoined: any;+ lastLogin: any | null;+ defaultShippingAddress: UpdateCustomer_customerUpdate_user_defaultShippingAddress | null;+ defaultBillingAddress: UpdateCustomer_customerUpdate_user_defaultBillingAddress | null;+ note: string | null;+ isActive: boolean;+}++export interface UpdateCustomer_customerUpdate {+ __typename: "CustomerUpdate";+ errors: (UpdateCustomer_customerUpdate_errors | null)[] | null;+ user: UpdateCustomer_customerUpdate_user | null;+}++export interface UpdateCustomer {+ customerUpdate: UpdateCustomer_customerUpdate | null;+}++export interface UpdateCustomerVariables {+ id: string;+ input: CustomerInput;+}diff --git a/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx b/saleor/static/dashboard-next/customers/views/CustomerDetails.tsxindex 0e74d85615..8ec86611c8 100644--- a/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx+++ b/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx@@ -1,8 +1,13 @@import * as React from "react";+import Messages from "../../components/messages";import Navigator from "../../components/Navigator";+import i18n from "../../i18n";+import { maybe } from "../../misc";import CustomerDetailsPage from "../components/CustomerDetailsPage/CustomerDetailsPage";+import { TypedUpdateCustomerMutation } from "../mutations";import { TypedCustomerDetailsQuery } from "../queries";+import { UpdateCustomer } from "../types/UpdateCustomer";import { customerListUrl, customerUrl } from "../urls";interface CustomerDetailsViewProps {@@ -14,21 +19,60 @@ export const CustomerDetailsView: React.StatelessComponent<> = ({ id }) => (<Navigator>{navigate => (- <TypedCustomerDetailsQuery variables={{ id }}>- {customerDetails => (- <CustomerDetailsPage- customer={customerDetails.data.user}- disabled={customerDetails.loading}- onAddressManageClick={() => undefined} // TODO: add address management- onBack={() => navigate(customerListUrl)}- onDelete={() => undefined} // TODO: add delete modal- onRowClick={id => () =>- navigate(customerUrl(encodeURIComponent(id)))}- onSubmit={() => undefined} // TODO: add mutations- onViewAllOrdersClick={() => undefined} // TODO: add filters to order- />- )}- </TypedCustomerDetailsQuery>+ <Messages>+ {pushMessage => {+ const handleCustomerUpdateSuccess = (data: UpdateCustomer) => {+ if (+ data.customerUpdate.errors === null ||+ data.customerUpdate.errors.length === 0+ ) {+ pushMessage({+ text: i18n.t("Customer updated", {+ context: "notification"+ })+ });+ }+ };+ return (+ <TypedUpdateCustomerMutation+ onCompleted={handleCustomerUpdateSuccess}+ >+ {(updateCustomer, updateCustomerOpts) => (+ <TypedCustomerDetailsQuery variables={{ id }}>+ {customerDetails => (+ <CustomerDetailsPage+ customer={customerDetails.data.user}+ disabled={+ customerDetails.loading || updateCustomerOpts.loading+ }+ errors={maybe(+ () => updateCustomerOpts.data.customerUpdate.errors+ )}+ onAddressManageClick={() => undefined} // TODO: add address management #3173+ onBack={() => navigate(customerListUrl)}+ onRowClick={id => () =>+ navigate(customerUrl(encodeURIComponent(id)))}+ onSubmit={formData =>+ updateCustomer({+ variables: {+ id,+ input: {+ email: formData.email,+ note: formData.note // TODO: add isActive #3174+ }+ }+ })+ }+ onDelete={() => undefined} // add removal modal #3175+ onViewAllOrdersClick={() => undefined} // TODO: add filters to order #3172+ />+ )}+ </TypedCustomerDetailsQuery>+ )}+ </TypedUpdateCustomerMutation>+ );+ }}+ </Messages>)}</Navigator>);diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.tsindex fa7b98e0ec..f89212d4a8 100644--- a/saleor/static/dashboard-next/types/globalTypes.ts+++ b/saleor/static/dashboard-next/types/globalTypes.ts@@ -177,6 +177,13 @@ export interface CollectionInput {seo?: SeoInput | null;}+export interface CustomerInput {+ email?: string | null;+ note?: string | null;+ defaultBillingAddress?: AddressInput | null;+ defaultShippingAddress?: AddressInput | null;+}+export interface DraftOrderInput {billingAddress?: AddressInput | null;user?: string | null;