<commit_before>/**
 * SetupUsingProxyWithSignIn component.
 *
 * Site Kit by Google, Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * External dependencies
 */
import punycode from 'punycode';

/**
 * WordPress dependencies
 */
import { Fragment, useCallback } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { getQueryArg, addQueryArgs } from '@wordpress/url';

/**
 * Internal dependencies
 */
import Data from 'googlesitekit-data';
import { VIEW_CONTEXT_DASHBOARD_SPLASH } from '../../googlesitekit/constants';
import WelcomeSVG from '../../../svg/graphics/welcome.svg';
import WelcomeAnalyticsSVG from '../../../svg/graphics/welcome-analytics.svg';
import { trackEvent, untrailingslashit } from '../../util';
import Header from '../Header';
import Button from '../Button';
import ResetButton from '../ResetButton';
import Layout from '../layout/Layout';
import BannerNotification from '../notifications/BannerNotification';
import OptIn from '../OptIn';
import CompatibilityChecks from './CompatibilityChecks';
import { CORE_SITE } from '../../googlesitekit/datastore/site/constants';
import {
	CORE_USER,
	DISCONNECTED_REASON_CONNECTED_URL_MISMATCH,
	PERMISSION_VIEW_SHARED_DASHBOARD,
} from '../../googlesitekit/datastore/user/constants';
import { CORE_LOCATION } from '../../googlesitekit/datastore/location/constants';
import { CORE_MODULES } from '../../googlesitekit/modules/datastore/constants';
import { CORE_FORMS } from '../../googlesitekit/datastore/forms/constants';
import { Grid, Row, Cell } from '../../material-components';
import {
	ANALYTICS_NOTICE_FORM_NAME,
	ANALYTICS_NOTICE_CHECKBOX,
	SHARED_DASHBOARD_SPLASH_ITEM_KEY,
} from './constants';
import HelpMenu from '../help/HelpMenu';
import ActivateAnalyticsNotice from './ActivateAnalyticsNotice';
import { useFeature } from '../../hooks/useFeature';
import Link from '../Link';
const { useSelect, useDispatch } = Data;

