import React, { useState, useEffect } from 'react'; import CloseIcon from '@mui/icons-material/Close'; import SaveIcon from '@mui/icons-material/Save'; import CheckCircleIcon from '@mui/icons-material/CheckCircle'; import LinkIcon from '@mui/icons-material/Link'; import { getNonce } from '../Helpers'; interface Integration { id: string; name: string; description: string; icon: string; config: any; fields: ConfigField[]; } interface ConfigField { name: string; label: string; type: string; required?: boolean; sensitive?: boolean; placeholder?: string; description?: string; options?: Array<{ value: string; label: string }>; } interface IntegrationModalProps { integration: Integration; isOpen: boolean; onClose: () => void; onSave: (integrationId: string, config: any) => void; onTest: (integrationId: string, config: any) => Promise; } const IntegrationModal: React.FC = ({ integration, isOpen, onClose, onSave, onTest }) => { const [config, setConfig] = useState({}); const [testing, setTesting] = useState(false); const [testResult, setTestResult] = useState<{ success: boolean; message: string } | null>(null); const [saving, setSaving] = useState(false); const [activeTab, setActiveTab] = useState<'settings' | 'hints'>('settings'); const [connecting, setConnecting] = useState(false); useEffect(() => { if (isOpen) { // Initialize config with existing values setConfig(integration.config || {}); setTestResult(null); setActiveTab('settings'); } }, [isOpen, integration]); const handleChange = (fieldName: string, value: any) => { setConfig((prev: any) => ({ ...prev, [fieldName]: value })); setTestResult(null); // Clear test result when config changes }; const handleTest = async () => { setTesting(true); setTestResult(null); try { const message = await onTest(integration.id, config); setTestResult({ success: true, message }); } catch (error: any) { setTestResult({ success: false, message: error }); } finally { setTesting(false); } }; const handleSave = () => { setSaving(true); onSave(integration.id, config); // Reset saving state after a delay (will be handled by parent component) setTimeout(() => setSaving(false), 1000); }; const handleConnectToGoogle = async () => { setConnecting(true); setTestResult(null); try { const response = await fetch((window as any).ajaxurl, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, body: new URLSearchParams({ action: 'simpleform_get_oauth_url', nonce: getNonce(), integration_id: integration.id, }), }); const data = await response.json(); if (data.success) { // Redirect to Google authorization window.location.href = data.data.auth_url; } else { setTestResult({ success: false, message: data.data?.message || 'Failed to get authorization URL' }); } } catch (error: any) { setTestResult({ success: false, message: 'Error connecting to Google: ' + error.message }); } finally { setConnecting(false); } }; const renderHintsTab = () => { if (integration.id === 'google_sheets') { return (

📋 Setup Instructions

Step 1: Create OAuth Credentials

  1. Go to Google Cloud Console
  2. Select your project or create a new one
  3. Navigate to APIs & ServicesCredentials
  4. Click Create CredentialsOAuth client ID
  5. Choose Web application
  6. Add this as Authorized redirect URI:
    {window.location.origin}/wp-admin/admin.php
    Note: Use ONLY the base URL without any query parameters
  7. Click Create and copy your Client ID and Client Secret

Step 2: Enable Google Sheets API

  1. In Google Cloud Console, go to APIs & ServicesLibrary
  2. Search for "Google Sheets API"
  3. Click Enable

Step 3: Configure OAuth Consent Screen

  1. Go to APIs & ServicesOAuth consent screen
  2. Choose External (for public) or Internal (for organization)
  3. Fill in app name, support email, and developer contact
  4. Add scope: https://www.googleapis.com/auth/spreadsheets
  5. Save and continue

⚠️ Important: Add Test Users

Since your app is in Testing mode, you must add test users:

  1. In OAuth consent screen, scroll to Test users section
  2. Click + ADD USERS
  3. Enter your Google email address (the one you'll use to authorize)
  4. Click SAVE

Without adding yourself as a test user, you'll get an "access_denied" error when trying to connect.

Step 4: Connect SimpleForm

  1. Enter your Client ID and Client Secret in the Settings tab
  2. Click Save Settings
  3. Click Connect to Google button
  4. Authorize the app when redirected to Google
  5. You'll be redirected back automatically
  6. Enter your Spreadsheet URL and Sheet Name
  7. Click Test Connection to verify

✅ You're All Set!

Once connected, all form submissions will automatically be sent to your Google Sheet.

⚠️ Troubleshooting

  • Invalid redirect URI: Make sure you added the exact redirect URI to Google Cloud Console
  • Access denied: Check that Google Sheets API is enabled
  • Token expired: Tokens auto-refresh, but you can reconnect if needed
); } if (integration.id === 'fluentcrm') { return (

📋 Setup Instructions

Step 1: Install FluentCRM

  1. Go to PluginsAdd New in your WordPress admin
  2. Search for "FluentCRM"
  3. Click Install Now and then Activate
  4. Or download from WordPress.org

Step 2: Create Lists and Tags

  1. Go to FluentCRMContactsLists
  2. Create lists to organize your contacts (e.g., "Newsletter Subscribers", "Leads")
  3. Go to FluentCRMContactsTags
  4. Create tags to categorize contacts (e.g., "Website Form", "Contact Page")

Step 3: Configure Global Settings

  1. In the Settings tab, select your default lists and tags
  2. Choose whether to enable double opt-in (recommended for GDPR compliance)
  3. Decide if existing contacts should be updated
  4. Click Save Settings
  5. Toggle the integration ON to enable it

Step 4: Configure Per-Form Settings (Optional)

Each form can have its own FluentCRM settings:

  1. Open any form in the Form Builder
  2. Go to Form Settings tab
  3. Scroll to FluentCRM Integration section
  4. Toggle to enable/disable for this specific form
  5. Select form-specific lists and tags (overrides global settings)
  6. Save your form

✅ How It Works

  • When a form is submitted, the contact is automatically added to FluentCRM
  • Email, name, phone, and other fields are mapped automatically
  • Contacts are added to the selected lists and tagged appropriately
  • You can then use FluentCRM's automation features for follow-ups

⚠️ Important Notes

  • Email Required: Forms must have an email field for FluentCRM integration to work
  • Global vs Form Settings: Form-specific settings override global settings
  • Double Opt-in: If enabled, contacts will receive a confirmation email before being added
  • GDPR Compliance: Make sure you have proper consent checkboxes in your forms
); } // Default hints for other integrations return (

Setup Instructions

Follow the instructions in the Settings tab to configure this integration.

); }; const renderField = (field: ConfigField) => { const value = config[field.name] || ''; switch (field.type) { case 'text': case 'password': case 'email': case 'url': return ( handleChange(field.name, e.target.value)} placeholder={field.placeholder} required={field.required} /> ); case 'textarea': return (