File size: 1,795 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
import { recordTracksEvent } from '@automattic/calypso-analytics';
import page from '@automattic/calypso-router';
import { Card, Button } from '@automattic/components';
import { useCallback } from 'react';
import { useSelector } from 'react-redux';
import QueryJetpackPlugins from 'calypso/components/data/query-jetpack-plugins';
import FormattedHeader from 'calypso/components/formatted-header';
import TrackComponentView from 'calypso/lib/analytics/track-component-view';
import { getPluginOnSite, isRequestingForSites } from 'calypso/state/plugins/installed/selectors';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';

import './style.scss';

const PromoCardBlock = ( {
	clickEvent,
	contentText,
	ctaText,
	headerText,
	href,
	image,
	impressionEvent,
	productSlug,
} ) => {
	const selectedSiteId = useSelector( getSelectedSiteId );
	const selectedPlugin = useSelector( ( state ) =>
		getPluginOnSite( state, selectedSiteId, productSlug )
	);
	const isFetching = useSelector( ( state ) => isRequestingForSites( state, [ selectedSiteId ] ) );

	const onClick = useCallback( () => {
		recordTracksEvent( clickEvent );
		page( href );
	}, [ clickEvent, href ] );

	return (
		<>
			<QueryJetpackPlugins siteIds={ [ selectedSiteId ] } />
			{ selectedPlugin || isFetching ? (
				<div></div>
			) : (
				<>
					<TrackComponentView eventName={ impressionEvent } />

					<Card className="promo-card-block">
						<img src={ image } alt="" />
						<div className="promo-card-block__text">
							<FormattedHeader brandFont headerText={ headerText } align="left" />
							<p>{ contentText }</p>
							<Button primary onClick={ onClick } target="_blank">
								{ ctaText }
							</Button>
						</div>
					</Card>
				</>
			) }
		</>
	);
};

export default PromoCardBlock;