Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add customer removal
dominik-zeglene7b1f4e7292a
diff --git a/saleor/static/dashboard-next/customers/mutations.ts b/saleor/static/dashboard-next/customers/mutations.tsindex 8640a280fb..cd33917969 100644--- a/saleor/static/dashboard-next/customers/mutations.ts+++ b/saleor/static/dashboard-next/customers/mutations.ts@@ -6,6 +6,10 @@ import {CreateCustomer,CreateCustomerVariables} from "./types/CreateCustomer";+import {+ RemoveCustomer,+ RemoveCustomerVariables+} from "./types/RemoveCustomer";import {UpdateCustomer,UpdateCustomerVariables@@ -48,8 +52,17 @@ export const TypedCreateCustomerMutation = TypedMutation<CreateCustomerVariables>(createCustomer);-// const removeCustomer = gql`-// mutation RemoveCustomer($id: ID!) {-// customerRemove-// }-// `+const removeCustomer = gql`+ mutation RemoveCustomer($id: ID!) {+ customerDelete(id: $id) {+ errors {+ field+ message+ }+ }+ }+`;+export const TypedRemoveCustomerMutation = TypedMutation<+ RemoveCustomer,+ RemoveCustomerVariables+>(removeCustomer);diff --git a/saleor/static/dashboard-next/customers/types/RemoveCustomer.ts b/saleor/static/dashboard-next/customers/types/RemoveCustomer.tsnew file mode 100644index 0000000000..ab5b2a6634--- /dev/null+++ b/saleor/static/dashboard-next/customers/types/RemoveCustomer.ts@@ -0,0 +1,25 @@+/* tslint:disable */+// This file was automatically generated and should not be edited.++// ====================================================+// GraphQL mutation operation: RemoveCustomer+// ====================================================++export interface RemoveCustomer_customerDelete_errors {+ __typename: "Error";+ field: string | null;+ message: string | null;+}++export interface RemoveCustomer_customerDelete {+ __typename: "CustomerDelete";+ errors: (RemoveCustomer_customerDelete_errors | null)[] | null;+}++export interface RemoveCustomer {+ customerDelete: RemoveCustomer_customerDelete | null;+}++export interface RemoveCustomerVariables {+ id: string;+}diff --git a/saleor/static/dashboard-next/customers/urls.ts b/saleor/static/dashboard-next/customers/urls.tsindex 48321b9003..980efdf89b 100644--- a/saleor/static/dashboard-next/customers/urls.ts+++ b/saleor/static/dashboard-next/customers/urls.ts@@ -1,4 +1,6 @@export const customerSection = "/customers/";export const customerListUrl = customerSection;export const customerUrl = (id: string) => customerSection + id + "/";+export const customerAddUrl = customerSection + "add/";+export const customerRemoveUrl = (id: string) => customerUrl(id) + "remove/";diff --git a/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx b/saleor/static/dashboard-next/customers/views/CustomerDetails.tsxindex 691e3efd1c..71657b7961 100644--- a/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx+++ b/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx@@ -1,15 +1,22 @@+import DialogContentText from "@material-ui/core/DialogContentText";import * as React from "react";+import { Route } from "react-router-dom";+import ActionDialog from "../../components/ActionDialog";import Messages from "../../components/messages";import Navigator from "../../components/Navigator";import i18n from "../../i18n";import { maybe } from "../../misc";import { orderUrl } from "../../orders";import CustomerDetailsPage from "../components/CustomerDetailsPage/CustomerDetailsPage";-import { TypedUpdateCustomerMutation } from "../mutations";+import {+ TypedRemoveCustomerMutation,+ TypedUpdateCustomerMutation+} from "../mutations";import { TypedCustomerDetailsQuery } from "../queries";+import { RemoveCustomer } from "../types/RemoveCustomer";import { UpdateCustomer } from "../types/UpdateCustomer";-import { customerListUrl } from "../urls";+import { customerListUrl, customerRemoveUrl, customerUrl } from "../urls";interface CustomerDetailsViewProps {id: string;@@ -34,44 +41,96 @@ export const CustomerDetailsView: React.StatelessComponent<});}};+ const handleCustomerRemoveSuccess = (data: RemoveCustomer) => {+ if (+ data.customerDelete.errors === null ||+ data.customerDelete.errors.length === 0+ ) {+ pushMessage({+ text: i18n.t("Customer removed", {+ context: "notification"+ })+ });+ navigate(customerListUrl);+ }+ };return (- <TypedUpdateCustomerMutation- onCompleted={handleCustomerUpdateSuccess}+ <TypedRemoveCustomerMutation+ variables={{ id }}+ onCompleted={handleCustomerRemoveSuccess}>- {(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(orderUrl(encodeURIComponent(id)))- }- onSubmit={formData =>- updateCustomer({- variables: {- id,- input: {- email: formData.email,- note: formData.note // TODO: add isActive #3174+ {(removeCustomer, removeCustomerOpts) => (+ <TypedUpdateCustomerMutation+ onCompleted={handleCustomerUpdateSuccess}+ >+ {(updateCustomer, updateCustomerOpts) => (+ <TypedCustomerDetailsQuery variables={{ id }}>+ {customerDetails => (+ <>+ <CustomerDetailsPage+ customer={customerDetails.data.user}+ disabled={+ customerDetails.loading ||+ updateCustomerOpts.loading ||+ removeCustomerOpts.loading}- }- })- }- onDelete={() => undefined} // add removal modal #3175- onViewAllOrdersClick={() => undefined} // TODO: add filters to order #3172- />+ errors={maybe(+ () =>+ updateCustomerOpts.data.customerUpdate.errors+ )}+ onAddressManageClick={() => undefined} // TODO: add address management #3173+ onBack={() => navigate(customerListUrl)}+ onRowClick={id =>+ navigate(orderUrl(encodeURIComponent(id)))+ }+ onSubmit={formData =>+ updateCustomer({+ variables: {+ id,+ input: {+ email: formData.email,+ note: formData.note // TODO: add isActive #3174+ }+ }+ })+ }+ onDelete={() => navigate(customerRemoveUrl(id))}+ onViewAllOrdersClick={() => undefined} // TODO: add filters to order #3172+ />+ <Route exact path={customerRemoveUrl(id)}>+ {({ match }) => (+ <ActionDialog+ onClose={() => navigate(customerUrl(id))}+ onConfirm={() => removeCustomer()}+ title={i18n.t("Remove customer", {+ context: "modal title"+ })}+ variant="delete"+ open={!!match}+ >+ <DialogContentText+ dangerouslySetInnerHTML={{+ __html: i18n.t(+ "Are you sure you want to remove <strong>{{ email }}</strong>?",+ {+ context: "modal content",+ email: maybe(+ () => customerDetails.data.user.email+ )+ }+ )+ }}+ />+ </ActionDialog>+ )}+ </Route>+ </>+ )}+ </TypedCustomerDetailsQuery>)}- </TypedCustomerDetailsQuery>+ </TypedUpdateCustomerMutation>)}- </TypedUpdateCustomerMutation>+ </TypedRemoveCustomerMutation>);}}</Messages>diff --git a/saleor/static/dashboard-next/types/globalTypes.ts b/saleor/static/dashboard-next/types/globalTypes.tsindex f7ba5a4b01..f430833940 100644--- a/saleor/static/dashboard-next/types/globalTypes.ts+++ b/saleor/static/dashboard-next/types/globalTypes.ts@@ -179,6 +179,7 @@ export interface CollectionInput {export interface CustomerInput {email?: string | null;+ isActive?: boolean | null;note?: string | null;defaultBillingAddress?: AddressInput | null;defaultShippingAddress?: AddressInput | null;@@ -268,21 +269,22 @@ export interface SiteDomainInput {export interface StaffCreateInput {email?: string | null;- note?: string | null;isActive?: boolean | null;+ note?: string | null;permissions?: (string | null)[] | null;sendPasswordEmail?: boolean | null;}export interface StaffInput {email?: string | null;- note?: string | null;isActive?: boolean | null;+ note?: string | null;permissions?: (string | null)[] | null;}export interface UserCreateInput {email?: string | null;+ isActive?: boolean | null;note?: string | null;defaultBillingAddress?: AddressInput | null;defaultShippingAddress?: AddressInput | null;