Skip to content

Commit 37235ee

Browse files
authored
Emails: redirect the no-domain email home to the MSD (#113346)
A site with no custom domain renders EmailNoDomain ("Get your own domain for a custom email address") and returns before the single-domain branch that #113314 redirects, so the titan-tiers flag had no effect on that page. Compute a redirect path rather than a domain name so both branches are covered. The no-domain case targets the emails index, whose EmptyDomainsState is the dashboard equivalent of EmailNoDomain; there is no domain to build a choose-email-solution URL from.
1 parent 48234d0 commit 37235ee

1 file changed

Lines changed: 18 additions & 13 deletions

File tree

client/my-sites/email/email-management/email-home.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,30 @@ const EmailHome = ( props: EmailManagementHomeProps ) => {
131131
// first render can run on stale data. Waiting for the refetch to settle
132132
// avoids sending someone who already bought email off to a purchase page,
133133
// which a cross-origin navigation would make unrecoverable.
134-
const redirectDomainName =
134+
const canRedirectToDashboard =
135135
isEnabled( 'emails/titan-tiers' ) &&
136136
! selectedDomainName &&
137137
! isSiteDomainLoading &&
138-
! isSiteDomainFetching &&
139-
domainsWithEmail.length < 1 &&
140-
domainsWithNoEmail.length === 1
141-
? domainsWithNoEmail[ 0 ].name
142-
: undefined;
138+
! isSiteDomainFetching;
139+
140+
let dashboardRedirectPath: string | undefined;
141+
if ( canRedirectToDashboard ) {
142+
if ( nonWpcomDomains.length < 1 ) {
143+
// No custom domain to buy email for, so land on the emails index,
144+
// which prompts for a domain first.
145+
dashboardRedirectPath = '/emails';
146+
} else if ( domainsWithEmail.length < 1 && domainsWithNoEmail.length === 1 ) {
147+
dashboardRedirectPath = `/emails/choose-email-solution/${ encodeURIComponent(
148+
domainsWithNoEmail[ 0 ].name
149+
) }`;
150+
}
151+
}
143152

144153
useEffect( () => {
145-
if ( redirectDomainName ) {
146-
navigate(
147-
dashboardLink(
148-
`/emails/choose-email-solution/${ encodeURIComponent( redirectDomainName ) }`
149-
)
150-
);
154+
if ( dashboardRedirectPath ) {
155+
navigate( dashboardLink( dashboardRedirectPath ) );
151156
}
152-
}, [ redirectDomainName ] );
157+
}, [ dashboardRedirectPath ] );
153158

154159
if ( isSiteDomainLoading || ! hasSitesLoaded || ! selectedSite || ! domains ) {
155160
return (

0 commit comments

Comments
 (0)