Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stepSlug, useMyDomainInputMode } from '../constants';
import type { SiteDetails } from '@automattic/data-stores';
import type { DashboardType } from 'calypso/dashboard/utils/link';
import type { AppConfigSlug } from 'calypso/dashboard/app/context';

type ValueOf< T > = T[ keyof T ];
export type Maybe< T > = T | null | undefined;
Expand Down Expand Up @@ -57,7 +57,7 @@ export type StartStepProps = {
progressStepList: Record< PossibleSlugs, string >;
domainInboundTransferStatusInfo: Partial< InboundTransferStatusInfo >;
initialMode: PossibleInitialModes;
dashboard?: DashboardType;
dashboard?: AppConfigSlug;
selectedSite: Maybe< SiteDetails >;
setPage: ( page: PossibleSlugs ) => void;
};
Expand Down
1 change: 1 addition & 0 deletions client/dashboard/app-ciab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
import './style.scss';

boot( {
slug: 'ciab',
name: 'CIAB',
basePath: '/ciab',
mainRoute: '/sites',
Expand Down
1 change: 1 addition & 0 deletions client/dashboard/app-dotcom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
import './style.scss';

boot( {
slug: 'dotcom',
name: 'WordPress.com',
basePath: '/',
mainRoute: '/sites',
Expand Down
4 changes: 4 additions & 0 deletions client/dashboard/app/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export type MeSupports = {
apps: boolean;
};

export type AppConfigSlug = 'dotcom' | 'ciab' | '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove the empty string and make dotcom the default?


export type AppConfig = {
slug: AppConfigSlug;
name: string;
basePath: string;
mainRoute: string;
Expand Down Expand Up @@ -59,6 +62,7 @@ export type AppConfig = {
};

export const APP_CONTEXT_DEFAULT_CONFIG: AppConfig = {
slug: '',
name: '',
basePath: '',
mainRoute: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { wpcomLink } from '../../utils/link';
export default function EmptyDomainsState() {
return (
<EmptyDomainsStateLayout
dashboard="ciab"
searchDomainNameLink={ wpcomLink( '/setup/domain' ) }
bringDomainNameTitle={ __( 'Use a domain name you already own' ) }
bringDomainNameDescription={ __(
Expand Down
1 change: 0 additions & 1 deletion client/dashboard/domains/empty-domains-state/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import EmptyDomainsStateLayout from './layout';
export default function EmptyDomainsState() {
return (
<EmptyDomainsStateLayout
dashboard="msd"
searchDomainNameLink={ wpcomLink( '/start/domain' ) }
bringDomainNameTitle={ __( 'Transfer a domain you already own' ) }
bringDomainNameDescription={ __(
Expand Down
11 changes: 5 additions & 6 deletions client/dashboard/domains/empty-domains-state/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import { __ } from '@wordpress/i18n';
import { Icon, search, globe } from '@wordpress/icons';
import { addQueryArgs } from '@wordpress/url';
import { useAnalytics } from '../../app/analytics';
import { useAppContext } from '../../app/context';
import EmptyState from '../../components/empty-state';
import OfferCard from '../../components/offer-card';
import { type DashboardType } from '../../utils/link';

interface EmptyDomainsStateLayoutProps {
searchDomainNameLink: string;
bringDomainNameTitle: string;
bringDomainNameDescription: string;
bringDomainNameLink: string;
bringDomainNameCTA: string;
dashboard: DashboardType;
}

export default function EmptyDomainsStateLayout( {
Expand All @@ -22,14 +21,14 @@ export default function EmptyDomainsStateLayout( {
bringDomainNameDescription,
bringDomainNameLink,
bringDomainNameCTA,
dashboard,
}: EmptyDomainsStateLayoutProps ) {
const { recordTracksEvent } = useAnalytics();
const { slug } = useAppContext();

const trackEmptyStateActionClick = ( action: string ) => {
recordTracksEvent( 'calypso_domains_dashboard_empty_state_action_click', {
action,
dashboard,
dashboard: slug,
} );
};

Expand Down Expand Up @@ -63,7 +62,7 @@ export default function EmptyDomainsStateLayout( {
actions={
<Button
variant="secondary"
href={ addQueryArgs( searchDomainNameLink, { dashboard } ) }
href={ addQueryArgs( searchDomainNameLink, { dashboard: slug } ) }
onClick={ handleSearchDomainsClick }
size="compact"
__next40pxDefaultSize
Expand All @@ -79,7 +78,7 @@ export default function EmptyDomainsStateLayout( {
actions={
<Button
variant="secondary"
href={ addQueryArgs( bringDomainNameLink, { dashboard } ) }
href={ addQueryArgs( bringDomainNameLink, { dashboard: slug } ) }
onClick={ handleTransferDomainClick }
size="compact"
__next40pxDefaultSize
Expand Down
23 changes: 10 additions & 13 deletions client/dashboard/utils/link.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import config from '@automattic/calypso-config';
import { isDashboardBackport } from './is-dashboard-backport';
import type { AppConfigSlug } from '../app/context';

/**
* This function returns all the origins for the dashboard.
Expand Down Expand Up @@ -32,17 +33,11 @@ export function a4aLink( path: string ) {
return new URL( path, 'https://agencies.automattic.com' ).href;
}

/**
* Dashboard type identifier.
* undefined represents the default (main MSD dashboard).
*/
export type DashboardType = 'ciab' | 'msd';

/**
* Returns the dashboard type from a string.
*/
export function getDashboardFromString( dashboard?: string ): DashboardType | null {
if ( dashboard === 'ciab' || dashboard === 'msd' ) {
export function getDashboardFromString( dashboard?: string ): AppConfigSlug | null {
if ( dashboard === 'ciab' || dashboard === 'dotcom' ) {
return dashboard;
}

Expand All @@ -53,7 +48,7 @@ export function getDashboardFromString( dashboard?: string ): DashboardType | nu
* Returns the dashboard type from URL query params.
* Used when in Stepper to know which dashboard the user came from.
*/
function getDashboardFromQuery(): DashboardType | null {
function getDashboardFromQuery(): AppConfigSlug | null {
const params = new URLSearchParams( window.location.search );
const dashboard = params.get( 'dashboard' );
if ( dashboard === 'ciab' ) {
Expand All @@ -67,7 +62,7 @@ function getDashboardFromQuery(): DashboardType | null {
* Only detects ciab (which has a distinctive /ciab prefix).
* Returns null for all other paths, falling through to default.
*/
function getDashboardFromPath(): DashboardType | null {
function getDashboardFromPath(): AppConfigSlug | null {
if ( window.location.pathname.startsWith( '/ciab' ) ) {
return 'ciab';
}
Expand All @@ -78,7 +73,7 @@ function getDashboardFromPath(): DashboardType | null {
* Returns the dashboard type from the referrer.
* Fallback when query param and path don't indicate dashboard.
*/
function getDashboardFromReferrer(): DashboardType | null {
function getDashboardFromReferrer(): AppConfigSlug | null {
if ( ! document.referrer ) {
return null;
}
Expand All @@ -97,8 +92,10 @@ function getDashboardFromReferrer(): DashboardType | null {
* Detects the current dashboard context.
* Priority: query param → current path → referrer → defaults to MSD
*/
export function getCurrentDashboard(): DashboardType {
return getDashboardFromQuery() ?? getDashboardFromPath() ?? getDashboardFromReferrer() ?? 'msd';
export function getCurrentDashboard(): AppConfigSlug {
return (
getDashboardFromQuery() ?? getDashboardFromPath() ?? getDashboardFromReferrer() ?? 'dotcom'
);
}

/**
Expand Down