diff --git a/packages/gitbook/src/components/SitePage/SitePageNotFound.tsx b/packages/gitbook/src/components/SitePage/SitePageNotFound.tsx index d6796c36e..01b2318ba 100644 --- a/packages/gitbook/src/components/SitePage/SitePageNotFound.tsx +++ b/packages/gitbook/src/components/SitePage/SitePageNotFound.tsx @@ -46,11 +46,7 @@ export function SitePageNotFound() { const { assistants } = useAI(); const isAuthenticated = isVisitorAuthenticated(visitorAuthClaims); - const [titleKey, messageKey] = !adaptiveAuthLoginHref - ? (['notfound_title', 'notfound'] as const) - : isAuthenticated - ? (['notfound_adaptive_no_access_title', 'notfound_adaptive_no_access'] as const) - : (['notfound_adaptive_title', 'notfound_adaptive'] as const); + const copy = getNotFoundCopy({ hasAdaptiveLogin: !!adaptiveAuthLoginHref, isAuthenticated }); // Show the assistant input when a non-search assistant is available (i.e. not just ask-AI). const assistant = assistants.find((candidate) => candidate.mode !== 'search') ?? null; @@ -132,10 +128,10 @@ export function SitePageNotFound() { 'text-tint-strong' )} > - {t(language, titleKey)} + {t(language, copy.title)}
- {t(language, messageKey)} + {t(language, copy.message)}
{adaptiveAuthLoginHref && isAuthenticated ? ( @@ -197,6 +193,19 @@ export function SitePageNotFound() { ); } +function getNotFoundCopy(args: { hasAdaptiveLogin: boolean; isAuthenticated: boolean }) { + if (!args.hasAdaptiveLogin) { + return { title: 'notfound_title', message: 'notfound' } as const; + } + if (args.isAuthenticated) { + return { + title: 'notfound_adaptive_no_access_title', + message: 'notfound_adaptive_no_access', + } as const; + } + return { title: 'notfound_adaptive_title', message: 'notfound_adaptive' } as const; +} + /** * List of related pages, with skeleton rows while they load. Renders nothing once we know * there are no suggestions.