export default function SetupUsingProxyWithSignIn() {
	const dashboardSharingEnabled = useFeature( 'dashboardSharing' );

	const analyticsModuleActive = useSelect( ( select ) =>
		select( CORE_MODULES ).isModuleActive( 'analytics' )
	);
	const connectAnalytics = useSelect( ( select ) =>
		select( CORE_FORMS ).getValue(
			ANALYTICS_NOTICE_FORM_NAME,
			ANALYTICS_NOTICE_CHECKBOX
		)
	);
	const {
		isSecondAdmin,
		isResettable,
		siteURL,
		proxySetupURL,
		disconnectedReason,
		isConnected,
		connectedProxyURL,
		homeURL,
	} = useSelect( ( select ) => {
		const site = select( CORE_SITE );
		const user = select( CORE_USER );

		return {
			isSecondAdmin: site.hasConnectedAdmins(),
			isResettable: site.isResettable(),
			siteURL: site.getReferenceSiteURL(),
			proxySetupURL: site.getProxySetupURL(),
			disconnectedReason: user.getDisconnectedReason(),
			connectedProxyURL: untrailingslashit( user.getConnectedProxyURL() ),
			homeURL: untrailingslashit( site.getHomeURL() ),
			isConnected: site.isConnected(),
		};
	} );

	const dashboardURL = useSelect( ( select ) =>
		select( CORE_SITE ).getAdminURL( 'googlesitekit-dashboard' )
	);

	const canViewSharedDashboard = useSelect( ( select ) =>
		select( CORE_USER ).hasCapability( PERMISSION_VIEW_SHARED_DASHBOARD )
	);

	const { dismissItem } = useDispatch( CORE_USER );

	const goToSharedDashboard = useCallback( () => {
		dismissItem( SHARED_DASHBOARD_SPLASH_ITEM_KEY );

		global.location = dashboardURL;
	}, [ dashboardURL, dismissItem ] );

	const { navigateTo } = useDispatch( CORE_LOCATION );
	const { activateModule } = useDispatch( CORE_MODULES );

	const onButtonClick = useCallback(
		async ( event ) => {
			event.preventDefault();

			let moduleReauthURL;

			if ( connectAnalytics ) {
				const { error, response } = await activateModule( 'analytics' );

				if ( ! error ) {
					await trackEvent(
						VIEW_CONTEXT_DASHBOARD_SPLASH,
						'start_setup_with_analytics'
					);
<commit_msg>Use navigateTo instead of location =.<commit_after>/**
 * SetupUsingProxyWithSignIn component.
 *
 * Site Kit by Google, Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * External dependencies
 */
import punycode from 'punycode';

/**
 * WordPress dependencies
 */
import { Fragment, useCallback } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { getQueryArg, addQueryArgs } from '@wordpress/url';

/**
 * Internal dependencies
 */
import Data from 'googlesitekit-data';
import { VIEW_CONTEXT_DASHBOARD_SPLASH } from '../../googlesitekit/constants';
import WelcomeSVG from '../../../svg/graphics/welcome.svg';
import WelcomeAnalyticsSVG from '../../../svg/graphics/welcome-analytics.svg';
import { trackEvent, untrailingslashit } from '../../util';
import Header from '../Header';
import Button from '../Button';
import ResetButton from '../ResetButton';
import Layout from '../layout/Layout';
import BannerNotification from '../notifications/BannerNotification';
import OptIn from '../OptIn';
import CompatibilityChecks from './CompatibilityChecks';
import { CORE_SITE } from '../../googlesitekit/datastore/site/constants';
import {
	CORE_USER,
	DISCONNECTED_REASON_CONNECTED_URL_MISMATCH,
	PERMISSION_VIEW_SHARED_DASHBOARD,
} from '../../googlesitekit/datastore/user/constants';
import { CORE_LOCATION } from '../../googlesitekit/datastore/location/constants';
import { CORE_MODULES } from '../../googlesitekit/modules/datastore/constants';
import { CORE_FORMS } from '../../googlesitekit/datastore/forms/constants';
import { Grid, Row, Cell } from '../../material-components';
import {
	ANALYTICS_NOTICE_FORM_NAME,
	ANALYTICS_NOTICE_CHECKBOX,
	SHARED_DASHBOARD_SPLASH_ITEM_KEY,
} from './constants';
import HelpMenu from '../help/HelpMenu';
import ActivateAnalyticsNotice from './ActivateAnalyticsNotice';
import { useFeature } from '../../hooks/useFeature';
import Link from '../Link';
const { useSelect, useDispatch } = Data;

export default function SetupUsingProxyWithSignIn() {
	const dashboardSharingEnabled = useFeature( 'dashboardSharing' );

	const analyticsModuleActive = useSelect( ( select ) =>
		select( CORE_MODULES ).isModuleActive( 'analytics' )
	);
	const connectAnalytics = useSelect( ( select ) =>
		select( CORE_FORMS ).getValue(
			ANALYTICS_NOTICE_FORM_NAME,
			ANALYTICS_NOTICE_CHECKBOX
		)
	);
	const {
		isSecondAdmin,
		isResettable,
		siteURL,
		proxySetupURL,
		disconnectedReason,
		isConnected,
		connectedProxyURL,
		homeURL,
	} = useSelect( ( select ) => {
		const site = select( CORE_SITE );
		const user = select( CORE_USER );

		return {
			isSecondAdmin: site.hasConnectedAdmins(),
			isResettable: site.isResettable(),
			siteURL: site.getReferenceSiteURL(),
			proxySetupURL: site.getProxySetupURL(),
			disconnectedReason: user.getDisconnectedReason(),
			connectedProxyURL: untrailingslashit( user.getConnectedProxyURL() ),
			homeURL: untrailingslashit( site.getHomeURL() ),
			isConnected: site.isConnected(),
		};
	} );

	const dashboardURL = useSelect( ( select ) =>
		select( CORE_SITE ).getAdminURL( 'googlesitekit-dashboard' )
	);

	const canViewSharedDashboard = useSelect( ( select ) =>
		select( CORE_USER ).hasCapability( PERMISSION_VIEW_SHARED_DASHBOARD )
	);

	const { dismissItem } = useDispatch( CORE_USER );

	const goToSharedDashboard = useCallback( () => {
		dismissItem( SHARED_DASHBOARD_SPLASH_ITEM_KEY );

		global.navigateTo( dashboardURL );
	}, [ dashboardURL, dismissItem ] );

	const { navigateTo } = useDispatch( CORE_LOCATION );
	const { activateModule } = useDispatch( CORE_MODULES );

	const onButtonClick = useCallback(
		async ( event ) => {
			event.preventDefault();

			let moduleReauthURL;

			if ( connectAnalytics ) {
				const { error, response } = await activateModule( 'analytics' );

				if ( ! error ) {
					await trackEvent(
						VIEW_CONTEXT_DASHBOARD_SPLASH,
						'start_setup_with_analytics'
					);

{'fraction_non_alphanumeric': 0.12187464962439735, 'fraction_numerical': 0.002242403856934634, 'mean_word_length': 4.409338993329291, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5040628', 'n_tokens_mistral': 2913, 'n_tokens_neox': 2746, 'n_words': 681}