Skip to content

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

Add transition state to customer remove dialog

dominik-zeglen903aca920050
diff --git a/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx b/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx
index 4b4c6dc936..19e5ce7963 100644
--- a/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx
+++ b/saleor/static/dashboard-next/customers/views/CustomerDetails.tsx
@@ -7,7 +7,7 @@ import Messages from "../../components/messages";
import Navigator from "../../components/Navigator";
import { WindowTitle } from "../../components/WindowTitle";
import i18n from "../../i18n";
-import { maybe } from "../../misc";
+import { getMutationState, maybe } from "../../misc";
import { orderUrl } from "../../orders/urls";
import CustomerDetailsPage from "../components/CustomerDetailsPage/CustomerDetailsPage";
import {
@@ -71,72 +71,91 @@ export const CustomerDetailsView: React.StatelessComponent<
>
{(updateCustomer, updateCustomerOpts) => (
<TypedCustomerDetailsQuery displayLoader variables={{ id }}>
- {customerDetails => (
- <>
- <WindowTitle
- title={maybe(() => customerDetails.data.user.email)}
- />
- <CustomerDetailsPage
- customer={customerDetails.data.user}
- disabled={
- customerDetails.loading ||
- updateCustomerOpts.loading ||
- removeCustomerOpts.loading
- }
- errors={maybe(
- () =>
- updateCustomerOpts.data.customerUpdate.errors
- )}
- saveButtonBar={
- updateCustomerOpts.loading ? "loading" : "default"
- }
- onAddressManageClick={() => undefined} // TODO: add address management #3173
- onBack={() => navigate(customerListUrl)}
- onRowClick={id => navigate(orderUrl(id))}
- onSubmit={formData =>
- updateCustomer({
- variables: {
- id,
- input: {
- email: formData.email,
- isActive: formData.isActive,
- note: formData.note
+ {customerDetails => {
+ const formTransitionState = getMutationState(
+ updateCustomerOpts.called,
+ updateCustomerOpts.loading,
+ maybe(
+ () => updateCustomerOpts.data.customerUpdate.errors
+ )
+ );
+ const removeTransitionState = getMutationState(
+ removeCustomerOpts.called,
+ removeCustomerOpts.loading,
+ maybe(
+ () => removeCustomerOpts.data.customerDelete.errors
+ )
+ );
+
+ return (
+ <>
+ <WindowTitle
+ title={maybe(
+ () => customerDetails.data.user.email
+ )}
+ />
+ <CustomerDetailsPage
+ customer={customerDetails.data.user}
+ disabled={
+ customerDetails.loading ||
+ updateCustomerOpts.loading ||
+ removeCustomerOpts.loading
+ }
+ errors={maybe(
+ () =>
+ updateCustomerOpts.data.customerUpdate.errors
+ )}
+ saveButtonBar={formTransitionState}
+ onAddressManageClick={() => undefined} // TODO: add address management #3173
+ onBack={() => navigate(customerListUrl)}
+ onRowClick={id => navigate(orderUrl(id))}
+ onSubmit={formData =>
+ updateCustomer({
+ variables: {
+ id,
+ input: {
+ email: formData.email,
+ isActive: formData.isActive,
+ note: formData.note
+ }
}
- }
- })
- }
- onDelete={() => navigate(customerRemoveUrl(id))}
- onViewAllOrdersClick={() => undefined} // TODO: add filters to order #3172
- />
- <Route exact path={customerRemovePath(":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>
- </>
- )}
+ })
+ }
+ onDelete={() => navigate(customerRemoveUrl(id))}
+ onViewAllOrdersClick={() => undefined} // TODO: add filters to order #3172
+ />
+ <Route exact path={customerRemovePath(":id")}>
+ {({ match }) => (
+ <ActionDialog
+ confirmButtonState={removeTransitionState}
+ 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>
)}
</TypedUpdateCustomerMutation>