File size: 895 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
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'calypso/state';
import getIntroOfferRequestStatus from 'calypso/state/selectors/get-intro-offers-request-status';
import { fetchIntroOffers } from 'calypso/state/sites/intro-offers/actions';

interface OwnProps {
	siteId?: number | 'none';
	currency?: string;
}

const QueryIntroOffers: React.FC< OwnProps > = ( { siteId, currency } ) => {
	const dispatch = useDispatch();
	const siteIdKey = siteId && typeof siteId === 'number' && siteId > 0 ? siteId : 'none';

	const introOfferRequestStatus = useSelector( ( state ) =>
		getIntroOfferRequestStatus( state, siteIdKey )
	);

	useEffect( () => {
		if ( introOfferRequestStatus === null ) {
			dispatch( fetchIntroOffers( siteIdKey, currency ) );
		}
	}, [ dispatch, introOfferRequestStatus, siteIdKey, currency ] );

	return null;
};

export default QueryIntroOffers;