File size: 4,231 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | 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: (
<p>
{ 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
) }
{ ' ' }
<ExternalLink href={ localizeUrl( 'https://wordpress.com/wp-login.php?action=recovery' ) }>
{ __( 'Learn More', __i18n_text_domain__ ) }
</ExternalLink>
</p>
),
WPORG: (
<p>
{ createInterpolateElement(
__(
'Your site is not <hosted_on_our_services>hosted with our services</hosted_on_our_services>. Support for the self-hosted version of WordPress is provided by the <wordpress_org_community_forums>WordPress.org community forums</wordpress_org_community_forums>, or if the problem relates to a specific plugin or theme, contact support for that product instead. If you’re not sure, share your question with a link, and we’ll point you in the right direction!',
__i18n_text_domain__
),
{
hosted_on_our_services: (
// @ts-expect-error Children must be passed to External link. This is done by createInterpolateElement, but the types don't see that.
<ExternalLink href={ localizeUrl( 'https://wordpress.com/support/com-vs-org/' ) } />
),
wordpress_org_community_forums: (
// @ts-expect-error Children must be passed to External link. This is done by createInterpolateElement, but the types don't see that.
<ExternalLink href={ localizeUrl( 'https://wordpress.org/support/forums/' ) } />
),
}
) }
</p>
),
UNKNOWN: (
<p>
{ __(
"We couldn't fetch enough information about this site to determine our ability to support you with it.",
__i18n_text_domain__
) }
</p>
),
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 (
<p className="help-center-notice__positive-feedback">
{ ownershipResult.site?.name || ownershipResult.siteURL }
</p>
);
}
const responses = getResponses(
tryGetHost( ownershipResult.site?.URL ) || ownershipResult.siteURL
);
if ( responses[ ownershipResult.result ] ) {
return <HelpCenterNotice>{ responses[ ownershipResult.result ] }</HelpCenterNotice>;
}
return null;
}
export function HelpCenterActiveTicketNotice( {
tickets,
}: {
tickets: SupportActivity[] | undefined;
} ) {
const locale = useLocale();
if ( ! tickets || ! tickets.length ) {
return null;
}
return (
<HelpCenterNotice>
<p>
<strong>
{ 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',
} )
) }
</strong>{ ' ' }
{ __(
"Rest assured that we got your message and we'll be in touch as soon as we can.",
__i18n_text_domain__
) }
</p>
</HelpCenterNotice>
);
}
export function HelpCenterNotice( { children }: { children: ReactNode } ) {
return (
<div className="help-center-notice__container">
<div>
<Icon icon={ info } className="info-icon"></Icon>
</div>
{ children }
</div>
);
}
|