/** * Shared editor for MailChimp / MailPoet / Campaign Monitor Subscribe blocks. * Each block passes `config` (bridgeKey, list/hide/defaultChecked attrs, labels). * Empty `lists` → notice; single-select list id matches legacy. */ import { __ } from '@wordpress/i18n'; import { PanelBody, SelectControl, ToggleControl, Notice, ExternalLink } from '@wordpress/components'; import BaseFieldEdit from './BaseFieldEdit'; export default function SubscribeFieldEdit( props ) { const { config, ...blockProps } = props; const { attributes, setAttributes } = props; const fb = ( typeof window !== 'undefined' && window.wppbFb ) || {}; const bridge = ( config && fb[ config.bridgeKey ] ) || {}; const lists = Array.isArray( bridge.lists ) ? bridge.lists : []; const settingsUrl = bridge.settingsUrl || ''; const setYesNo = ( attr, on ) => setAttributes( { [ attr ]: on ? 'yes' : '' } ); const panel = ( { lists.length > 0 ? ( setAttributes( { [ config.listAttr ]: val } ) } help={ __( 'The list new subscribers are added to.', 'profile-builder' ) } /> ) : ( { __( 'No lists available — configure the integration in its settings page, then reopen this form.', 'profile-builder' ) } { settingsUrl && ' ' } { settingsUrl && ( { `${ config.serviceLabel } ${ __( 'settings', 'profile-builder' ) }` } ) } ) } { config.defaultCheckedAttr && ( setYesNo( config.defaultCheckedAttr, on ) } help={ __( 'Pre-check the subscribe box on registration forms.', 'profile-builder' ) } /> ) } setYesNo( config.hideFieldAttr, on ) } /> ); return ( ); }