import { useEffect, useState } from "react" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { Switch } from "@/components/ui/switch" import { Label } from "@/components/ui/label" import { Checkbox } from "@/components/ui/checkbox" import { Badge } from "@/components/ui/badge" import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert" import { ShoppingCart, KeyRound } from "lucide-react" import { SettingsGrid } from "@/components/settings-layout" import { EmailVerificationSettings, wordpressRoles, } from "../../config" interface SettingsTabProps { settings: EmailVerificationSettings updateSettings: (key: K, value: EmailVerificationSettings[K]) => void toggleRole: (role: string) => void } interface RegistrationFormState { enabled: boolean applyToWordPress: boolean applyToWooCommerce: boolean } export function SettingsTab({ settings, updateSettings, toggleRole }: SettingsTabProps) { const [registrationForm, setRegistrationForm] = useState({ enabled: false, applyToWordPress: false, applyToWooCommerce: false, }) useEffect(() => { const loadRegistrationFormSettings = async () => { try { const apiUrl = window.swiftCommerceData?.apiUrl || '/wp-json/swift-commerce/v1' const response = await fetch(`${apiUrl}/registration-form/settings`, { headers: { 'X-WP-Nonce': window.swiftCommerceData?.restNonce || '', }, credentials: 'same-origin', }) if (!response.ok) return const data = await response.json() if (data.success && data.settings) { setRegistrationForm({ enabled: Boolean(data.settings.enabled), applyToWordPress: Boolean(data.settings.applyToWordPress), applyToWooCommerce: Boolean(data.settings.applyToWooCommerce), }) } } catch (error) { console.error('Failed to load registration form status:', error) } } loadRegistrationFormSettings() }, []) const hasRegistrationFormConflict = settings.enabled && registrationForm.enabled && ( (settings.enableForRegistration && registrationForm.applyToWordPress) || (settings.enableForWooCommerceRegistration && registrationForm.applyToWooCommerce) ) const showsPasswordFlowNotice = settings.enabled && (settings.enableForRegistration || settings.enableForWooCommerceRegistration) return ( {/* Core Settings - FREE */} Verification Settings Configure when email verification is required {hasRegistrationFormConflict && (

When enabled, Registration Form field order and custom fields appear on active registration forms. When disabled, Email Verification shows its default password setup fields.

updateSettings('registrationFormMode', checked ? 'registration_form' : 'email_verification')} />

Active form: {settings.registrationFormMode === 'registration_form' ? 'Registration Form fields' : 'Email Verification default fields'}

)} {showsPasswordFlowNotice && ( Password setup is handled during registration Swift Commerce asks new users to create their password during registration, so the account is ready after verification or approval. )} {/* Enable for WordPress Registration - FREE */}

Require email verification for WordPress default registration form

updateSettings('enableForRegistration', checked)} />
{/* Enable for WooCommerce My Account - FREE */}
WooCommerce

Require email verification for WooCommerce My Account registration

updateSettings('enableForWooCommerceRegistration', checked)} />
{/* Skip Roles - FREE */} Skip Verification for Roles Select user roles that should bypass email verification
{wordpressRoles.map((role) => { const isChecked = settings.skipRoles.includes(role.value) return (
toggleRole(role.value)} > toggleRole(role.value)} />
) })}

Users with selected roles will not need to verify their email address.

) }