Skip to content

Commit

Permalink
Initial PoC of using the add-new-site component on /sites
Browse files Browse the repository at this point in the history
  • Loading branch information
markbiek committed Jan 14, 2025
1 parent 1b3e3d7 commit e48f2c0
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 8 deletions.
8 changes: 7 additions & 1 deletion client/components/add-new-site/content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ const AddNewSiteContent = ( props: AddNewSiteContentProps ) => {
/>
);
}
return null;
return (
<AsyncLoad
{ ...props }
require="calypso/components/add-new-site/content/site-list"
placeholder={ null }
/>
);
};

export default AddNewSiteContent;
22 changes: 22 additions & 0 deletions client/components/add-new-site/content/site-list/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import AddNewSiteSiteListMenuItems from 'calypso/components/add-new-site/menu-items/site-list';
import AddNewSitePopover from 'calypso/components/add-new-site/popover';
import type { AddNewSiteContentProps } from 'calypso/components/add-new-site/types';

const AddNewSiteSiteList = ( {
isMenuVisible,
popoverMenuContext,
setMenuVisible,
toggleMenu,
}: AddNewSiteContentProps ) => {
return (
<AddNewSitePopover
isMenuVisible={ isMenuVisible }
toggleMenu={ toggleMenu }
popoverMenuContext={ popoverMenuContext }
>
<AddNewSiteSiteListMenuItems setMenuVisible={ setMenuVisible } />
</AddNewSitePopover>
);
};

export default AddNewSiteSiteList;
139 changes: 139 additions & 0 deletions client/components/add-new-site/menu-items/site-list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import config from '@automattic/calypso-config';
import { WordPressLogo, JetpackLogo } from '@automattic/components';
import { download, reusableBlock, Icon } from '@wordpress/icons';
import clsx from 'clsx';
import { useTranslate } from 'i18n-calypso';
import { useContext, useCallback } from 'react';
import { A4A_MARKETPLACE_HOSTING_PRESSABLE_LINK } from 'calypso/a8c-for-agencies/components/sidebar-menu/lib/constants';
import useFetchDevLicenses from 'calypso/a8c-for-agencies/data/purchases/use-fetch-dev-licenses';
import usePressableOwnershipType from 'calypso/a8c-for-agencies/sections/marketplace/hosting-overview/hooks/use-pressable-ownership-type';
import devSiteBanner from 'calypso/assets/images/a8c-for-agencies/dev-site-banner.svg';
import pressableIcon from 'calypso/assets/images/pressable/pressable-icon.svg';
import AddNewSiteContext from 'calypso/components/add-new-site/context';
import AddNewSiteMenuItem from 'calypso/components/add-new-site/menu-item';
import AddNewSitePopoverColumn from 'calypso/components/add-new-site/popover-column';
import { preventWidows } from 'calypso/lib/formatting';
import type { AddNewSiteMenuItemsProps } from 'calypso/components/add-new-site/types';

const AddNewSiteSiteListMenuItems = ( { setMenuVisible }: AddNewSiteMenuItemsProps ) => {
const translate = useTranslate();

const { setVisibleModalType } = useContext( AddNewSiteContext );

const pressableOwnership = usePressableOwnershipType();

const { data: devLicenses } = useFetchDevLicenses();

const hasAvailableDevSites = devLicenses?.available > 0;

const devSitesEnabled = config.isEnabled( 'a4a-dev-sites' );

const handleOnClick = useCallback(
( modalType: string ) => {
setVisibleModalType( modalType );
setMenuVisible( false );
},
[ setVisibleModalType, setMenuVisible ]
);

return (
<>
<AddNewSitePopoverColumn heading={ translate( 'Add a new site' ) }>
<AddNewSiteMenuItem
icon={ <WordPressLogo /> }
heading={ translate( 'WordPress.com' ) }
description={ preventWidows(
translate( 'Build and grow your site, all in one powerful platform.' )
) }
buttonProps={ {
onClick: () => {
// TODO
},
} }
/>
<AddNewSiteMenuItem
icon={ <JetpackLogo /> }
heading={ translate( 'Via the Jetpack plugin' ) }
description={ preventWidows(
translate( 'Install the Jetpack plugin on an existing site' )
) }
buttonProps={ {
onClick: () => {
handleOnClick( 'jetpack-connection' );
},
} }
/>
<AddNewSiteMenuItem
icon={ <img src={ pressableIcon } alt="Pressable" /> }
heading="Pressable"
description={ translate( 'Bring your theme, plugins, and content to WordPress.com.' ) }
buttonProps={ {
href:
pressableOwnership === 'regular'
? 'https://my.pressable.com/agency/auth'
: A4A_MARKETPLACE_HOSTING_PRESSABLE_LINK,
target: pressableOwnership === 'regular' ? '_blank' : undefined,
} }
/>
</AddNewSitePopoverColumn>
<AddNewSitePopoverColumn heading={ translate( 'Migrate & Import' ) }>
<AddNewSiteMenuItem
icon={ <Icon icon={ reusableBlock } size={ 18 } /> }
heading="Migrate"
description={ preventWidows(
translate( 'Bring your theme, plugins, and content to WordPress.com.' )
) }
buttonProps={ {
onClick: () => {
// TODO
},
} }
/>
<AddNewSiteMenuItem
icon={ <Icon icon={ download } size={ 18 } /> }
heading="Import"
description={ preventWidows(
translate( 'Use a backup file to import your content into a new site.' )
) }
buttonProps={ {
onClick: () => {
// TODO
},
} }
/>
</AddNewSitePopoverColumn>
{ devSitesEnabled && (
<AddNewSitePopoverColumn>
<AddNewSiteMenuItem
isBanner
icon={ <img src={ devSiteBanner } alt="Get a Free Domain and Up to 55% off" /> }
heading={ translate( 'Get a Free Domain and Up to 55% off' ) }
description={ preventWidows(
translate(
'Save up to 55% on annual plans and get a free custom domain for a year. Your next site is just a step away.'
)
) }
disabled={ ! hasAvailableDevSites }
buttonProps={ {
onClick: () => {
// TODO
},
} }
>
<div>
<div
className={ clsx( 'add-new-site-popover__cta', {
disabled: ! hasAvailableDevSites,
} ) }
>
{ translate( 'Unlock Offer' ) }
</div>
</div>
</AddNewSiteMenuItem>
</AddNewSitePopoverColumn>
) }
</>
);
};

