File size: 2,166 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 { useTranslate } from 'i18n-calypso';
import { useEffect } from 'react';
import { useQueryJetpackPartnerPortalPartner } from 'calypso/components/data/query-jetpack-partner-portal-partner';
import JetpackLogo from 'calypso/components/jetpack-logo';
import SidebarNavigation from 'calypso/components/sidebar-navigation';
import SelectPartnerKey from 'calypso/jetpack-cloud/sections/partner-portal/primary/select-partner-key';
import PluginsMain from 'calypso/my-sites/plugins/main';
import PluginDetails from 'calypso/my-sites/plugins/plugin-details';
import { useDispatch, useSelector } from 'calypso/state';
import {
	hasActivePartnerKey,
	hasFetchedPartner,
	isFetchingPartner,
} from 'calypso/state/partner-portal/partner/selectors';
import { setSelectedSiteId } from 'calypso/state/ui/actions';

import './style.scss';

interface Props {
	filter?: string;
	search?: string;
	site?: string;
	pluginSlug?: string;
	path?: string;
}

export default function PluginsOverview( { filter, search, site, pluginSlug, path }: Props ) {
	const dispatch = useDispatch();
	const translate = useTranslate();

	const hasFetched = useSelector( hasFetchedPartner );
	const isFetching = useSelector( isFetchingPartner );
	const hasActiveKey = useSelector( hasActivePartnerKey );

	// Reset selected site id for multi-site view since it is never reset
	// and the <PluginsMain /> component behaves differently when there
	// is a selected site which is incorrect for multi-site view
	useEffect( () => {
		if ( ! site ) {
			dispatch( setSelectedSiteId( null ) );
		}
	}, [ dispatch, site ] );

	useQueryJetpackPartnerPortalPartner();

	if ( hasFetched && ! hasActiveKey ) {
		return <SelectPartnerKey />;
	}

	if ( hasFetched ) {
		return (
			<div className="plugins-overview__container">
				<SidebarNavigation sectionTitle={ translate( 'Plugins' ) } />
				{ pluginSlug ? (
					<PluginDetails isJetpackCloud siteUrl={ site } pluginSlug={ pluginSlug } path={ path } />
				) : (
					<PluginsMain isJetpackCloud filter={ filter } search={ search } />
				) }
			</div>
		);
	}

	return isFetching ? <JetpackLogo className="plugins-overview__logo" size={ 72 } /> : null;
}