Skip to content

Commit

Permalink
Rename clearedCart to userHasClearedCart
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenDufresne committed Jan 17, 2025
1 parent 3c483a7 commit 1a976af
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions client/layout/masterbar/checkout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ const CheckoutMasterbar = ( {
const { responseCart, replaceProductsInCart } = useShoppingCart( cartKey );
const [ isModalVisible, setIsModalVisible ] = useState( false );

const closeAndLeave = ( clearedCart: boolean = false ) =>
const closeAndLeave = ( userHasClearedCart: boolean = false ) =>
leaveCheckout( {
siteSlug,
forceCheckoutBackUrl,
previousPath,
tracksEvent: 'calypso_masterbar_close_clicked',
clearedCart: clearedCart,
userHasClearedCart: userHasClearedCart,
} );

const clickClose = () => {
Expand Down
12 changes: 6 additions & 6 deletions client/my-sites/checkout/src/lib/leave-checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import { sendMessageToOpener } from './popup';
const debug = debugFactory( 'calypso:leave-checkout' );

const getCloseURL = ( {
clearedCart,
userHasClearedCart,
previousPath,
siteSlug,
}: {
clearedCart: boolean;
userHasClearedCart: boolean;
previousPath?: string;
siteSlug?: string;
} ): string => {
Expand All @@ -34,7 +34,7 @@ const getCloseURL = ( {
/* Regex to match /domains/add/abc123/email/def456? */
const emailUpsellRegex = /\/domains\/add\/[^/]+\/email\/[^/]+(\?|\/|$)/;

if ( clearedCart && emailUpsellRegex.test( previousPath ) ) {
if ( userHasClearedCart && emailUpsellRegex.test( previousPath ) ) {
return '/domains/add/' + siteSlug;
}
return previousPath;
Expand All @@ -49,14 +49,14 @@ export const leaveCheckout = ( {
previousPath,
tracksEvent,
createUserAndSiteBeforeTransaction,
clearedCart = false,
userHasClearedCart = false,
}: {
siteSlug?: string;
forceCheckoutBackUrl?: string;
previousPath?: string;
tracksEvent: string;
createUserAndSiteBeforeTransaction?: boolean;
clearedCart?: boolean;
userHasClearedCart?: boolean;
} ): void => {
recordTracksEvent( tracksEvent );
debug( 'leaving checkout with args', {
Expand Down Expand Up @@ -97,7 +97,7 @@ export const leaveCheckout = ( {
return;
}

const closeUrl = getCloseURL( { clearedCart, previousPath, siteSlug } );
const closeUrl = getCloseURL( { userHasClearedCart, previousPath, siteSlug } );

try {
const searchParams = new URLSearchParams( window.location.search );
Expand Down
12 changes: 6 additions & 6 deletions client/my-sites/checkout/src/test/leave-checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe( 'leaveCheckout', () => {
leaveCheckout( {
siteSlug: siteSlug,
tracksEvent: 'checkout_cancel',
clearedCart: true,
userHasClearedCart: true,
} );

expect( navigate ).toHaveBeenCalledWith( `/plans/${ siteSlug }` );
Expand All @@ -79,7 +79,7 @@ describe( 'leaveCheckout', () => {
it( 'returns to /start if missing site slug', () => {
leaveCheckout( {
tracksEvent: 'checkout_cancel',
clearedCart: true,
userHasClearedCart: true,
} );

expect( navigate ).toHaveBeenCalledWith( '/start' );
Expand All @@ -92,7 +92,7 @@ describe( 'leaveCheckout', () => {
siteSlug: siteSlug,
tracksEvent: 'checkout_cancel',
previousPath: '/domains/add/my-search-domain/email/mywpsite.wordpress.com?',
clearedCart: true,
userHasClearedCart: true,
} );

expect( navigate ).toHaveBeenCalledWith( `/domains/add/${ siteSlug }` );
Expand All @@ -104,7 +104,7 @@ describe( 'leaveCheckout', () => {
leaveCheckout( {
tracksEvent: 'checkout_cancel',
previousPath: previousPath,
clearedCart: false,
userHasClearedCart: false,
} );

expect( navigate ).toHaveBeenCalledWith( previousPath );
Expand All @@ -119,7 +119,7 @@ describe( 'leaveCheckout', () => {
siteSlug: siteSlug,
tracksEvent: 'checkout_cancel',
previousPath: previousPath,
clearedCart: false,
userHasClearedCart: false,
} );

expect( navigate ).toHaveBeenCalledWith( previousPath );
Expand All @@ -134,7 +134,7 @@ describe( 'leaveCheckout', () => {
siteSlug: siteSlug,
tracksEvent: 'checkout_cancel',
previousPath: previousPath,
clearedCart: false,
userHasClearedCart: false,
} );

expect( navigate ).toHaveBeenCalledWith( previousPath );
Expand Down

0 comments on commit 1a976af

Please sign in to comment.