1
1
import styled from '@emotion/styled' ;
2
2
import clsx from 'clsx' ;
3
- import React , { ReactNode } from 'react' ;
3
+ import React , { ReactNode , useEffect , useState } from 'react' ;
4
4
import Breadcrumb , { Item as TBreadcrumbItem } from 'calypso/components/breadcrumb' ;
5
5
import FormattedHeader from 'calypso/components/formatted-header' ;
6
6
import ScreenOptionsTab from 'calypso/components/screen-options-tab' ;
@@ -35,6 +35,22 @@ interface Props {
35
35
loggedIn ?: boolean ;
36
36
}
37
37
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
+
38
54
const NavigationHeader = React . forwardRef < HTMLElement , Props > ( ( props , ref ) => {
39
55
const {
40
56
id,
@@ -52,8 +68,13 @@ const NavigationHeader = React.forwardRef< HTMLElement, Props >( ( props, ref )
52
68
loggedIn = true ,
53
69
} = props ;
54
70
71
+ const [ showCrumbs , setShowCrumbs ] = useState ( false ) ;
55
72
const showTitle = alwaysShowTitle || ( navigationItems . length < 2 && loggedIn ) ;
56
73
74
+ useEffect ( ( ) => {
75
+ setShowCrumbs ( checkShouldShowBreadcrumb ( ) ) ;
76
+ } , [ ] ) ;
77
+
57
78
return (
58
79
< header
59
80
id = { id }
@@ -68,12 +89,14 @@ const NavigationHeader = React.forwardRef< HTMLElement, Props >( ( props, ref )
68
89
< Container >
69
90
< div className = "navigation-header__main" >
70
91
{ 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
+ ) }
77
100
{ showTitle && (
78
101
< FormattedHeader
79
102
align = "left"
@@ -89,6 +112,8 @@ const NavigationHeader = React.forwardRef< HTMLElement, Props >( ( props, ref )
89
112
) ;
90
113
} ) ;
91
114
115
+ NavigationHeader . displayName = 'NavigationHeader' ;
116
+
92
117
NavigationHeader . defaultProps = {
93
118
id : '' ,
94
119
className : '' ,
0 commit comments