import React, { useState, useEffect } from 'react'; import { getNonce, isPro } from '../Helpers'; import LockIcon from '@mui/icons-material/Lock'; import LoginIcon from '@mui/icons-material/Login'; import PersonAddIcon from '@mui/icons-material/PersonAdd'; import CommentIcon from '@mui/icons-material/Comment'; import ShoppingCartIcon from '@mui/icons-material/ShoppingCart'; import SaveIcon from '@mui/icons-material/Save'; import SecurityIcon from '@mui/icons-material/Security'; import SettingsIcon from '@mui/icons-material/Settings'; import NoticeModal from './NoticeModal/NoticeModal'; import '../styles/_auth-settings.scss'; interface AuthSettingsProps { // Props if needed } interface FormOption { id: number; form_name: string; } const AuthSettings: React.FC = () => { const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); const [forms, setForms] = useState([]); const [isWooCommerceActive, setIsWooCommerceActive] = useState(false); const [activeTab, setActiveTab] = useState('forms'); const [isProUser, setIsProUser] = useState(false); // Check if user has pro version const [modalConfig, setModalConfig] = useState({ isOpen: false, type: 'toast' as 'success' | 'error' | 'confirmation' | 'premium' | 'toast', title: '', message: '', position: 'top-right' as 'top-right' | 'center', mode: 'success' as 'success' | 'error', onConfirm: () => { }, onClose: () => { }, confirmText: 'OK', declineText: 'Cancel' }); const [settings, setSettings] = useState({ wp_login_form_id: '', wp_registration_form_id: '', wc_login_form_id: '', wc_registration_form_id: '', comment_form_id: '', // Login settings enable_remember_me: true, redirect_after_login: '', save_login_to_leads: false, // Registration settings auto_login_after_registration: true, send_welcome_email: true, require_email_verification: false, password_min_length: 8, require_terms_acceptance: false, redirect_after_registration: '', save_registration_to_leads: false, // Security settings max_login_attempts: 5, lockout_duration: 15, enable_captcha_after_failures: false, }); useEffect(() => { loadSettings(); loadForms(); checkWooCommerce(); checkProStatus(); }, []); const checkProStatus = () => { const isProuser = isPro(); setIsProUser(isProuser); }; const showProModal = () => { setModalConfig({ isOpen: true, type: 'premium', title: '🚀 Upgrade to Pro', message: 'Login & Registration features are available in the Pro version. Upgrade now to unlock advanced authentication, user management, and security features!', position: 'center', mode: 'success', onConfirm: () => { window.open('https://wpazleen.com/simple-form-pricing/', '_blank'); closeModal(); }, onClose: closeModal, confirmText: 'Upgrade Now', declineText: 'Maybe Later' }); }; const closeModal = () => { setModalConfig(prev => ({ ...prev, isOpen: false })); }; const showToast = (mode: 'success' | 'error', title: string, message: string) => { setModalConfig({ isOpen: true, type: 'toast', title, message, position: 'top-right', mode, onConfirm: closeModal, onClose: closeModal, confirmText: 'OK', declineText: 'Cancel' }); setTimeout(closeModal, 3000); }; const loadSettings = () => { (wp as any).ajax.send('simpleform_get_auth_settings', { data: { nonce: getNonce(), }, success(response: any) { if (response.settings) { setSettings(prev => ({ ...prev, ...response.settings })); } setLoading(false); }, error(error: any) { showToast('error', 'Error', 'Failed to load settings. Please refresh the page.'); setLoading(false); }, }); }; const loadForms = () => { (wp as any).ajax.send('simpleform_get_tables', { data: { nonce: getNonce(), }, success(response: any) { setForms(response.tables || []); }, error(error: any) { showToast('error', 'Error', 'Failed to load forms list.'); }, }); }; const checkWooCommerce = () => { (wp as any).ajax.send('simpleform_check_woocommerce', { data: { nonce: getNonce(), }, success(response: any) { setIsWooCommerceActive(response.active || false); }, error() { setIsWooCommerceActive(false); }, }); }; const handleSave = () => { setSaving(true); (wp as any).ajax.send('simpleform_save_auth_settings', { data: { nonce: getNonce(), settings: settings, }, success(response: any) { setSaving(false); showToast('success', 'Success', 'Settings saved successfully!'); }, error(error: any) { setSaving(false); showToast('error', 'Error', 'Failed to save settings. Please try again.'); }, }); }; const handleChange = (field: string, value: any) => { setSettings(prev => ({ ...prev, [field]: value })); }; if (loading) { return (

Loading settings...

); } return (

Login & Registration Settings

Configure authentication forms and security settings

{/* Tab Navigation */}
{/* Form Selection Tab */} {activeTab === 'forms' && (
{!isProUser && (
PRO
)}

Form Selection

{/* WordPress Login */}
Replace default WordPress login form
{/* WordPress Registration */}
Replace default WordPress registration form
{/* WooCommerce Login */}
{isWooCommerceActive ? 'Replace WooCommerce login form' : 'Requires WooCommerce plugin'}
{/* WooCommerce Registration */}
{isWooCommerceActive ? 'Replace WooCommerce registration form' : 'Requires WooCommerce plugin'}
{/* Comment Form */}
Replace default comment form
)} {/* Login Settings Tab */} {activeTab === 'login' && (
{!isProUser && (
PRO
)}

Login Settings

Enable "Remember Me" Allow users to stay logged in
handleChange('redirect_after_login', e.target.value)} placeholder="Leave empty for dashboard" /> Custom URL to redirect users after successful login
Save login data to leads Store login attempts in leads database (username, time, IP)
)} {/* Registration Settings Tab */} {activeTab === 'registration' && (
{!isProUser && (
PRO
)}

Registration Settings

Auto-login after registration Automatically log in users after successful registration
Send welcome email Send WordPress welcome email to new users
Require email verification Users must verify email before logging in
Require terms acceptance Users must accept terms and conditions
handleChange('password_min_length', parseInt(e.target.value))} min="6" max="20" /> Minimum number of characters required for passwords
handleChange('redirect_after_registration', e.target.value)} placeholder="Leave empty for dashboard" /> Custom URL to redirect users after successful registration
Save registration data to leads Store registration data in leads database (all fields except passwords)
)} {/* Security Settings Tab */} {activeTab === 'security' && (
{!isProUser && (
PRO
)}

Security Settings

handleChange('max_login_attempts', parseInt(e.target.value))} min="3" max="10" /> Number of failed login attempts before lockout
handleChange('lockout_duration', parseInt(e.target.value))} min="5" max="60" /> How long to lock out users after max attempts
Enable CAPTCHA after failed attempts Show CAPTCHA after multiple failed login attempts
)} {/* Save Button - Always visible */}
{!isProUser && (
{/*
PRO
*/}
)}
{/* Notice Modal */}
); }; export default AuthSettings;