import { isEnabled } from '@automattic/calypso-config';
import { Button, ProgressBar, Gridicon, Card } from '@automattic/components';
import clsx from 'clsx';
import { translate } from 'i18n-calypso';
import { Component } from 'react';
import { connect } from 'react-redux';
import JetpackReviewPrompt from 'calypso/blocks/jetpack-review-prompt';
import TimeMismatchWarning from 'calypso/blocks/time-mismatch-warning';
import DocumentHead from 'calypso/components/data/document-head';
import QueryJetpackScan from 'calypso/components/data/query-jetpack-scan';
import ScanPlaceholder from 'calypso/components/jetpack/scan-placeholder';
import ScanThreats from 'calypso/components/jetpack/scan-threats';
import SecurityIcon from 'calypso/components/jetpack/security-icon';
import { withLocalizedMoment } from 'calypso/components/localized-moment';
import Main from 'calypso/components/main';
import NavigationHeader from 'calypso/components/navigation-header';
import SidebarNavigation from 'calypso/components/sidebar-navigation';
import { withApplySiteOffset, applySiteOffsetType } from 'calypso/components/site-offset';
import isA8CForAgencies from 'calypso/lib/a8c-for-agencies/is-a8c-for-agencies';
import PageViewTracker from 'calypso/lib/analytics/page-view-tracker';
import contactSupportUrl from 'calypso/lib/jetpack/contact-support-url';
import isJetpackCloud from 'calypso/lib/jetpack/is-jetpack-cloud';
import { triggerScanRun } from 'calypso/lib/jetpack/trigger-scan-run';
import { Scan, Site } from 'calypso/my-sites/scan/types';
import { recordTracksEvent } from 'calypso/state/analytics/actions';
import { setValidFrom } from 'calypso/state/jetpack-review-prompt/actions';
import { incrementCounter } from 'calypso/state/persistent-counter/actions';
import { getCount } from 'calypso/state/persistent-counter/selectors';
import getSettingsUrl from 'calypso/state/selectors/get-settings-url';
import getSiteScanIsInitial from 'calypso/state/selectors/get-site-scan-is-initial';
import getSiteScanProgress from 'calypso/state/selectors/get-site-scan-progress';
import getSiteScanRequestStatus from 'calypso/state/selectors/get-site-scan-request-status';
import getSiteScanState from 'calypso/state/selectors/get-site-scan-state';
import isRequestingJetpackScan from 'calypso/state/selectors/is-requesting-jetpack-scan';
import getSiteUrl from 'calypso/state/sites/selectors/get-site-url';
import { IAppState } from 'calypso/state/types';
import { getSelectedSite, getSelectedSiteId } from 'calypso/state/ui/selectors';
import ScanNavigation from './navigation';
import type { TranslateResult } from 'i18n-calypso';
import type { utc } from 'moment';
import './style.scss';
interface Props {
site: Site | null;
siteId: number | null;
siteSlug: string | null;
siteUrl?: string;
scanState?: Scan;
scanProgress?: number;
isInitialScan?: boolean;
isRequestingScan?: boolean;
scanPageVisitCount?: number;
scanRequestStatus?: 'pending' | 'success' | 'failed';
timezone: string | null;
gmtOffset: number | null;
moment: {
utc: typeof utc;
};
applySiteOffset: applySiteOffsetType | null;
dispatchRecordTracksEvent: typeof recordTracksEvent;
dispatchScanRun: ( arg0: number ) => void;
dispatchIncrementCounter: ( arg0: string, arg1: boolean, arg2: boolean ) => void;
dispatchSetReviewPromptValid: ( arg0: 'restore' | 'scan', arg1: number | null ) => void;
isAdmin: boolean;
siteSettingsUrl?: string | null;
}
const SCAN_VISIT_COUNTER_NAME = 'scan-page-visit';
class ScanPage extends Component< Props > {
componentDidMount() {
const { scanState, dispatchIncrementCounter } = this.props;
if ( scanState?.state && scanState?.state !== 'unavailable' ) {
// Counting visits to the scan page for the Jetpack (Scan) Review Prompt.
// Review Prompt should appear after 3 visits (not including same day visits)
dispatchIncrementCounter( SCAN_VISIT_COUNTER_NAME, false, false );
}
}
componentDidUpdate( prevProps: Props ) {
if ( prevProps.scanPageVisitCount !== this.props.scanPageVisitCount ) {
// After 3 Scan page visits, trigger the Jetpack Review Prompt.
if ( this.props.scanPageVisitCount === 3 ) {
this.props.dispatchSetReviewPromptValid( 'scan', Date.now() );
}
}
}
renderProvisioning() {
return (
<>
{ translate( "Welcome to Jetpack Scan! We're scoping out your site, setting up to do a full scan. " + "We'll let you know if we spot any issues that might impact a scan, " + 'then your first full scan will start.' ) }
> ); } renderHeader( text: TranslateResult ) { return
{ translate(
/* translators: %s is a time string relative to now */
'The last Jetpack scan ran {{strong}}%s{{/strong}} and everything ' +
'looked great.' +
'{{br/}}' +
'Run a manual scan now or wait for Jetpack to scan your site later today.',
{
args: [ lastScanFinishTime ],
components: {
strong: ,
br:
,
},
}
) }
{ translate( 'Welcome to Jetpack Scan. We are starting your first scan now. ' + 'Scan results will be ready soon.' ) }
) }{ scanProgress }%
{ translate(
'{{strong}}Did you know{{/strong}} {{br/}}' +
'We will send you an email if security threats are found. In the meantime feel ' +
'free to continue to use your site as normal, you can check back on ' +
'progress at any time.',
{
components: {
strong: ,
br:
,
},
}
) }
{ translate( "Jetpack Scan couldn't complete a scan of your site. Please check to see if your site is down " + "– if it's not, try again. If it is, or if Jetpack Scan is still having problems, contact our support team." ) }
{ this.renderContactSupportButton() } > ); } renderScanState() { const { site, scanState, isRequestingScan, scanRequestStatus } = this.props; // Show the loading placeholder until we have a site to work with. if ( ! site ) { return