/** * WordPress dependencies */ import { ToggleControl } from '@safe-wordpress/components'; import { _x } from '@safe-wordpress/i18n'; /** * External dependencies */ import type { AkismetSettings, SpamSettings } from '@nelio/forms/types'; import { TextFieldControl } from '@nelio/forms/components'; import { getFormEditorSettings } from '@nelio/forms/utils'; export type SpamSettingsProps = { readonly spamSettings: SpamSettings; readonly setSpamSettings: ( settings: SpamSettings ) => void; }; export const FormSpamSettings = ( props: SpamSettingsProps ): JSX.Element | null => { const { spamSettings, setSpamSettings } = props; const isAkismetActive = getFormEditorSettings().activePlugins.includes( 'akismet/akismet' ); if ( ! isAkismetActive ) { return ( <> { _x( 'Install and activate Akismet with an API key to enable spam check.', 'user', 'nelio-forms' ) } ); } //end if return ( <> setSpamSettings( checked ? { enabled: true, akismet: { custom: false, }, } : { enabled: false } ) } /> { spamSettings.enabled && ( <> setSpamSettings( { ...spamSettings, akismet: { name: '', email: '', url: '', content: '', ...spamSettings.akismet, custom: checked, }, } ) } /> setSpamSettings( { ...spamSettings, akismet } ) } /> ) } ); }; type AkismetCustomFieldsProps = { readonly akismet: AkismetSettings; readonly onChange: ( settings: AkismetSettings ) => void; }; const AkismetCustomFields = ( props: AkismetCustomFieldsProps ): JSX.Element | null => { const { akismet, onChange } = props; if ( ! akismet.custom ) { return null; } //end if const { name, email, url, content } = akismet; return ( <> onChange( { ...akismet, name: value } ) } /> onChange( { ...akismet, email: value } ) } /> onChange( { ...akismet, url: value } ) } /> onChange( { ...akismet, content: value } ) } /> ); };