import { __ } from '@wordpress/i18n'; import { createInterpolateElement } from '@wordpress/element'; import { useEffect, useState } from 'react'; import useGSCData from '@/hooks/useGSCData'; import ButtonInput from '@/components/Inputs/ButtonInput'; import Modal from '@/components/Common/Modal'; import Icon from '@/utils/Icon'; /** * Google Search Console product mark. Inlined (no asset) following the BurstLogo * pattern. Native artwork is 256x228; only `size` is exposed. * * @param {Object} props Component props. * @param {number} props.size Edge length in px. * @return {JSX.Element} The icon. */ const GoogleSearchConsoleIcon = ({ size = 24 }: { size?: number }) => ( ); /** * Settings field that connects / disconnects Google Search Console. * * Renders the three connection states (connected, disconnected, * needs-reconnect). Connecting happens inside a modal so the loading and error * states stay visible for the whole popup round-trip. Token handling lives * entirely on the server; this only reflects state. * * @return {JSX.Element} The rendered field. */ const GoogleSearchConsoleField = () => { const { status, isFetching, isConnecting, isDisconnecting, error, connect, cancelConnect, disconnect } = useGSCData(); const [ connectOpen, setConnectOpen ] = useState( false ); const [ disconnectOpen, setDisconnectOpen ] = useState( false ); const isConnected = 'connected' === status; const needsReconnect = 'needs-reconnect' === status; // Close the connect modal once the connection lands. useEffect( () => { if ( connectOpen && isConnected ) { setConnectOpen( false ); } }, [ connectOpen, isConnected ]); const closeConnect = () => { cancelConnect(); setConnectOpen( false ); }; return (
{ __( 'Google Search Console', 'burst-statistics' ) }
{ isConnected && __( 'Connected', 'burst-statistics' ) } { needsReconnect && __( 'Reconnection required', 'burst-statistics' ) } { 'disconnected' === status && __( 'Not connected', 'burst-statistics' ) }
{ createInterpolateElement( __( 'Burst shows your Search Console data using read-only access. Your authorization is stored only on this site and the data is fetched directly from Google – nothing is stored on Burst’s servers. Read our Search Console privacy policy.', 'burst-statistics' ), { a: ( ) } ) }
{ __( 'Burst will open a Google window where you can grant read-only access to your Search Console data. Keep this tab open while you authorize.', 'burst-statistics' ) }
{ isConnecting && ({ error }
) }