-
Notifications
You must be signed in to change notification settings - Fork 862
Expand file tree
/
Copy pathindex.jsx
More file actions
102 lines (95 loc) · 2.79 KB
/
index.jsx
File metadata and controls
102 lines (95 loc) · 2.79 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import {
AdminPage as JetpackAdminPage,
Button,
Container,
getRedirectUrl,
JetpackProtectLogo,
} from '@automattic/jetpack-components';
import { useConnection } from '@automattic/jetpack-connection';
import { __, sprintf } from '@wordpress/i18n';
import { useEffect } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import useNotices from '../../hooks/use-notices';
import usePlan from '../../hooks/use-plan';
import useProtectData from '../../hooks/use-protect-data';
import useWafData from '../../hooks/use-waf-data';
import Notice from '../notice';
import ScanButton from '../scan-button';
import Tabs, { Tab } from '../tabs';
import styles from './styles.module.scss';
const AdminPage = ( { children } ) => {
const { notice } = useNotices();
const { isRegistered } = useConnection();
const { isSeen: wafSeen } = useWafData();
const navigate = useNavigate();
const {
counts: {
current: { threats: numThreats },
},
} = useProtectData();
const location = useLocation();
const { hasPlan } = usePlan();
// Redirect to the setup page if the site is not registered.
useEffect( () => {
if ( ! isRegistered ) {
navigate( '/setup' );
}
}, [ isRegistered, navigate ] );
if ( ! isRegistered ) {
return null;
}
const viewingScanPage = location.pathname.includes( '/scan' );
const { siteSuffix, blogID } = window.jetpackProtectInitialState || {};
const goToCloudUrl = getRedirectUrl( 'jetpack-scan-dash', { site: blogID ?? siteSuffix } );
return (
<JetpackAdminPage
moduleName={ __( 'Jetpack Protect', 'jetpack-protect' ) }
header={
<div className={ styles.header }>
<JetpackProtectLogo />
{ hasPlan && viewingScanPage && (
<div className={ styles.header__scan_buttons }>
<Button variant="link" isExternalLink weight={ 'regular' } href={ goToCloudUrl }>
{ __( 'Go to Cloud', 'jetpack-protect' ) }
</Button>
<ScanButton />
</div>
) }
</div>
}
>
{ notice && <Notice floating={ true } dismissable={ true } { ...notice } /> }
<Container horizontalSpacing={ 0 }>
<Tabs className={ styles.navigation }>
<Tab
link="/scan"
label={
<span className={ styles.tab }>
{ numThreats > 0
? sprintf(
// translators: %d is the number of threats found.
__( 'Scan (%d)', 'jetpack-protect' ),
numThreats
)
: __( 'Scan', 'jetpack-protect' ) }
</span>
}
/>
<Tab
link="/firewall"
label={
<>
{ __( 'Firewall', 'jetpack-protect' ) }
{ wafSeen === false && (
<span className={ styles.badge }>{ __( 'New', 'jetpack-protect' ) }</span>
) }
</>
}
/>
</Tabs>
</Container>
{ children }
</JetpackAdminPage>
);
};
export default AdminPage;