Skip to content

Commit 6ab2845

Browse files
MSD Billing: Fix cancel skip link rendering and skip survey if already sent (#107193)
1 parent 40703cf commit 6ab2845

File tree

2 files changed

+51
-18
lines changed
  • client/dashboard/me/billing-purchases/cancel-purchase

2 files changed

+51
-18
lines changed

client/dashboard/me/billing-purchases/cancel-purchase/cancel-purchase-form/index.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,21 @@ export default function CancelPurchaseForm( props: CancelPurchaseFormProps ) {
418418
const variant = surveyStep !== UPSELL_STEP ? 'primary' : 'secondary';
419419

420420
return (
421-
<Button
422-
disabled={ ! canGoNext() }
423-
isBusy={ isCancelling }
424-
onClick={ onSubmit }
425-
variant={ variant }
426-
>
427-
{ __( 'Submit' ) }
428-
</Button>
421+
<ButtonStack justify="flex-start">
422+
<Button
423+
disabled={ ! canGoNext() }
424+
isBusy={ isCancelling }
425+
onClick={ onSubmit }
426+
variant={ variant }
427+
>
428+
{ __( 'Submit' ) }
429+
</Button>
430+
{ ! canGoNext() && ! isCancelling && (
431+
<Button variant="link" onClick={ onSubmit }>
432+
{ __( 'Skip' ) }
433+
</Button>
434+
) }
435+
</ButtonStack>
429436
);
430437
};
431438

client/dashboard/me/billing-purchases/cancel-purchase/index.tsx

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
siteLatestAtomicTransferQuery,
1919
siteFeaturesQuery,
2020
removePurchaseMutation,
21+
userPreferenceQuery,
2122
} from '@automattic/api-queries';
2223
import config from '@automattic/calypso-config';
2324
import { localizeUrl } from '@automattic/i18n-utils';
@@ -77,6 +78,7 @@ import {
7778
FEEDBACK_STEP,
7879
NEXT_ADVENTURE_STEP,
7980
OFFER_ACCEPTED_STEP,
81+
REMOVE_PLAN_STEP,
8082
UPSELL_STEP,
8183
} from './cancel-purchase-form/steps';
8284
import CancelPurchaseDomainOptions from './domain-options';
@@ -88,7 +90,12 @@ import MarketPlaceSubscriptionsDialog from './marketplace-subscriptions-dialog';
8890
import nextStep from './next-step';
8991
import CancelPurchaseRefundInformation from './refund-information';
9092
import type { CancelPurchaseState } from './types';
91-
import type { Purchase, MarketingSurveyDetails, PlanProduct } from '@automattic/api-core';
93+
import type {
94+
Purchase,
95+
MarketingSurveyDetails,
96+
PlanProduct,
97+
UserPreferences,
98+
} from '@automattic/api-core';
9299
import type { ChangeEvent } from 'react';
93100
import './style.scss';
94101

@@ -113,6 +120,11 @@ export default function CancelPurchase() {
113120
initialized: false,
114121
} );
115122
const { purchaseId } = cancelPurchaseRoute.useParams();
123+
const getCancelPurchaseSurveyCompletedPreferenceKey = (
124+
purchaseId: string | number
125+
): keyof UserPreferences => {
126+
return `cancel-purchase-survey-completed-${ purchaseId }`;
127+
};
116128

