/** * "After sending": the form's actions (mails, webhooks, chat, SMS, WhatsApp, conversions), shown * with the contact step whose entries they handle, and the connections they use. Changing them * needs the right to see entries; whoever lacks it can prepare them, and someone with the right * publishes. */ import React, { useEffect, useRef, useState } from 'react'; import type { Action, Condition, FormDocument, Text } from '@funnelforms/form-schema'; import { ACTION_FOR_TYPE, ACTION_KINDS, actionGaps, addAction, addActionFor, addCrmAction, CONNECTION_TYPES, duplicateAction, emailFields, integrationsUrl, removeAction, retiredConnection, setRecipient, type ActionKind, type ActionTexts } from '../actions'; import type { Connection, ConnectionTest } from '../api'; import { calcRule, entryFields, starterRule } from '../conditions'; import { contactFields, CRM_NAMES, suggestMapping, type CrmConnection } from '../connect'; import { isPro } from '../edition'; import { euPrivacy, openPrivacy } from '../privacy'; import { nodeName, text } from '../document'; import { editText, setText } from '../languages'; import type { Recipe } from '../store'; import { useBuilder, useEnv } from './context'; import { describeCondition, fieldTitle } from './describe'; import { __, sprintf } from './i18n'; import { AiCallEditor } from './AiCall'; import { CrmAction } from './CrmAction'; import { CodeNotices } from './CustomCode'; import { useCrmCatalog } from './CrmConnections'; import { ConditionEditor } from './Logic'; import { MailEditor } from './MailEditor'; import { WhatsAppTemplatePicker } from './WhatsAppTemplates'; import { Button, Dialog, Field as FieldRow, icons, Notice, ProBadge, Select, TextInput, Toggle } from './ui'; function useChange(): ( recipe: Recipe, key?: string ) => void { return useEnv().store.getState().change; } export function kindName( kind: string ): string { const names: Record = { email: __( 'E-mail to you', 'funnelforms-pro' ), autoresponder: __( 'Confirmation to the visitor', 'funnelforms-pro' ), webhook: __( 'Webhook', 'funnelforms-pro' ), chat: __( 'Slack or Teams message', 'funnelforms-pro' ), sms: __( 'Text message (SMS)', 'funnelforms-pro' ), whatsapp: __( 'WhatsApp message', 'funnelforms-pro' ), aiCall: __( 'AI Phone Agent', 'funnelforms-pro' ), conversion: __( 'Conversion (Meta, GA4, TikTok)', 'funnelforms-pro' ), googleAds: __( 'Google Ads conversion', 'funnelforms-pro' ), crm: __( 'CRM, newsletter or spreadsheet', 'funnelforms-pro' ), customCode: __( 'Custom code', 'funnelforms-pro' ), }; return names[ kind ] ?? kind; } function connectionTypeName( type: string ): string { const names: Record = { slack: 'Slack', teams: 'Microsoft Teams', twilio: 'Twilio', bird: 'Bird', whatsapp: 'WhatsApp Business', elevenlabs: 'ElevenLabs', meta: 'Meta', ga4: 'Google Analytics 4', tiktok: 'TikTok', smtp: 'SMTP', stripe: 'Stripe', paypal: 'PayPal', mollie: 'Mollie', caldav: 'CalDAV', google: 'Google Calendar', microsoft: 'Microsoft Outlook', }; return names[ type ] ?? type; } /** Credentials each connection type asks for: parameter, label, secret, optional. */ function credentials( type: string ): Array<[ string, string, boolean, boolean? ]> { const webhook = __( 'Webhook URL', 'funnelforms-pro' ); const accessKey = __( 'Access key', 'funnelforms-pro' ); const accessToken = __( 'Access token', 'funnelforms-pro' ); const all: Record> = { slack: [ [ 'url', webhook, true ] ], teams: [ [ 'url', webhook, true ] ], twilio: [ [ 'accountSid', __( 'Account SID', 'funnelforms-pro' ), false ], [ 'authToken', __( 'Auth token', 'funnelforms-pro' ), true ], ], bird: [ [ 'workspaceId', __( 'Workspace ID', 'funnelforms-pro' ), false ], [ 'channelId', __( 'Channel ID', 'funnelforms-pro' ), false ], [ 'accessKey', accessKey, true ], ], whatsapp: [ [ 'phoneNumberId', __( 'Phone number ID', 'funnelforms-pro' ), false ], [ 'accessToken', accessToken, true ], [ 'businessAccountId', __( 'WhatsApp Business account ID (for templates)', 'funnelforms-pro' ), false, true ], ], meta: [ [ 'pixelId', __( 'Pixel ID', 'funnelforms-pro' ), false ], [ 'accessToken', accessToken, true ], ], ga4: [ [ 'measurementId', __( 'Measurement ID', 'funnelforms-pro' ), false ], [ 'apiSecret', __( 'API secret', 'funnelforms-pro' ), true ], ], tiktok: [ [ 'pixelCode', __( 'Pixel code', 'funnelforms-pro' ), false ], [ 'accessToken', accessToken, true ], ], stripe: [ [ 'secretKey', __( 'Secret key (sk_… or rk_…)', 'funnelforms-pro' ), true ], [ 'webhookSecret', __( 'Webhook signing secret (whsec_…)', 'funnelforms-pro' ), true, true ], ], paypal: [ [ 'clientId', __( 'Client ID', 'funnelforms-pro' ), false ], [ 'clientSecret', __( 'Client secret', 'funnelforms-pro' ), true ], ], mollie: [ [ 'apiKey', __( 'API key (live_… or test_…)', 'funnelforms-pro' ), true ] ], }; return all[ type ] ?? []; } /** How a connection can be tried out: a message to a number, a message to the channel, or not at all (payments, conversions). */ function testKind( type: string ): 'number' | 'whatsapp' | 'direct' | null { if ( CONNECTION_TYPES.sms.includes( type ) ) { return 'number'; } if ( 'whatsapp' === type ) { return 'whatsapp'; } return [ 'slack', 'teams', 'caldav', 'google', 'microsoft' ].includes( type ) ? 'direct' : null; } /** Where the form uses a connection: its actions, the mail server of mails, the payment. */ export function connectionUses( doc: FormDocument | null, ref: string ): string[] { if ( ! doc || ! ref ) { return []; } const uses = doc.actions .filter( ( a ) => { const config = a.config as unknown as { connectionRef?: string; transport?: { connectionRef?: string } }; return config.connectionRef === ref || config.transport?.connectionRef === ref; } ) .map( ( a ) => kindName( a.kind ) ); if ( doc.settings.payment?.connection === ref ) { uses.push( __( 'Payment', 'funnelforms-pro' ) ); } for ( const node of doc.nodes ) { for ( const field of 'contact' === node.type ? node.fields : [] ) { if ( ( field.props.sms as { connectionRef?: string } | undefined )?.connectionRef === ref ) { uses.push( __( 'Phone verification', 'funnelforms-pro' ) ); } } } return uses; } function defaultTexts(): ActionTexts { return { adminSubject: __( 'New entry', 'funnelforms-pro' ), adminBody: __( 'You have a new entry:', 'funnelforms-pro' ) + '\n\n{{lead}}\n\n{{answers}}', replySubject: __( 'Thank you for your request', 'funnelforms-pro' ), replyBody: __( 'Thank you! We have received your answers and will get back to you soon.', 'funnelforms-pro' ) + '\n\n{{answers}}', chatMessage: __( 'New entry', 'funnelforms-pro' ), }; } function gapText( gap: ReturnType[ number ] ): string { const texts = { recipient: __( 'Add a recipient.', 'funnelforms-pro' ), url: __( 'Enter the web address that receives the entries.', 'funnelforms-pro' ), connection: __( 'Choose a connection.', 'funnelforms-pro' ), template: __( 'Enter the name of the approved template.', 'funnelforms-pro' ), sendTo: __( 'Enter the conversion ID and label, e.g. AW-123456789/AbC-D_efG.', 'funnelforms-pro' ), agent: __( 'Choose the agent that calls.', 'funnelforms-pro' ), consent: __( 'Choose the consent field: the lead is called only when it is checked.', 'funnelforms-pro' ), code: __( 'Enter the code that runs after sending.', 'funnelforms-pro' ), }; return texts[ gap ]; } /** One line about where an action goes. */ function target( action: Action, locale: string, connections: Connection[] ): string { const label = ( ref: string ): string => connections.find( ( c ) => c.ref === ref )?.label ?? ''; switch ( action.kind ) { case 'email': case 'autoresponder': return text( action.config.to, locale ); case 'webhook': return action.config.url; case 'sms': return retiredConnection( action.config.connectionRef ) ? __( 'MessageBird (no longer supported)', 'funnelforms-pro' ) : label( action.config.connectionRef ); case 'chat': case 'whatsapp': case 'conversion': return label( action.config.connectionRef ); case 'aiCall': return ''; case 'crm': return [ CRM_NAMES[ action.config.provider ] ?? action.config.provider, label( action.config.connectionRef ) ].filter( Boolean ).join( ' · ' ); case 'googleAds': return action.config.sendTo; case 'customCode': { // The first line of the code, so several pieces can be told apart. const line = action.config.code.trim().split( '\n' )[ 0 ] ?? ''; return line.length > 48 ? line.slice( 0, 47 ) + '…' : line; } default: return ''; } } /** * The actions of the form; with a node, those that run for entries of that contact step (the * actions for every contact step among them), and new ones are for that step alone when there * are several. */ export function ActionsSection( { doc, node }: { doc: FormDocument; node?: string } ) { const { api, rights, readOnly } = useEnv(); const change = useChange(); const [ connections, setConnections ] = useState( [] ); const [ open, setOpen ] = useState( null ); const locale = doc.locales.default; const several = doc.nodes.filter( ( n ) => 'contact' === n.type ).length > 1; const shown = node ? doc.actions.filter( ( a ) => ! a.node || a.node === node ) : doc.actions; useEffect( () => { let live = true; api.connections().then( ( list ) => live && setConnections( list ), () => undefined ); return () => { live = false; }; }, [ api ] ); const add = ( kind: ActionKind | ( ( d: FormDocument ) => string | null ) ): void => { let id = ''; change( ( d ) => { id = ( 'function' === typeof kind ? kind( d ) : addAction( d, kind, defaultTexts() ) ) ?? ''; const created = d.actions.find( ( a ) => a.id === id ); if ( created && node && several ) { created.node = node; } } ); setOpen( id || null ); }; const connectionsChanged = ( list: Connection[] ): void => setConnections( list ); return (

{ node ? __( 'Actions', 'funnelforms-pro' ) : __( 'After sending', 'funnelforms-pro' ) }

{ rights.entries ? null : { __( 'Changes here need the right to see entries. You can prepare them; someone with that right publishes them.', 'funnelforms-pro' ) } } { 0 === shown.length ?

{ __( 'Nothing happens yet besides saving the entry. Add a mail to you, a confirmation for the visitor or a connection to your tools.', 'funnelforms-pro' ) }

: null }
    { shown.map( ( action ) => { const gaps = actionGaps( action, locale ); const expanded = open === action.id; return (
  • { expanded ? (
    { gaps.map( ( g ) => ( { gapText( g ) } ) ) }
    ) : null }
  • ); } ) }
{ 'free' === process.env.FUNNELFORMS_EDITION ? ( <> label={ __( 'Add an action', 'funnelforms-pro' ) } value="" options={ [ { value: '', label: __( 'Choose…', 'funnelforms-pro' ) }, ...freeKinds( doc, node && several ? node : undefined ).map( ( k ) => ( { value: k, label: kindName( k ) } ) ), ] } onChange={ ( v ) => { if ( '' !== v && ! readOnly ) { add( v ); } } } />

{ __( 'Webhooks, CRM and newsletter tools, Slack and Teams, text messages, WhatsApp, conversion tracking and more than one mail of each kind come with Funnelforms Pro.', 'funnelforms-pro' ) }

) : ( <> label={ __( 'Add an action', 'funnelforms-pro' ) } value="" options={ [ { value: '', label: __( 'Choose…', 'funnelforms-pro' ) }, ...ACTION_KINDS.map( ( k ) => ( { value: k, label: kindName( k ) } ) ), ] } onChange={ ( v ) => { if ( '' !== v && ! readOnly ) { add( v ); } } } /> ) }
); } /** * The site's connections an action can send entries through (CRM, newsletter and spreadsheet * tools, Slack and Teams, SMS, WhatsApp, conversion platforms), each ready to add with one click, * except those this step already sends to. Tools that are not connected yet are connected under * Funnelforms → Integrations, which the hint links to for users who may change settings. */ function ConnectedTools( { node, shown, connections, onAdd }: { node?: string; shown: Action[]; connections: Connection[]; onAdd: ( create: ( d: FormDocument ) => string | null ) => void } ) { const { api, readOnly } = useEnv(); const catalog = useCrmCatalog( api.connect ); const used = new Set( shown.map( ( a ) => ( a.config as { connectionRef?: string } ).connectionRef ).filter( Boolean ) ); const crm = ( c: CrmConnection ) => ( d: FormDocument ): string => { const spec = catalog.providers?.find( ( p ) => p.provider === c.provider ); return addCrmAction( d, c.provider, c.ref, spec ? suggestMapping( spec, contactFields( d, node ) ) : {} ); }; const ready = [ ...( catalog.connections ?? [] ).map( ( c ) => ( { ref: c.ref, name: CRM_NAMES[ c.provider ] ?? c.provider, label: c.label, create: crm( c ) } ) ), ...connections.filter( ( c ) => ACTION_FOR_TYPE[ c.type ] ).map( ( c ) => ( { ref: c.ref, name: connectionTypeName( c.type ), label: c.label, create: ( d: FormDocument ) => addActionFor( d, c, defaultTexts() ) } ) ), ].filter( ( r ) => ! used.has( r.ref ) ); const link = integrationsUrl(); if ( ! ready.length && ! link ) { return null; } return (
{ ready.length ? ( <>

{ __( 'Your connected tools', 'funnelforms-pro' ) }

    { ready.map( ( r ) => (
  • ) ) }
) : null } { link ? (

{ ready.length ? __( 'More tools are connected once under Integrations; they then show up here.', 'funnelforms-pro' ) : __( 'Send entries to your CRM, newsletter, Slack, WhatsApp or ad platforms: connect the tool once under Integrations, and it shows up here.', 'funnelforms-pro' ) }{ ' ' } { __( 'Open Integrations', 'funnelforms-pro' ) }

) : null }
); } /** Edits one text of an action's config in the language being edited. */ function useConfigText( doc: FormDocument, action: Action ) { const change = useChange(); const { lang } = useEnv(); const base = doc.locales.default; return ( key: string ) => { const config = action.config as unknown as Record; const current = config[ key ] as Text | undefined; const value = editText( current, lang, base ); const placeholder = lang !== base ? text( current, base ) : undefined; const set = ( v: string ): void => change( ( d ) => { const a = d.actions.find( ( x ) => x.id === action.id ); if ( a ) { const c = a.config as unknown as Record; const next = { ...( ( c[ key ] as Text | undefined ) ?? {} ) }; setText( next, lang, v, base ); c[ key ] = next; } }, `action:${ action.id }:${ key }` ); return { value, set, placeholder }; }; } /** In Funnelforms Free: the kinds that can be added, one notification and one confirmation per contact step. */ function freeKinds( doc: FormDocument, node: string | undefined ): ActionKind[] { return ACTION_KINDS.filter( ( k ) => ! isPro( 'action:' + k ) && ! doc.actions.some( ( a ) => a.kind === k && ( a.node ?? '' ) === ( node ?? '' ) ) ); } /** In Funnelforms Free: an action of Pro, which it neither edits nor runs. */ function ProAction( { kind }: { kind: ActionKind } ) { return { sprintf( /* translators: %s: name of an action, such as Webhook */ __( '%s is part of Funnelforms Pro. Delete this action to publish the form.', 'funnelforms-pro' ), kindName( kind ) ) }; } /** Changes a plain value of the action. */ function useConfigValue( action: Action ) { const change = useChange(); return ( key: string, value: unknown ): void => change( ( d ) => { const a = d.actions.find( ( x ) => x.id === action.id ); if ( a ) { ( a.config as unknown as Record )[ key ] = value; } }, `action:${ action.id }:${ key }` ); } /** Placeholders for mail and message texts: all answers, the lead summary, single fields, calculations. */ function Placeholders( { doc, onInsert }: { doc: FormDocument; onInsert: ( token: string ) => void } ) { const locale = doc.locales.default; const options: Array<{ value: string; label: string }> = [ { value: '', label: __( 'Insert a placeholder…', 'funnelforms-pro' ) }, { value: '{{answers}}', label: __( 'All answers', 'funnelforms-pro' ) }, { value: '{{lead}}', label: __( 'Lead summary: contact details, results and source', 'funnelforms-pro' ) }, { value: '{{contact}}', label: __( 'All contact details', 'funnelforms-pro' ) }, ...( doc.calculations.length ? [ { value: '{{calculations}}', label: __( 'All results of calculations', 'funnelforms-pro' ) } ] : [] ), { value: '{{entry:id}}', label: __( 'Number of the entry', 'funnelforms-pro' ) }, { value: '{{page:url}}', label: __( 'Page of the form', 'funnelforms-pro' ) }, { value: '{{form:title}}', label: __( 'Name of the form', 'funnelforms-pro' ) }, { value: '{{entry:date}}', label: __( 'Date of the entry', 'funnelforms-pro' ) }, { value: '{{entry:time}}', label: __( 'Time of the entry', 'funnelforms-pro' ) }, { value: '{{visit:device}}', label: __( 'Device (desktop, tablet, mobile)', 'funnelforms-pro' ) }, { value: '{{visit:browser}}', label: __( 'Browser and system', 'funnelforms-pro' ) }, { value: '{{visit:duration}}', label: __( 'Time to fill in', 'funnelforms-pro' ) }, { value: '{{visit:referrer}}', label: __( 'Came from', 'funnelforms-pro' ) }, { value: '{{utm}}', label: __( 'All UTM values', 'funnelforms-pro' ) }, ...[ 'source', 'medium', 'campaign', 'term', 'content' ].map( ( key ) => ( { value: `{{utm:${ key }}}`, label: `utm_${ key }` } ) ), { value: '{{url:gclid}}', label: __( 'Google Ads click ID (gclid)', 'funnelforms-pro' ) }, { value: '{{url:name}}', label: __( 'Another parameter of the page address (replace "name")', 'funnelforms-pro' ) }, ]; if ( doc.nodes.some( ( n ) => 'fields' in n && n.fields.some( ( f ) => 'booking' === f.type ) ) ) { options.push( { value: '{{booking:date}}', label: __( 'Date of the appointment', 'funnelforms-pro' ) }, { value: '{{booking:time}}', label: __( 'Time of the appointment', 'funnelforms-pro' ) }, { value: '{{booking:name}}', label: __( 'Type of the appointment', 'funnelforms-pro' ) }, { value: '{{booking:duration}}', label: __( 'Duration of the appointment', 'funnelforms-pro' ) } ); } if ( doc.settings.payment ) { options.push( { value: '{{payment:status}}', label: __( 'Status of the payment', 'funnelforms-pro' ) }, { value: '{{payment:amount}}', label: __( 'Amount paid', 'funnelforms-pro' ) }, { value: '{{payment:reference}}', label: __( 'Reference', 'funnelforms-pro' ) } ); } for ( const node of doc.nodes ) { if ( 'end' === node.type ) { continue; } for ( const field of node.fields ) { if ( ! [ 'content', 'result', 'html', 'captcha' ].includes( field.type ) ) { options.push( { value: `{{field:${ field.key }}}`, label: fieldTitle( field as never, locale ) } ); } } } for ( const calc of doc.calculations ) { options.push( { value: `{{calc:${ calc.id }}}`, label: calc.label || calc.id } ); } return ( { setTested( null ); onChange( v ); } } /> { retired ? { __( 'MessageBird is no longer supported; Bird is its successor. Choose a Twilio or Bird connection, or add one. Until then no text message is sent.', 'funnelforms-pro' ) } : null } { chosen?.webhookUrl ? ( { __( 'In Stripe, add this address as webhook endpoint for the events checkout.session.*, customer.subscription.*, charge.refunded and charge.dispute.created, then enter its signing secret here, so payments, subscriptions and refunds are confirmed even when visitors close the page.', 'funnelforms-pro' ) } { chosen.webhookUrl } ) : null } { tested && 'test' !== dialog ? { tested.message } : null } { rights.settings ? (
{ manage && kind && api.testConnection ? ( ) : null } { manage ? ( ) : null } { manage && api.deleteConnection && /^[a-z0-9]+:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test( chosen.ref ) ? ( ) : null } { chosen?.webhookUrl ? ( ) : null }
) : (

{ __( 'Connections are added by someone who may change the settings.', 'funnelforms-pro' ) }

) } { manage && ! kind && chosen ?

{ __( 'Try it with a test entry: payments with the test keys of the provider, conversions with the test event code of the platform.', 'funnelforms-pro' ) }

: null } { 'secret' === dialog && chosen ? setDialog( null ) } /> : null } { 'add' === dialog ? ( setDialog( null ) } onSaved={ ( c ) => { onConnection( c ); onChange( c.ref ); setDialog( null ); } } /> ) : null } { 'edit' === dialog && chosen ? ( setDialog( null ) } onSaved={ ( c ) => { onConnections?.( connections.map( ( x ) => ( x.ref === c.ref ? { ...x, ...c } : x ) ) ); setDialog( null ); } } /> ) : null } { 'delete' === dialog && chosen ? ( setDialog( null ) } onDeleted={ () => { onConnections?.( connections.filter( ( x ) => x.ref !== chosen.ref ) ); onChange( '' ); setDialog( null ); } } /> ) : null } { 'test' === dialog && chosen && kind ? void runTest( t ) } onClose={ () => { setDialog( null ); setTested( null ); } } /> : null } ); } /** Asks for the number (and for WhatsApp the template) a test goes to. */ function TestConnectionDialog( { connection, whatsapp, test, busy, result, onTest, onClose }: { connection: Connection; whatsapp: boolean; test?: ConnectionTest; busy: boolean; result: { ok: boolean; message: string } | null; onTest: ( test: ConnectionTest ) => void; onClose: () => void } ) { const [ to, setTo ] = useState( '' ); const [ sender, setSender ] = useState( test?.sender ?? '' ); const [ template, setTemplate ] = useState( test?.template || 'hello_world' ); const [ language, setLanguage ] = useState( test?.language || 'en_US' ); const ready = '' !== to.trim() && ( ! whatsapp || ( '' !== template.trim() && '' !== language.trim() ) ); return ( } > { result && ! result.ok ? { result.message } : null } { whatsapp ? ( <> ) : ( ) } ); } /** Deleting a connection, with what stops working in this form. */ function DeleteConnectionDialog( { connection, uses, onClose, onDeleted }: { connection: Connection; uses: string[]; onClose: () => void; onDeleted: () => void } ) { const { api } = useEnv(); const [ busy, setBusy ] = useState( false ); const [ error, setError ] = useState( null ); const remove = async (): Promise => { if ( ! api.deleteConnection ) { return; } setBusy( true ); setError( null ); try { await api.deleteConnection( connection.ref ); onDeleted(); } catch ( e ) { setError( e instanceof Error ? e.message : String( e ) ); setBusy( false ); } }; return ( } > { error ? { error } : null } { uses.length ? ( { sprintf( __( 'These stop working: %s. Choose another connection for them afterwards.', 'funnelforms-pro' ), uses.join( ', ' ) ) } ) : null }

{ __( 'The connection is deleted for the whole site: other forms that use it stop sending through it too. The stored access keys are removed; this cannot be undone.', 'funnelforms-pro' ) }

); } /** The Stripe signing secret, known only once the webhook address is registered in Stripe. */ function SecretDialog( { connection, onClose }: { connection: Connection; onClose: () => void } ) { const { api } = useEnv(); const [ secret, setSecret ] = useState( '' ); const [ busy, setBusy ] = useState( false ); const [ error, setError ] = useState( null ); const save = async (): Promise => { setBusy( true ); setError( null ); try { await api.updateConnection( connection.ref, { webhookSecret: secret.trim() } ); onClose(); } catch ( e ) { setError( e instanceof Error ? e.message : String( e ) ); setBusy( false ); } }; return ( } > { error ? { error } : null } ); } /** Adds a connection, or with one given changes its name and replaces the access keys typed in. */ function ConnectionDialog( { types, connection, onClose, onSaved }: { types: string[]; connection?: Connection; onClose: () => void; onSaved: ( c: Connection ) => void } ) { const { api } = useEnv(); const [ type, setType ] = useState( connection?.type ?? types[ 0 ] ?? '' ); const [ label, setLabel ] = useState( connection?.label ?? '' ); const [ values, setValues ] = useState>( {} ); const [ busy, setBusy ] = useState( false ); const [ error, setError ] = useState( null ); const [ sandbox, setSandbox ] = useState( false ); const fields = credentials( type ); const complete = '' !== label.trim() && ( connection ? true : fields.every( ( [ key, , , optional ] ) => optional || '' !== ( values[ key ] ?? '' ).trim() ) ); const save = async (): Promise => { setBusy( true ); setError( null ); try { const given = Object.fromEntries( Object.entries( values ).filter( ( [ , v ] ) => '' !== v.trim() ) ); if ( connection ) { onSaved( await api.updateConnection( connection.ref, { ...given, label: label.trim() } ) ); } else { onSaved( await api.createConnection( type, label.trim(), 'paypal' === type && sandbox ? { ...given, sandbox: true } : given ) ); } } catch ( e ) { setError( e instanceof Error ? e.message : String( e ) ); setBusy( false ); } }; return ( } > { error ? { error } : null } { types.length > 1 && ! connection ? change( ( d ) => { const a = d.actions.find( ( x ) => x.id === action.id ); if ( a ) { a.on = v; } } ) } /> ) : null } { contacts.length > 1 || action.node ? ( ( { value: f.id, label: text( f.label, locale ) || f.key } ) ) ] } onChange={ ( v ) => change( ( d ) => setRecipient( d, action.id, v ) ) } /> ) : ( { __( 'Add an e-mail field to a contact step to send a confirmation.', 'funnelforms-pro' ) } ) ) : ( field( 'to', __( 'To', 'funnelforms-pro' ), { hint: __( 'Several addresses separated by commas.', 'funnelforms-pro' ) } ) ) } { field( 'subject', __( 'Subject', 'funnelforms-pro' ) ) } } /> set( 'layout', v ? 'branded' : 'plain' ) } hint={ __( 'Your text on a card in the colour of the form, with the logo of your website; all answers as a clear table.', 'funnelforms-pro' ) } /> { /* The PDF is Funnelforms Pro: Free shows the switch only to turn it off. */ } { 'free' !== process.env.FUNNELFORMS_EDITION || true === action.config.attachPdf ? set( 'attachPdf', v ) } /> : null }
{ __( 'Sender and copies', 'funnelforms-pro' ) } { field( 'fromName', __( 'Sender name', 'funnelforms-pro' ) ) } { field( 'from', __( 'Sender address', 'funnelforms-pro' ), { hint: __( 'Empty for the address of the website. Use an address of your own domain, or mails may land in spam.', 'funnelforms-pro' ) } ) } { field( 'replyTo', __( 'Reply to', 'funnelforms-pro' ) ) } { field( 'cc', __( 'Copy to (CC)', 'funnelforms-pro' ) ) } { field( 'bcc', __( 'Blind copy to (BCC)', 'funnelforms-pro' ) ) } set( 'nl2br', v ) } /> { smtp.length || 'smtp' === transport.type ? ( set( 'format', 'ff4' === v ? 'ff4' : undefined ) } hint={ 'ff4' === action.config.format ? __( 'Fields are named by their variable names; contact fields as "field-" plus the name. Give fields the IDs they had in Funnelforms 4 as variable names, and existing Zaps keep working.', 'funnelforms-pro' ) : undefined } /> { common } ); case 'crm': return 'free' === process.env.FUNNELFORMS_EDITION ? : ; case 'chat': return 'free' === process.env.FUNNELFORMS_EDITION ? : ( <> { const v = e.target.value; change( ( d ) => { const a = d.actions.find( ( x ) => x.id === action.id ); if ( a && 'whatsapp' === a.kind ) { a.config.parameters[ i ] = { ...a.config.parameters[ i ], [ locale ]: v }; } }, `action:${ action.id }:p${ i }` ); } } /> { common } ); case 'aiCall': return 'free' === process.env.FUNNELFORMS_EDITION ? ( ) : ( ); case 'conversion': return 'free' === process.env.FUNNELFORMS_EDITION ? : ( <> ( { value: c.id, label: c.label || c.id } ) ) ] } onChange={ ( v ) => set( 'valueCalculation', v || undefined ) } /> ) : null } { action.config.valueCalculation ? set( 'currency', v.trim().toUpperCase() || undefined ) } /> : null }

{ __( 'Sent only when the cookie banner of your website reports the visitor\'s consent through the WP Consent API or Borlabs Cookie. Without that consent nothing is sent.', 'funnelforms-pro' ) }

{ common } ); case 'googleAds': return 'free' === process.env.FUNNELFORMS_EDITION ? : ( <> set( 'sendTo', v.replace( /\s/g, '' ) ) } hint={ __( 'In Google Ads under Goals, Conversions: the value of send_to in the event snippet.', 'funnelforms-pro' ) } />

{ __( 'Sent in the visitor\'s browser through the Google tag of your website once the entry is stored. Without a Google tag on the page nothing is sent.', 'funnelforms-pro' ) }

{ doc.calculations.length ? (