import DialogContentText from "@material-ui/core/DialogContentText"; import React from "react"; import { FormattedMessage, useIntl } from "react-intl"; import ActionDialog from "@saleor/components/ActionDialog"; import { WindowTitle } from "@saleor/components/WindowTitle"; import useNavigator from "@saleor/hooks/useNavigator"; import useNotifier from "@saleor/hooks/useNotifier"; import { commonMessages } from "@saleor/intl"; import { getMutationState, maybe } from "../../misc"; import { orderListUrl, orderUrl } from "../../orders/urls"; import CustomerDetailsPage from "../components/CustomerDetailsPage/CustomerDetailsPage"; import { TypedRemoveCustomerMutation, TypedUpdateCustomerMutation } from "../mutations"; import { TypedCustomerDetailsQuery } from "../queries"; import { RemoveCustomer } from "../types/RemoveCustomer"; import { UpdateCustomer } from "../types/UpdateCustomer"; import { customerAddressesUrl, customerListUrl, customerUrl, CustomerUrlQueryParams } from "../urls"; interface CustomerDetailsViewProps { id: string; params: CustomerUrlQueryParams; } export const CustomerDetailsView: React.StatelessComponent< CustomerDetailsViewProps > = ({ id, params }) => { const navigate = useNavigator(); const notify = useNotifier(); const intl = useIntl(); const handleCustomerUpdateSuccess = (data: UpdateCustomer) => { if (data.customerUpdate.errors.length === 0) { notify({ text: intl.formatMessage(commonMessages.savedChanges) }); } }; const handleCustomerRemoveSuccess = (data: RemoveCustomer) => { if (data.customerDelete.errors.length === 0) { notify({ text: intl.formatMessage({ defaultMessage: "Customer Removed" }) }); navigate(customerListUrl()); } }; return ( {(removeCustomer, removeCustomerOpts) => ( {(updateCustomer, updateCustomerOpts) => ( {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 ( <> customerDetails.data.user.email)} /> updateCustomerOpts.data.customerUpdate.errors )} saveButtonBar={formTransitionState} onAddressManageClick={() => navigate(customerAddressesUrl(id)) } onBack={() => navigate(customerListUrl())} onRowClick={id => navigate(orderUrl(id))} onSubmit={formData => updateCustomer({ variables: { id, input: { email: formData.email, firstName: formData.firstName, isActive: formData.isActive, lastName: formData.lastName, note: formData.note } } }) } onDelete={() => navigate( customerUrl(id, { action: "remove" }) ) } onViewAllOrdersClick={() => navigate( orderListUrl({ email: maybe(() => customerDetails.data.user.email) }) ) } /> navigate(customerUrl(id), true)} onConfirm={() => removeCustomer()} title={intl.formatMessage({ defaultMessage: "Delete Customer", description: "dialog header" })} variant="delete" open={params.action === "remove"} > {maybe( () => customerDetails.data.user.email, "..." )} ) }} /> ); }} )} )} ); }; export default CustomerDetailsView;