File size: 14,157 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
import config, { isEnabled } from '@automattic/calypso-config';
import { getUrlParts } from '@automattic/calypso-url';
import { UniversalNavbarHeader, UniversalNavbarFooter } from '@automattic/wpcom-template-parts';
import clsx from 'clsx';
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { useEffect } from 'react';
import { connect, useSelector } from 'react-redux';
import { CookieBannerContainerSSR } from 'calypso/blocks/cookie-banner';
import ReaderJoinConversationDialog from 'calypso/blocks/reader-join-conversation/dialog';
import AsyncLoad from 'calypso/components/async-load';
import { withCurrentRoute } from 'calypso/components/route';
import SympathyDevWarning from 'calypso/components/sympathy-dev-warning';
import MasterbarLoggedOut from 'calypso/layout/masterbar/logged-out';
import OauthClientMasterbar from 'calypso/layout/masterbar/oauth-client';
import { isInStepContainerV2FlowContext } from 'calypso/layout/utils';
import isA8CForAgencies from 'calypso/lib/a8c-for-agencies/is-a8c-for-agencies';
import isAkismetRedirect from 'calypso/lib/akismet/is-akismet-redirect';
import isJetpackCloud from 'calypso/lib/jetpack/is-jetpack-cloud';
import { isWpMobileApp } from 'calypso/lib/mobile-app';
import {
isWooOAuth2Client,
isGravatarOAuth2Client,
isJetpackCloudOAuth2Client,
isWPJobManagerOAuth2Client,
isGravPoweredOAuth2Client,
isBlazeProOAuth2Client,
isAndroidOAuth2Client,
isIosOAuth2Client,
} from 'calypso/lib/oauth2-clients';
import { createAccountUrl } from 'calypso/lib/paths';
import isReaderTagEmbedPage from 'calypso/lib/reader/is-reader-tag-embed-page';
import { getOnboardingUrl as getPatternLibraryOnboardingUrl } from 'calypso/my-sites/patterns/paths';
import { isUserLoggedIn } from 'calypso/state/current-user/selectors';
import { getRedirectToOriginal, isTwoFactorEnabled } from 'calypso/state/login/selectors';
import {
getCurrentOAuth2Client,
showOAuth2Layout,
} from 'calypso/state/oauth2-clients/ui/selectors';
import { clearLastActionRequiresLogin } from 'calypso/state/reader-ui/actions';
import { getLastActionRequiresLogin } from 'calypso/state/reader-ui/selectors';
import getCurrentRoute from 'calypso/state/selectors/get-current-route';
import getIsBlazePro from 'calypso/state/selectors/get-is-blaze-pro';
import getIsWoo from 'calypso/state/selectors/get-is-woo';
import getWccomFrom from 'calypso/state/selectors/get-wccom-from';
import isWooJPCFlow from 'calypso/state/selectors/is-woo-jpc-flow';
import { getIsOnboardingAffiliateFlow } from 'calypso/state/signup/flow/selectors';
import { masterbarIsVisible } from 'calypso/state/ui/selectors';
import BodySectionCssClass from './body-section-css-class';
import { refreshColorScheme, getColorSchemeFromCurrentQuery } from './color-scheme';
import HelpCenterLoader from './help-center-loader';
import './style.scss';
const LayoutLoggedOut = ( {
isAkismet,
isJetpackLogin,
isPopup,
isGravatar,
isWPJobManager,
isGravPoweredClient,
isMobile,
masterbarIsHidden,
oauth2Client,
primary,
secondary,
renderHeaderSection,
sectionGroup,
sectionName,
sectionTitle,
redirectUri,
useOAuth2Layout,
showGdprBanner,
isWooJPC,
isWoo,
isBlazePro,
locale,
twoFactorEnabled,
/* eslint-disable no-shadow */
clearLastActionRequiresLogin,
userAllowedToHelpCenter,
colorScheme,
} ) => {
const isLoggedIn = useSelector( isUserLoggedIn );
const currentRoute = useSelector( getCurrentRoute );
const loggedInAction = useSelector( getLastActionRequiresLogin );
const isCheckout = sectionName === 'checkout';
const isCheckoutPending = sectionName === 'checkout-pending';
const isCheckoutFailed =
sectionName === 'checkout' && currentRoute.startsWith( '/checkout/failed-purchases' );
const isJetpackCheckout =
sectionName === 'checkout' && currentRoute.startsWith( '/checkout/jetpack' );
const isJetpackThankYou =
sectionName === 'checkout' && currentRoute.startsWith( '/checkout/jetpack/thank-you' );
const isReaderTagEmbed = typeof window !== 'undefined' && isReaderTagEmbedPage( window.location );
// It's used to add a class name for the login-related pages, except for `/log-in/link/use`.
const hasGravPoweredClientClass =
isGravPoweredClient && ! currentRoute.startsWith( '/log-in/link/use' );
const isMagicLogin =
currentRoute &&
( currentRoute.startsWith( '/log-in/link' ) ||
currentRoute.startsWith( '/log-in/jetpack/link' ) );
const isWpcomMagicLogin =
isMagicLogin &&
! hasGravPoweredClientClass &&
! isJetpackCloudOAuth2Client( oauth2Client ) &&
! isWooOAuth2Client( oauth2Client );
const loadHelpCenter =
isLoggedIn &&
// we want to show only the Help center in my home and the help section (but not the FAB)
( [ 'home', 'help' ].includes( sectionName ) ||
currentRoute?.startsWith( '/start/do-it-for-me/' ) ) &&
userAllowedToHelpCenter;
const classes = {
[ 'is-group-' + sectionGroup ]: sectionGroup,
[ 'is-section-' + sectionName ]: sectionName,
'focus-content': true,
'has-header-section': renderHeaderSection,
'has-no-sidebar': ! secondary,
'has-no-masterbar': masterbarIsHidden,
'is-akismet': isAkismet,
'is-jetpack-login': isJetpackLogin,
'is-jetpack-site': isJetpackCheckout,
'is-popup': isPopup,
'is-gravatar': isGravatar,
'is-mobile': isMobile,
'is-wp-job-manager': isWPJobManager,
'is-grav-powered-client': hasGravPoweredClientClass,
'is-woocommerce-core-profiler-flow': isWooJPC,
'is-magic-login': isMagicLogin,
'is-wpcom-magic-login': isWpcomMagicLogin,
'is-woo-passwordless': isWoo,
'is-blaze-pro': isBlazePro,
'two-factor-auth-enabled': twoFactorEnabled,
'is-woo-com-oauth': isWooOAuth2Client( oauth2Client ),
woo: isWoo,
'feature-flag-woocommerce-core-profiler-passwordless-auth': true,
'jetpack-cloud': isJetpackCloudOAuth2Client( oauth2Client ),
};
let masterbar = null;
// TODO: figure out how refreshColorScheme is used in the rest of the app, and remove this.
useEffect( () => {
isWooJPC && refreshColorScheme( 'default', colorScheme );
}, [] ); // Empty dependency array ensures it runs only once on mount
// Open new window to create account page when a logged in action was triggered on the Reader tag embed page and the user is not logged in
if ( ! isLoggedIn && loggedInAction && isReaderTagEmbed ) {
const { pathname } = getUrlParts( window.location.href );
window.open( createAccountUrl( { redirectTo: pathname, ref: 'reader-lp' } ), '_blank' );
}
if ( isBlazePro || isWoo ) {
/**
* This effectively removes the masterbar completely from Login pages (only).
* However, in some cases, we want the styles imported from the masterbar to be applied.
* They are more generic and affect the whole page, unfortunately.
* For that, importing OauthClientMasterbar suffices to apply those styles, until refactored (we are in the process ofrefactoring).
*/
masterbar = null;
} else if ( useOAuth2Layout && ( isGravatar || isGravPoweredClient ) ) {
masterbar = null;
} else if ( useOAuth2Layout && oauth2Client && oauth2Client.name && ! masterbarIsHidden ) {
classes.dops = true;
classes[ oauth2Client.name ] = true;
masterbar = <OauthClientMasterbar oauth2Client={ oauth2Client } />;
} else if (
config.isEnabled( 'jetpack-cloud' ) ||
isWpMobileApp() ||
isJetpackThankYou ||
isReaderTagEmbed
) {
masterbar = null;
} else if (
[
'patterns',
'performance-profiler',
'plugins',
'reader',
'site-profiler',
'subscriptions',
'theme',
'themes',
].includes( sectionName )
) {
const nonMonochromeSections = [ 'plugins', 'themes', 'theme' ];
const className = clsx( {
'is-style-monochrome':
isEnabled( 'site-profiler/metrics' ) && ! nonMonochromeSections.includes( sectionName ),
} );
masterbar = (
<UniversalNavbarHeader
isLoggedIn={ isLoggedIn }
sectionName={ sectionName }
className={ className }
{ ...( isEnabled( 'site-profiler/metrics' ) &&
! nonMonochromeSections.includes( sectionName ) && {
logoColor: 'white',
} ) }
{ ...( sectionName === 'subscriptions' && { variant: 'minimal' } ) }
{ ...( sectionName === 'patterns' && {
startUrl: getPatternLibraryOnboardingUrl( locale, isLoggedIn ),
} ) }
/>
);
} else if ( isWooJPC ) {
classes.woo = true;
classes[ 'has-no-masterbar' ] = false;
masterbar = (
<AsyncLoad require="calypso/layout/masterbar/woo-core-profiler" placeholder={ null } />
);
} else {
masterbar = ! masterbarIsHidden && (
<MasterbarLoggedOut
title={ sectionTitle }
sectionName={ sectionName }
isCheckout={ isCheckout }
isCheckoutPending={ isCheckoutPending }
isCheckoutFailed={ isCheckoutFailed }
redirectUri={ redirectUri }
/>
);
}
const bodyClass = [ 'font-smoothing-antialiased' ];
return (
<div className={ clsx( 'layout', classes ) }>
{ loadHelpCenter && (
<HelpCenterLoader
sectionName={ sectionName }
loadHelpCenter={ loadHelpCenter }
currentRoute={ currentRoute }
/>
) }
{ 'development' === process.env.NODE_ENV && <SympathyDevWarning /> }
<BodySectionCssClass group={ sectionGroup } section={ sectionName } bodyClass={ bodyClass } />
<div className="layout__header-section">
{ masterbar }
{ renderHeaderSection && (
<div className="layout__header-section-content">{ renderHeaderSection() }</div>
) }
</div>
{ isJetpackCloud() && (
<AsyncLoad require="calypso/jetpack-cloud/style" placeholder={ null } />
) }
{ isA8CForAgencies() && (
<AsyncLoad require="calypso/a8c-for-agencies/style" placeholder={ null } />
) }
<div id="content" className="layout__content">
<AsyncLoad require="calypso/components/global-notices" placeholder={ null } id="notices" />
<div id="primary" className="layout__primary">
{ primary }
</div>
<div id="secondary" className="layout__secondary">
{ secondary }
</div>
</div>
{ config.isEnabled( 'cookie-banner' ) && (
<CookieBannerContainerSSR serverShow={ showGdprBanner } />
) }
{ [ 'plugins' ].includes( sectionName ) && (
<>
<UniversalNavbarFooter currentRoute={ currentRoute } isLoggedIn={ isLoggedIn } />
{ config.isEnabled( 'layout/support-article-dialog' ) && (
<AsyncLoad require="calypso/blocks/support-article-dialog" placeholder={ null } />
) }
</>
) }
{ [ 'patterns', 'reader', 'theme', 'themes' ].includes( sectionName ) &&
! isReaderTagEmbed && (
<UniversalNavbarFooter currentRoute={ currentRoute } isLoggedIn={ isLoggedIn } />
) }
{ ! isLoggedIn &&
// Limit this to reader pages. If we need to expand its scope, make sure we do not
// render it in the 'signup' sections, otherwise this may appear a second time in
// the external signup window it opens.
[ 'reader' ].includes( sectionName ) &&
! isReaderTagEmbed && (
<ReaderJoinConversationDialog
onClose={ () => clearLastActionRequiresLogin() }
isVisible={ !! loggedInAction }
loggedInAction={ loggedInAction }
onLoginSuccess={ () => {
if ( loggedInAction?.redirectTo ) {
window.location = loggedInAction.redirectTo;
} else {
window.location.reload();
}
} }
/>
) }
</div>
);
};
LayoutLoggedOut.displayName = 'LayoutLoggedOut';
LayoutLoggedOut.propTypes = {
primary: PropTypes.element,
secondary: PropTypes.element,
// Connected props
currentRoute: PropTypes.string,
masterbarIsHidden: PropTypes.bool,
section: PropTypes.oneOfType( [ PropTypes.bool, PropTypes.object ] ),
redirectUri: PropTypes.string,
showOAuth2Layout: PropTypes.bool,
};
export default withCurrentRoute(
connect(
( state, { currentSection, currentRoute, currentQuery } ) => {
const sectionGroup = currentSection?.group ?? null;
const sectionName = currentSection?.name ?? null;
const sectionTitle = currentSection?.title ?? '';
const isAkismet = isAkismetRedirect(
new URLSearchParams( getRedirectToOriginal( state )?.split( '?' )[ 1 ] ).get( 'back' )
);
const isInvitationURL = currentRoute.startsWith( '/accept-invite' );
const oauth2Client = getCurrentOAuth2Client( state );
const isGravatar = isGravatarOAuth2Client( oauth2Client );
const isWPJobManager = isWPJobManagerOAuth2Client( oauth2Client );
const isGravPoweredClient = isGravPoweredOAuth2Client( oauth2Client );
const isMobile = isAndroidOAuth2Client( oauth2Client ) || isIosOAuth2Client( oauth2Client );
const isWooJPC = isWooJPCFlow( state );
const isJetpackLogin = currentRoute.startsWith( '/log-in/jetpack' );
const isLogin = currentRoute.startsWith( '/log-in' );
const noMasterbarForRoute = isLogin || isInvitationURL;
const isPopup = '1' === currentQuery?.is_popup;
const noMasterbarForSection =
! isWooOAuth2Client( oauth2Client ) &&
! isBlazeProOAuth2Client( oauth2Client ) &&
[ 'signup', 'jetpack-connect' ].includes( sectionName );
const wccomFrom = getWccomFrom( state );
const masterbarIsHidden =
! ( currentSection || currentRoute ) ||
! masterbarIsVisible( state ) ||
noMasterbarForSection ||
noMasterbarForRoute ||
isInStepContainerV2FlowContext( currentRoute, currentQuery );
const twoFactorEnabled = isTwoFactorEnabled( state );
/**
* This is a mechanism to set a color scheme for WooJPC pages, from the current URL.
*
* TODO: there is a possiblity this is not utilized. If that's the case, we can remove this call.
*/
const colorScheme = isWooJPC ? getColorSchemeFromCurrentQuery( currentQuery ) : null;
return {
isAkismet,
isJetpackLogin,
isPopup,
isGravatar,
isMobile,
isWPJobManager,
isGravPoweredClient,
wccomFrom,
masterbarIsHidden,
sectionGroup,
sectionName,
sectionTitle,
oauth2Client,
useOAuth2Layout: showOAuth2Layout( state ),
isWooJPC,
isWoo: getIsWoo( state ),
isBlazePro: getIsBlazePro( state ),
userAllowedToHelpCenter: ! getIsOnboardingAffiliateFlow( state ),
twoFactorEnabled,
colorScheme,
};
},
{ clearLastActionRequiresLogin }
)( localize( LayoutLoggedOut ) )
);
|