/** * WordPress dependencies */ import { Button, SelectControl, Spinner, TextControl, } from '@safe-wordpress/components'; import { _x } from '@safe-wordpress/i18n'; /** * External dependencies */ import { noop } from 'lodash'; /** * Internal dependencies */ import type { ConnectionMode, GA4Property } from './config'; type ConnectionProps = { readonly className?: string; readonly disabled?: boolean; readonly currentProperty: GA4Property; readonly mode: ConnectionMode; readonly selectedProperty: GA4Property; readonly properties: ReadonlyArray< GA4Property >; readonly onChangeAccount: () => void; readonly onSelectProperty: ( property: GA4Property ) => void; }; export const Connection = ( { className = '', currentProperty, disabled, mode, selectedProperty, properties, onSelectProperty, onChangeAccount, }: ConnectionProps ): JSX.Element | null => { switch ( mode ) { case 'init': return null; case 'awaiting-authorization': return (
{ _x( 'Please authorize your Google account…', 'user', 'nelio-ab-testing' ) }
); case 'property-retrieval': return (
{ _x( 'Fetching properties from Google Analytics…', 'user', 'nelio-ab-testing' ) }
); 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-ab-testing' ) }

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