Skip to content

Commit 5c9fa23

Browse files
authored
Commerce trial: delete expired sites (#103504)
1 parent 65106b6 commit 5c9fa23

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

client/components/navigation-header/index.tsx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import styled from '@emotion/styled';
22
import clsx from 'clsx';
3-
import React, { ReactNode } from 'react';
3+
import React, { ReactNode, useEffect, useState } from 'react';
44
import Breadcrumb, { Item as TBreadcrumbItem } from 'calypso/components/breadcrumb';
55
import FormattedHeader from 'calypso/components/formatted-header';
66
import ScreenOptionsTab from 'calypso/components/screen-options-tab';
@@ -35,6 +35,22 @@ interface Props {
3535
loggedIn?: boolean;
3636
}
3737

38+
// This function checks if the URL contains the 'options' query parameter and if it includes 'noCrumbs'.
39+
// Expired eCommerce trials use this to hide the breadcrumbs since those users can't access settings and other pages exposed in the breadcrumbs.
40+
export const checkShouldShowBreadcrumb = (): boolean => {
41+
if ( typeof window === 'undefined' ) {
42+
return false;
43+
}
44+
45+
try {
46+
const params = new URLSearchParams( window.location.search );
47+
const options = params.get( 'options' ) || '';
48+
return ! options.includes( 'noCrumbs' );
49+
} catch {
50+
return false;
51+
}
52+
};
53+
3854
const NavigationHeader = React.forwardRef< HTMLElement, Props >( ( props, ref ) => {
3955
const {
4056
id,
@@ -52,8 +68,13 @@ const NavigationHeader = React.forwardRef< HTMLElement, Props >( ( props, ref )
5268
loggedIn = true,
5369
} = props;
5470

71+
const [ showCrumbs, setShowCrumbs ] = useState( false );
5572
const showTitle = alwaysShowTitle || ( navigationItems.length < 2 && loggedIn );
5673

74+
useEffect( () => {
75+
setShowCrumbs( checkShouldShowBreadcrumb() );
76+
}, [] );
77+
5778
return (
5879
<header
5980
id={ id }
@@ -68,12 +89,14 @@ const NavigationHeader = React.forwardRef< HTMLElement, Props >( ( props, ref )
6889
<Container>
6990
<div className="navigation-header__main">
7091
{ screenOptionsTab && <ScreenOptionsTab wpAdminPath={ screenOptionsTab } /> }
71-
<Breadcrumb
72-
items={ navigationItems }
73-
mobileItem={ mobileItem }
74-
compact={ compactBreadcrumb }
75-
hideWhenOnlyOneLevel
76-
/>
92+
{ showCrumbs && (
93+
<Breadcrumb
94+
items={ navigationItems }
95+
mobileItem={ mobileItem }
96+
compact={ compactBreadcrumb }
97+
hideWhenOnlyOneLevel
98+
/>
99+
) }
77100
{ showTitle && (
78101
<FormattedHeader
79102
align="left"
@@ -89,6 +112,8 @@ const NavigationHeader = React.forwardRef< HTMLElement, Props >( ( props, ref )
89112
);
90113
} );
91114

115+
NavigationHeader.displayName = 'NavigationHeader';
116+
92117
NavigationHeader.defaultProps = {
93118
id: '',
94119
className: '',

client/my-sites/controller.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ function onSelectedSiteAvailable( context ) {
324324
! wasUpgradedFromTrialSite( state, selectedSite.ID ) &&
325325
[ PLAN_FREE, PLAN_JETPACK_FREE ].includes( currentPlanSlug )
326326
) {
327+
const isDeleteSitePath = /^\/sites\/settings\/site\/[^/]+\/delete-site\?options=noCrumbs$/.test(
328+
context.path
329+
);
330+
327331
const permittedPathPrefixes = [
328332
'/checkout/',
329333
'/domains/',
@@ -334,7 +338,11 @@ function onSelectedSiteAvailable( context ) {
334338
'/settings/delete-site/',
335339
];
336340

337-
if ( ! permittedPathPrefixes.some( ( prefix ) => context.pathname.startsWith( prefix ) ) ) {
341+
const isPermittedPath = permittedPathPrefixes.some( ( prefix ) =>
342+
context.pathname.startsWith( prefix )
343+
);
344+
345+
if ( ! isDeleteSitePath && ! isPermittedPath ) {
338346
page.redirect( `/plans/my-plan/trial-expired/${ selectedSite.slug }` );
339347
return false;
340348
}

client/my-sites/plans/ecommerce-trial/ecommerce-trial-expired/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const ECommerceTrialExpired = (): JSX.Element => {
6161
siteIsAtomic && selectedSite?.URL
6262
? `${ selectedSite.URL }/wp-admin/export.php`
6363
: `/export/${ siteSlug }`;
64-
const settingsDeleteSiteUrl = `/settings/delete-site/${ siteSlug }`;
64+
const settingsDeleteSiteUrl = `/settings/delete-site/${ siteSlug }?options=noCrumbs`;
6565

6666
const onDeleteClick = useCallback(
6767
( e: React.MouseEvent< HTMLButtonElement > ) => {
@@ -77,7 +77,7 @@ const ECommerceTrialExpired = (): JSX.Element => {
7777
);
7878

7979
const isWooExpressTrial = purchase?.isWooExpressTrial;
80-
const isEntrepreneurTrial = purchase?.isWooExpressTrial === false;
80+
const isEntrepreneurTrial = ! purchase?.isWooExpressTrial;
8181

8282
return (
8383
<>

0 commit comments

Comments
 (0)