import { localizeUrl, useLocale, getRelativeTimeString } from '@automattic/i18n-utils'; import { ExternalLink } from '@wordpress/components'; import { createInterpolateElement } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import { Icon, info } from '@wordpress/icons'; import type { AnalysisReport, SupportActivity } from '../types'; import type { ReactNode } from 'react'; import './help-center-notice.scss'; type Props = { ownershipResult: AnalysisReport | null; }; function getResponses( siteName?: string ) { const responses: Record< AnalysisReport[ 'result' ], React.ReactElement | string > = { NOT_OWNED_BY_USER: (
{ sprintf(
/* translators: %s is site name (eg myblog.com) */
__(
'%s is linked to another WordPress.com account. If you’re trying to access it, please follow our Account Recovery procedure.',
__i18n_text_domain__
),
siteName
) }
{ ' ' }
{ createInterpolateElement(
__(
'Your site is not
{ __( "We couldn't fetch enough information about this site to determine our ability to support you with it.", __i18n_text_domain__ ) }
), OWNED_BY_USER: '', DISABLED: '', LOADING: '', }; return responses; } function tryGetHost( url: string | undefined ) { if ( ! url ) { return null; } try { return new URL( url ).host; } catch { return url; } } export function HelpCenterOwnershipNotice( { ownershipResult }: Props ) { if ( ! ownershipResult ) { return null; } if ( ownershipResult.result === 'OWNED_BY_USER' ) { return ({ ownershipResult.site?.name || ownershipResult.siteURL }
); } const responses = getResponses( tryGetHost( ownershipResult.site?.URL ) || ownershipResult.siteURL ); if ( responses[ ownershipResult.result ] ) { return{ sprintf( /* translators: %s humanized date ex: 2 hours ago */ __( 'You submitted a request %s.', __i18n_text_domain__ ), getRelativeTimeString( { timestamp: tickets[ 0 ].timestamp * 1000, locale, style: 'long', } ) ) } { ' ' } { __( "Rest assured that we got your message and we'll be in touch as soon as we can.", __i18n_text_domain__ ) }