import React, { useState, useEffect } from 'react'; import LockIcon from '@mui/icons-material/Lock'; import NoticeModal from './../NoticeModal/NoticeModal'; import { getNonce, isPro } from '../../Helpers'; interface PollSettingsData { allow_multiple: boolean; show_results: 'always' | 'after_vote' | 'never'; allow_revote: boolean; require_login: boolean; close_date: string; result_display: 'percentage' | 'count' | 'both'; collect_name: boolean; collect_email: boolean; hide_after_submit: boolean; reward_type: 'none' | 'redirect' | 'coupon'; redirect_url: string; coupon_code: string; vote_tracking: 'ip_address' | 'browser_storage' | 'hybrid'; display_mode: 'all_at_once' | 'step_by_step'; answers_per_step: number; step_navigation: 'numbers' | 'custom' | 'progress_bar'; custom_step_labels: string[]; poll_type: 'single_question' | 'multiple_questions'; } interface PollSettingsProps { settings: PollSettingsData; onUpdate: (settings: PollSettingsData) => void; } const PollSettings: React.FC = ({ settings, onUpdate }) => { const [isProUser, setIsProUser] = useState(false); 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' }); useEffect(() => { const isProuser = isPro(); setIsProUser(isProuser); }, []); const closeModal = () => { setModalConfig(prev => ({ ...prev, isOpen: false })); }; const showProModal = () => { // alert('🔥Enjoy an awesome limited-time discount before it expires!'); setModalConfig({ isOpen: true, type: 'premium', title: '🚀 Upgrade to Pro', message: '🔥Enjoy an awesome limited-time discount before it expires!', position: 'center', mode: 'success', onConfirm: () => { window.open('https://wpazleen.com/simple-form-pricing/', '_blank'); closeModal(); }, onClose: closeModal, confirmText: 'Upgrade Now', declineText: 'Maybe Later' }); }; const updateSetting = (field: keyof PollSettingsData, value: any) => { // Show warning when switching poll types if (field === 'poll_type' && value !== settings.poll_type) { const message = value === 'multiple_questions' ? 'Switching to Multiple Questions Survey will convert your current answers into the first survey question. Continue?' : 'Switching to Single Question Poll will use only the first question from your survey. Continue?'; setModalConfig({ isOpen: true, type: 'confirmation', title: 'Change Poll Type', message: message, position: 'center', mode: 'success', onConfirm: () => { onUpdate({ ...settings, [field]: value, }); closeModal(); }, onClose: closeModal, confirmText: 'Continue', declineText: 'Cancel' }); return; // Don't change immediately, wait for confirmation } onUpdate({ ...settings, [field]: value, }); }; return (
{!isProUser && (
PRO
)}

User Information

Show name field before poll starts
Show email field before poll starts
{!isProUser && (
PRO
)}

Voting Options

Users can select more than one answer
Users can vote again to change their answer
Only logged-in users can participate
{!isProUser && (
PRO
)}

Results Display

When to display poll results to users
How to display the voting results
{!isProUser && (
PRO
)}

Poll Schedule

updateSetting('close_date', e.target.value)} disabled={!isProUser} /> Poll will automatically close on this date. Leave empty for no expiration.
{!isProUser && (
PRO
)}

Poll Behavior

Hide the poll form after user submits their vote
What to do after user completes the poll
{settings.reward_type === 'redirect' && (
updateSetting('redirect_url', e.target.value)} placeholder="https://example.com/thank-you" disabled={!isProUser} /> URL to redirect users after voting
)} {settings.reward_type === 'coupon' && (
updateSetting('coupon_code', e.target.value)} placeholder="SAVE20" disabled={!isProUser} /> Coupon code to display after voting
)}
{!isProUser && (
PRO
)}

Poll Type

Single Question: One question with multiple answer choices
Multiple Questions: Survey-style with multiple questions, each having their own answers
{!isProUser && (
PRO
)}

Display Mode

Choose how poll answers are displayed to users
{settings.display_mode === 'step_by_step' && ( <>
updateSetting('answers_per_step', parseInt(e.target.value) || 1)} disabled={!isProUser} /> Number of answer options to show per step
How to display step indicators
{settings.step_navigation === 'custom' && (