/** * WordPress dependencies */ import { Button, SelectControl, Spinner, TextControl, } from '@safe-wordpress/components'; import { _x } from '@safe-wordpress/i18n'; /** * External dependencies */ import { noop } from 'lodash'; import { usePostTypes } from '@nelio-content/data'; import { Maybe } from '@nelio-content/types'; /** * Internal dependencies */ import { AnalyticsRefreshButton } from './analytics-refresh-button'; import type { ConnectionMode, GA4Property } from './config'; type ConnectionProps = { readonly className?: string; readonly name: string; readonly currentProperty: Maybe< GA4Property >; readonly mode: ConnectionMode; readonly selectedProperty: Maybe< GA4Property >; readonly properties: ReadonlyArray< GA4Property >; readonly onChangeAccount: () => void; readonly onSelectProperty: ( property: GA4Property ) => void; }; export const Connection = ( { className = '', name, currentProperty, mode, selectedProperty, properties, onSelectProperty, onChangeAccount, }: ConnectionProps ): JSX.Element | null => { const hasAnalytics = usePostTypes( 'analytics' ).length > 0; if ( ! hasAnalytics ) { return null; } switch ( mode ) { case 'init': return (
); case 'awaiting-authorization': return (
{ _x( 'Please authorize your Google account…', 'user', 'nelio-content' ) }
); case 'property-retrieval': return (
{ _x( 'Fetching properties from Google Analytics…', 'user', 'nelio-content' ) }
); case 'property-selection': return (
{ properties.length ? ( ( { label: `${ p.name } (${ p.id })`, value: p.id, } ) ) } onChange={ ( selectedValue ) => onSelectProperty( properties.find( ( p ) => p.id === selectedValue ) as GA4Property ) } /> ) : (

{ _x( 'Selected account doesn’t have any properties. Please select a different account.', 'user', 'nelio-content' ) }

) }
); case 'ga4-property-id': return (
); } };