1
1
import { ExternalLink } from '@automattic/components' ;
2
+ import { HelpCenter } from '@automattic/data-stores' ;
3
+ import { localizeUrl } from '@automattic/i18n-utils' ;
4
+ import { dispatch as dataStoreDispatch } from '@wordpress/data' ;
2
5
import { useTranslate } from 'i18n-calypso' ;
3
6
import PropTypes from 'prop-types' ;
4
7
import InfoPopover from 'calypso/components/info-popover' ;
5
8
6
9
import './style.scss' ;
7
10
11
+ const HELP_CENTER_STORE = HelpCenter . register ( ) ;
12
+
8
13
function makePrivacyLink ( privacyLink = true , link = '' ) {
9
14
if ( privacyLink ) {
10
15
if ( typeof privacyLink === 'string' ) {
@@ -24,10 +29,23 @@ function SupportInfo( {
24
29
position = 'left' ,
25
30
privacyLink,
26
31
popoverClassName = '' ,
32
+ supportPostId,
33
+ supportBlogId,
27
34
} ) {
28
35
const translate = useTranslate ( ) ;
29
36
const filteredPrivacyLink = makePrivacyLink ( privacyLink , link ) ;
30
37
38
+ const handleLinkClick = ( event , url ) => {
39
+ if ( supportPostId ) {
40
+ event . preventDefault ( ) ;
41
+ dataStoreDispatch ( HELP_CENTER_STORE ) . setShowSupportDoc ( url , supportPostId , supportBlogId ) ;
42
+ }
43
+ // If no supportPostId, let the link open normally in a new tab
44
+ } ;
45
+
46
+ const LinkComponent = supportPostId ? 'a' : ExternalLink ;
47
+ const linkUrl = supportPostId ? localizeUrl ( link ) : link ;
48
+
31
49
return (
32
50
< div className = "support-info" >
33
51
< InfoPopover
@@ -40,9 +58,13 @@ function SupportInfo( {
40
58
{ link || filteredPrivacyLink ? ' ' : null }
41
59
{ link && (
42
60
< span className = "support-info__learn-more" >
43
- < ExternalLink href = { link } target = "_blank" >
61
+ < LinkComponent
62
+ href = { linkUrl }
63
+ target = { supportPostId ? undefined : '_blank' }
64
+ onClick = { ( event ) => handleLinkClick ( event , linkUrl ) }
65
+ >
44
66
{ translate ( 'Learn more' ) }
45
- </ ExternalLink >
67
+ </ LinkComponent >
46
68
</ span >
47
69
) }
48
70
{ filteredPrivacyLink && (
@@ -63,6 +85,9 @@ SupportInfo.propTypes = {
63
85
link : PropTypes . string ,
64
86
position : PropTypes . string ,
65
87
privacyLink : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . bool ] ) ,
88
+ popoverClassName : PropTypes . string ,
89
+ supportPostId : PropTypes . number ,
90
+ supportBlogId : PropTypes . number ,
66
91
} ;
67
92
68
93
export default SupportInfo ;
0 commit comments