| import { Card, Button } from '@automattic/components'; |
| import clsx from 'clsx'; |
| import { localize } from 'i18n-calypso'; |
| import PropTypes from 'prop-types'; |
| import { Component } from 'react'; |
| import { connect } from 'react-redux'; |
| import VisitSite from 'calypso/blocks/visit-site'; |
| import DocumentHead from 'calypso/components/data/document-head'; |
| import Main from 'calypso/components/main'; |
| import SiteSelector from 'calypso/components/site-selector'; |
| import { recordTracksEvent } from 'calypso/lib/analytics/tracks'; |
| import isJetpackCloud from 'calypso/lib/jetpack/is-jetpack-cloud'; |
| import getSites from 'calypso/state/selectors/get-sites'; |
| import hasLoadedSites from 'calypso/state/selectors/has-loaded-sites'; |
| import { hasJetpackActivePlugins, isJetpackSitePred } from 'calypso/state/sites/selectors'; |
|
|
| |
| |
| |
| |
| |
| const isJetpackSiteOrJetpackCloud = isJetpackSitePred( { |
| considerStandaloneProducts: isJetpackCloud(), |
| } ); |
|
|
| import './style.scss'; |
|
|
| class Sites extends Component { |
| static propTypes = { |
| siteBasePath: PropTypes.string.isRequired, |
| clearPageTitle: PropTypes.bool, |
| isPostShare: PropTypes.bool, |
| }; |
|
|
| componentDidMount() { |
| const path = this.getPath(); |
| recordTracksEvent( 'calypso_site_selector_view', { |
| path, |
| is_post_share: this.props.isPostShare, |
| } ); |
|
|
| if ( this.props.fromSite && path ) { |
| recordTracksEvent( 'calypso_site_selector_site_missing', { |
| path, |
| site: this.props.fromSite, |
| } ); |
| } |
| } |
|
|
| filterSites = ( site ) => { |
| |
| |
| if ( hasJetpackActivePlugins( site ) && ! isJetpackSiteOrJetpackCloud( site ) ) { |
| return false; |
| } |
|
|
| if ( site.is_deleted ) { |
| return false; |
| } |
|
|
| const path = this.props.siteBasePath; |
|
|
| |
| if ( /^\/domains/.test( path ) ) { |
| if ( site?.is_wpcom_staging_site ) { |
| return false; |
| } |
| return ! site.jetpack || site.options?.is_automated_transfer; |
| } |
|
|
| |
| if ( /^\/plans/.test( path ) ) { |
| if ( site?.is_wpcom_staging_site ) { |
| return false; |
| } |
| return ! site.jetpack || site.capabilities.manage_options; |
| } |
|
|
| if ( /^\/hosting-config/.test( path ) ) { |
| |
| |
| return true; |
| } |
|
|
| |
| if ( /^\/home/.test( path ) ) { |
| return ! site.is_vip; |
| } |
|
|
| return site; |
| }; |
|
|
| |
| |
| |
| |
| getPath() { |
| let path = this.props.siteBasePath.split( '?' )[ 0 ].split( '/' )[ 1 ]; |
| if ( typeof path !== 'undefined' ) { |
| path = path.toLowerCase(); |
| } |
|
|
| return path; |
| } |
|
|
| getHeaderText() { |
| if ( this.props.getSiteSelectionHeaderText ) { |
| return this.props.getSiteSelectionHeaderText(); |
| } |
|
|
| let path = this.getPath(); |
| const initialPath = path; |
|
|
| const { translate } = this.props; |
|
|
| |
| const editorRouters = [ 'page', 'post', 'edit', 'block-editor' ]; |
| if ( editorRouters.includes( path ) ) { |
| return translate( 'Select a site to start writing' ); |
| } |
|
|
| switch ( path ) { |
| case 'activity-log': |
| path = translate( 'Activity' ); |
| break; |
| case 'stats': |
| path = translate( 'Stats' ); |
| break; |
| case 'plans': |
| path = translate( 'Plans' ); |
| break; |
| case 'media': |
| path = translate( 'Media' ); |
| break; |
| case 'sharing': |
| path = translate( 'Sharing' ); |
| break; |
| case 'people': |
| path = translate( 'Users' ); |
| break; |
| case 'domains': |
| path = translate( 'Domains' ); |
| break; |
| case 'settings': |
| path = translate( 'Settings' ); |
| break; |
| case 'home': |
| path = translate( 'My Home' ); |
| break; |
| case 'hosting-config': |
| path = translate( 'Hosting Configuration' ); |
| break; |
| case 'hosting-overview': |
| path = translate( 'Hosting Overview' ); |
| break; |
| case 'jetpack-search': |
| path = 'Jetpack Search'; |
| break; |
| case 'site-monitoring': |
| path = translate( 'Site Monitoring' ); |
| break; |
| case 'github-deployments': |
| path = translate( 'GitHub Deployments' ); |
| break; |
| case 'earn': |
| path = translate( 'Monetize' ); |
| break; |
| case 'subscribers': |
| path = translate( 'Subscribers' ); |
| break; |
| case 'themes': |
| path = translate( 'Themes' ); |
| break; |
| case 'marketing': |
| path = translate( 'Marketing' ); |
| break; |
| case 'import': |
| path = translate( 'Import' ); |
| break; |
| case 'export': |
| path = translate( 'Export' ); |
| break; |
| case 'email': |
| path = translate( 'Emails' ); |
| break; |
| case 'purchases': |
| path = translate( 'Purchases' ); |
| break; |
| case 'customize': |
| path = translate( 'Customizer' ); |
| break; |
| case 'google-my-business': |
| path = translate( 'Google Business Profile' ); |
| break; |
| case 'view': |
| path = translate( 'Preview' ); |
| break; |
| case 'woocommerce-installation': |
| path = 'WooCommerce'; |
| break; |
| case 'store': |
| path = translate( 'Store' ); |
| break; |
| case 'add-ons': |
| path = translate( 'Add-ons' ); |
| break; |
| } |
| |
| const capitalize = initialPath === path; |
|
|
| return translate( 'Select a site to open {{strong}}%(path)s{{/strong}}', { |
| args: { path }, |
| components: { |
| strong: <strong className={ clsx( { 'strong--capitalize': capitalize } ) } />, |
| }, |
| } ); |
| } |
|
|
| render() { |
| const { clearPageTitle, fromSite, siteBasePath, sites, translate, hasFetchedSites } = |
| this.props; |
| const filteredSites = sites.filter( this.filterSites ); |
|
|
| |
| const showEmptyContent = isJetpackCloud() && hasFetchedSites && ! filteredSites.length; |
|
|
| return ( |
| <> |
| { clearPageTitle && <DocumentHead title="" /> } |
| <Main className={ clsx( 'sites', { 'sites__main-empty': showEmptyContent } ) }> |
| { showEmptyContent ? ( |
| <div className="sites__empty-state"> |
| <h1 className="card-heading-36">{ translate( 'Add a site' ) }</h1> |
| <p> |
| { translate( |
| 'It looks like you don’t have any connected Jetpack sites to manage.' |
| ) } |
| </p> |
| <Button |
| primary |
| target="_blank" |
| href="https://jetpack.com/support/jetpack-agency-licensing-portal-instructions/add-sites-agency-portal-dashboard/" |
| > |
| { translate( 'Learn how to add a site' ) } |
| </Button> |
| </div> |
| ) : ( |
| <> |
| <div className="sites__select-header"> |
| <h2 className="sites__select-heading">{ this.getHeaderText() }</h2> |
| { fromSite && <VisitSite siteSlug={ fromSite } /> } |
| </div> |
| <Card className="sites__select-wrapper"> |
| <SiteSelector filter={ this.filterSites } siteBasePath={ siteBasePath } groups /> |
| </Card> |
| </> |
| ) } |
| </Main> |
| </> |
| ); |
| } |
| } |
|
|
| export default connect( ( state ) => { |
| return { |
| hasFetchedSites: hasLoadedSites( state ), |
| sites: getSites( state, false ), |
| }; |
| } )( localize( Sites ) ); |
|
|