117129
// Queries
118130
const { data: purchase, isPending: purchaseQueryIsPending } = useSuspenseQuery(
@@ -150,14 +162,20 @@ export default function CancelPurchase() {
150162
const { data: cancellationOffers } = useQuery(
151163
cancellationOffersQuery( purchase.blog_id, purchase.ID )
152164
);
165+
const {
166+
data: userHasCompletedCancelSurveyForPurchase,
167+
isPending: userPreferencesQueryIsPending,
168+
} = useQuery(
169+
userPreferenceQuery( getCancelPurchaseSurveyCompletedPreferenceKey( purchase.ID ) )
170+
);
153171

154172
// Mutations
155173
const cancelAndRefundPurchaseMutate = useMutation( cancelAndRefundPurchaseMutation() );
156174
const setPurchaseAutoRenewMutation = useMutation( userPurchaseSetAutoRenewQuery() );
157175
const cancelAndRefundMutation = useMutation( cancelAndRefundPurchaseMutation() );
158176
const removePurchaseMutator = useMutation( removePurchaseMutation() );
159177
const extendWithFreeMonthMutation = useMutation( extendPurchaseWithFreeMonthMutation() );
160-
const userPreferences = useMutation( userPreferencesMutation() );
178+
const userPreferencesMutator = useMutation( userPreferencesMutation() );
161179
const {
162180
mutate: applyCancellationOffer,
163181
isPending: isApplyingOffer,
@@ -199,7 +217,7 @@ export default function CancelPurchase() {
199217
[ key ]: value,
200218
},
201219
};
202-
userPreferences.mutate( payload );
220+
userPreferencesMutator.mutate( payload );
203221
};
204222
const flowType = getPurchaseCancellationFlowType( purchase );
205223

@@ -266,6 +284,7 @@ export default function CancelPurchase() {
266284
const getAllSurveySteps = useCallback( () => {
267285
let steps = [ FEEDBACK_STEP ];
268286
const isJetpack = purchase.is_jetpack_plan_or_product;
287+
const skipRemovePlanSurvey = purchase.is_plan && userHasCompletedCancelSurveyForPurchase;
269288

270289
if (
271290
isPartnerPurchase( purchase ) &&
@@ -292,6 +311,16 @@ export default function CancelPurchase() {
292311
steps.push( ATOMIC_REVERT_STEP );
293312
}
294313

314+
if ( skipRemovePlanSurvey ) {
315+
if ( steps.includes( FEEDBACK_STEP ) ) {
316+
steps = steps.filter( ( step ) => step !== FEEDBACK_STEP );
317+
}
318+
if ( steps.includes( NEXT_ADVENTURE_STEP ) ) {
319+
steps = steps.filter( ( step ) => step !== NEXT_ADVENTURE_STEP );
320+
}
321+
steps = [ REMOVE_PLAN_STEP, ...steps ];
322+
}
323+
295324
return steps;
296325
}, [
297326
purchase,
@@ -346,7 +375,7 @@ export default function CancelPurchase() {
346375
customerConfirmedUnderstanding: false,
347376
domainConfirmationConfirmed: false,
348377
initialized: true,
349-
isLoading: true,
378+
isLoading: REMOVE_PLAN_STEP !== firstStep,
350379
isNextAdventureValid: false,
351380
isSubmitting: false,
352381
questionOneOrder,
@@ -360,7 +389,7 @@ export default function CancelPurchase() {
360389
showDomainOptionsStep: false,
361390
siteId: undefined,
362391
solution: '',
363-
surveyShown: false,
392+
surveyShown: REMOVE_PLAN_STEP === firstStep,
364393
surveyStep: firstStep,
365394
upsell: '',
366395
willAtomicSiteRevert: willAtomicSiteRevertAfterPurchaseDeactivation(
@@ -393,10 +422,6 @@ export default function CancelPurchase() {
393422
setState( ( state ) => ( { ...state, isShowingMarketplaceSubscriptionsDialog: true } ) );
394423
};
395424

396-
const getCancelPurchaseSurveyCompletedPreferenceKey = ( purchaseId: string | number ): string => {
397-
return `cancel-purchase-survey-completed-${ purchaseId }`;
398-
};
399-
400425
const cancelPurchaseSurveyCompleted = ( purchaseId: number ) => () => {
401426
savePreference( getCancelPurchaseSurveyCompletedPreferenceKey( purchaseId ), true )();
402427
};
@@ -1016,7 +1041,8 @@ export default function CancelPurchase() {
10161041
purchaseQueryIsPending ||
10171042
( Boolean( purchase.meta ) && domainQueryIsPending ) ||
10181043
siteLatestAtomicTransferQueryIsPending ||
1019-
productsQueryIsPending;
1044+
productsQueryIsPending ||
1045+
userPreferencesQueryIsPending;
10201046

10211047
const isDataValid = useCallback( () => {
10221048
if ( isDataLoading ) {

0 commit comments

Comments
 (0)