From 0539f30c8100a481bf1824392287384a7ebd7740 Mon Sep 17 00:00:00 2001 From: Payton Swick Date: Tue, 8 Oct 2024 11:17:33 -0400 Subject: [PATCH] Purchases: Revamp Cancellation Flow (originally 93211) (#95065) * Initial commit * Revamp cancellation flow * Address review * Fix console errors * Improve button alignment * Remove redundant styles * Remove bold for "immediately" * Address review * Address feedback * Address review * Remove linter comment --------- Co-authored-by: Aurorum <43215253+Aurorum@users.noreply.github.com> --- .../me/purchases/cancel-purchase/button.jsx | 55 +-- .../cancel-purchase/domain-options.jsx | 299 +++++++++++++++ .../cancel-purchase/feature-list.jsx | 61 +++ client/me/purchases/cancel-purchase/index.jsx | 290 +++++++++----- .../cancel-purchase/loading-placeholder.jsx | 46 +-- .../cancel-purchase/refund-information.jsx | 353 +----------------- .../me/purchases/cancel-purchase/style.scss | 197 +++++++--- .../cancel-purchase/support-link.jsx | 83 ++++ .../purchases/confirm-cancel-domain/index.jsx | 65 ++-- .../loading-placeholder.jsx | 36 +- .../confirm-cancel-domain/style.scss | 15 + client/me/purchases/controller.jsx | 4 - packages/calypso-products/src/plans-list.tsx | 35 ++ packages/calypso-products/src/types.ts | 1 + 14 files changed, 950 insertions(+), 590 deletions(-) create mode 100644 client/me/purchases/cancel-purchase/domain-options.jsx create mode 100644 client/me/purchases/cancel-purchase/feature-list.jsx create mode 100644 client/me/purchases/cancel-purchase/support-link.jsx diff --git a/client/me/purchases/cancel-purchase/button.jsx b/client/me/purchases/cancel-purchase/button.jsx index 308b4830b84ea..59c7e6555daac 100644 --- a/client/me/purchases/cancel-purchase/button.jsx +++ b/client/me/purchases/cancel-purchase/button.jsx @@ -275,42 +275,51 @@ class CancelPurchaseButton extends Component { render() { const { purchase, translate, cancelBundledDomain, includedDomainPurchase } = this.props; - let text; - let onClick; - if ( hasAmountAvailableToRefund( purchase ) ) { - onClick = this.handleCancelPurchaseClick; + const isValidForRefund = + isDomainRegistration( purchase ) || + isSubscription( purchase ) || + isOneTimePurchase( purchase ); - if ( isDomainRegistration( purchase ) ) { - text = translate( 'Cancel Domain and Refund' ); + const isValidForCancel = isDomainRegistration( purchase ) && isRefundable( purchase ); + + const onClick = ( () => { + if ( hasAmountAvailableToRefund( purchase ) && isValidForRefund ) { + return this.handleCancelPurchaseClick; } - if ( isSubscription( purchase ) ) { - text = translate( 'Cancel Subscription' ); + if ( ! hasAmountAvailableToRefund( purchase ) && isValidForCancel ) { + return this.handleCancelPurchaseClick; } - if ( isOneTimePurchase( purchase ) ) { - text = translate( 'Cancel and Refund' ); + if ( ! hasAmountAvailableToRefund( purchase ) && isSubscription( purchase ) ) { + return this.handleCancelPurchaseClick; } - } else { - onClick = () => { - this.cancelPurchase( purchase ); - }; - if ( isDomainRegistration( purchase ) ) { - text = translate( 'Cancel Domain' ); + return () => this.cancelPurchase( purchase ); + } )(); - // Domain in AGP bought with domain credits should be canceled immediately - if ( isRefundable( purchase ) ) { - onClick = this.handleCancelPurchaseClick; + const text = ( () => { + if ( hasAmountAvailableToRefund( purchase ) ) { + if ( isDomainRegistration( purchase ) ) { + return translate( 'Cancel domain and refund' ); + } + if ( isSubscription( purchase ) ) { + return translate( 'Cancel subscription' ); + } + if ( isOneTimePurchase( purchase ) ) { + return translate( 'Cancel and refund' ); } } + if ( isDomainRegistration( purchase ) ) { + return translate( 'Cancel domain' ); + } + if ( isSubscription( purchase ) ) { - onClick = this.handleCancelPurchaseClick; - text = translate( 'Cancel Subscription' ); + return translate( 'Cancel subscription' ); } - } + } )(); const disableButtons = this.state.disabled || this.props.disabled; const { isJetpack, isAkismet, purchaseListUrl, activeSubscriptions } = this.props; @@ -322,7 +331,7 @@ class CancelPurchaseButton extends Component { const planName = getName( purchase ); return ( -
+