File size: 1,830 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
import { Reader, SubscriptionManager } from '@automattic/data-stores';
import Banner from 'calypso/components/banner';
import { navigate } from 'calypso/lib/navigate';
import { useSelector } from 'calypso/state';
import { isA8cTeamMember } from 'calypso/state/teams/selectors';

const CUSTOMER_COUNCIL_P2_URL = 'https://readercouncilgeneral.wordpress.com/';
const CUSTOMER_COUNCIL_P2_ID = '237686330';

export const CustomerCouncilBanner = ( { translate } ) => {
	const { mutate: subscribe, isIdle: notActivelySubscribing } =
		SubscriptionManager.useSiteSubscribeMutation();

	const {
		data: p2,
		isFetched: checkedAlreadySubscribed,
		isFetching: checkingAlreadySubscribed,
	} = Reader.useReadFeedSiteQuery( Number( CUSTOMER_COUNCIL_P2_ID ) );
	const alreadySubscribed = p2?.is_following;

	const isAutomattician = useSelector( isA8cTeamMember );

	const hideBanner =
		isAutomattician ||
		( alreadySubscribed && checkedAlreadySubscribed ) ||
		checkingAlreadySubscribed;

	if ( hideBanner ) {
		return null;
	}

	const subscribeToP2AndNavigate = () => {
		subscribe(
			{ blog_id: CUSTOMER_COUNCIL_P2_ID, url: CUSTOMER_COUNCIL_P2_URL },
			{
				onSettled: () => {
					navigate( CUSTOMER_COUNCIL_P2_URL );
				},
			}
		);
	};

	return (
		<Banner
			horizontal
			callToAction={
				notActivelySubscribing ? translate( 'Subscribe' ) : `${ translate( 'Subscribing' ) }...`
			}
			disableHref
			dismissPreferenceName="reader-council-banner"
			dismissTemporary
			title={ translate( 'Want to shape the future of the WordPress.com Reader?' ) }
			onClick={ subscribeToP2AndNavigate }
			description={ translate(
				'Join {{a}}our new blog{{/a}} to share your feedback and help us improve your reading experience.',
				{
					components: {
						a: <a href={ CUSTOMER_COUNCIL_P2_URL } />,
					},
				}
			) }
		/>
	);
};