export default AddNewSiteSiteListMenuItems;
25 changes: 18 additions & 7 deletions client/sites/components/sites-dashboard-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import styled from '@emotion/styled';
import { download, Icon } from '@wordpress/icons';
import { useI18n } from '@wordpress/react-i18n';
import { addQueryArgs } from '@wordpress/url';
import { useState, useRef } from 'react';
import AddNewSiteContent from 'calypso/components/add-new-site/content';
import PopoverMenuItem from 'calypso/components/popover-menu/item';
import SplitButton from 'calypso/components/split-button';
import { useAddNewSiteUrl } from 'calypso/lib/paths/use-add-new-site-url';
import { MEDIA_QUERIES, TRACK_SOURCE_NAME } from 'calypso/sites-dashboard/utils';
import { useSitesDashboardImportSiteUrl } from '../hooks/use-sites-dashboard-import-site-url';
import { LinkWithRedirect } from './link-with-redirect';
import 'calypso/components/add-new-site/style.scss';

interface SitesDashboardHeaderProps {
isPreviewPaneOpen: boolean;
Expand Down Expand Up @@ -102,16 +104,17 @@ const popoverHoverStyles = css`
const SitesDashboardHeader: React.FC< SitesDashboardHeaderProps > = ( { isPreviewPaneOpen } ) => {
const { __ } = useI18n();
const isMobile = useMobileBreakpoint();

const createSiteUrl = useAddNewSiteUrl( {
source: TRACK_SOURCE_NAME,
ref: 'topbar',
} );
const [ isMenuVisible, setMenuVisible ] = useState( false );
const popoverMenuContext = useRef( null );

const importSiteUrl = useSitesDashboardImportSiteUrl( {
ref: 'topbar',
} );

const toggleMenu = () => {
setMenuVisible( ( isVisible ) => ! isVisible );
};

return (
<PageHeader>
<HeaderControls>
Expand All @@ -122,10 +125,11 @@ const SitesDashboardHeader: React.FC< SitesDashboardHeaderProps > = ( { isPrevie
label={ __( 'Add new site' ) }
onClick={ () => {
recordTracksEvent( 'calypso_sites_dashboard_new_site_action_click_add' );
toggleMenu();
} }
href={ createSiteUrl }
toggleIcon={ isMobile ? 'plus' : undefined }
isMobile={ isMobile }
ref={ popoverMenuContext }
>
<PopoverMenuItem
onClick={ () => {
Expand All @@ -151,6 +155,13 @@ const SitesDashboardHeader: React.FC< SitesDashboardHeaderProps > = ( { isPrevie
<span>{ __( 'Import an existing site' ) }</span>
</PopoverMenuItem>
</AddNewSiteSplitButton>

<AddNewSiteContent
isMenuVisible={ isMenuVisible }
toggleMenu={ toggleMenu }
popoverMenuContext={ popoverMenuContext }
setMenuVisible={ setMenuVisible }
/>
</HeaderControls>
</PageHeader>
);
Expand Down

0 comments on commit e48f2c0

Please sign in to comment.