diff --git a/src/Pages/VotingSystem.jsx b/src/Pages/VotingSystem.jsx index e3d3f7e..6213909 100644 --- a/src/Pages/VotingSystem.jsx +++ b/src/Pages/VotingSystem.jsx @@ -5,8 +5,6 @@ import { Vote, BarChart3, Users, - Clock, - Shield, TrendingUp, CheckCircle2 } from 'lucide-react'; @@ -22,12 +20,8 @@ const VotingSystem = () => { const [showFeedbackModal, setShowFeedbackModal] = useState(false); const [currentPollForFeedback, setCurrentPollForFeedback] = useState(null); - useEffect(() => { - }, []); - const handleVote = (pollId, optionIndex) => { if (votedPolls.has(pollId)) return; - setPolls((prevPolls) => prevPolls.map((poll) => { if (poll.id === pollId) { @@ -39,8 +33,6 @@ const VotingSystem = () => { }) ); setVotedPolls(prev => new Set([...prev, pollId])); - - // Show feedback modal after voting const poll = polls.find(p => p.id === pollId); setCurrentPollForFeedback(poll); setShowFeedbackModal(true); @@ -48,40 +40,16 @@ const VotingSystem = () => { const handleFeedbackSubmit = async (formData) => { try { - // Here you would send feedback to your backend - console.log('Submitting voting feedback:', { - pollId: currentPollForFeedback?.id, - pollTitle: currentPollForFeedback?.title, - ...formData - }); - - // You can add API call here to save feedback - // await fetch('/api/feedback', { - // method: 'POST', - // headers: { 'Content-Type': 'application/json' }, - // body: JSON.stringify({ - // pollId: currentPollForFeedback?.id, - // pollTitle: currentPollForFeedback?.title, - // feedbackType: 'voting', - // ...formData - // }) - // }); - toast.success('Thank you for your feedback!'); } catch (error) { - console.error('Failed to submit feedback:', error); toast.error('Failed to submit feedback. Please try again.'); } }; - - const handleCreatePoll = (e) => { e.preventDefault(); const optionsArray = newOptions.split('\n').map(opt => opt.trim()).filter(opt => opt); - if (!newTitle.trim() || optionsArray.length < 2) { - return; - } + if (!newTitle.trim() || optionsArray.length < 2) return; const newPoll = { id: Date.now(), title: newTitle.trim(), @@ -98,128 +66,128 @@ const VotingSystem = () => { const getVotePercentage = (votes, total) => total > 0 ? Math.round((votes / total) * 100) : 0; return ( -
-
+
+
+ {/* Header */} -
- +
+
-

+

Voting System

-

- Create engaging polls and gather insights with our modern, secure voting platform. - Real-time results with beautiful analytics. +

+ Create polls, vote, and view results, all in a secure, beautiful platform.

+ {/* Stats */} -
-
-
- -
-
-

Active Polls

-

{polls.length}

-
-
-
- -
-
-
- -
-
-

Total Votes

-

- {polls.reduce((acc, poll) => acc + poll.votes.reduce((a, v) => a + v, 0), 0)} -

-
-
-
- -
-
-
- + {/* Stat Card */} + {[ + { + icon: , + label: "Active Polls", + value: polls.length, + bg: "from-emerald-100 to-teal-100 dark:from-green-900 dark:to-emerald-900" + }, + { + icon: , + label: "Total Votes", + value: polls.reduce((acc, poll) => acc + poll.votes.reduce((a, v) => a + v, 0), 0), + bg: "from-teal-100 to-lime-100 dark:from-teal-900 dark:to-lime-900" + }, + { + icon: , + label: "Engagement", + value: polls.length > 0 ? Math.round( + polls.reduce((acc, poll) => acc + getTotalVotes(poll), 0) / polls.length + ) : 0, + bg: "from-lime-100 to-emerald-100 dark:from-lime-900 dark:to-emerald-900" + } + ].map((stat, idx) => ( +
+
+ {stat.icon}
-
-

Engagement

-

- {polls.length > 0 ? Math.round(polls.reduce((acc, poll) => acc + poll.votes.reduce((a, v) => a + v, 0), 0) / polls.length) : 0} -

+
+

{stat.label}

+
{stat.value}
-
+ ))} + {/* Tabs */}
{[ { id: 'browse', label: 'Browse Polls', icon: Vote }, { id: 'create', label: 'Create Poll', icon: Plus }, { id: 'results', label: 'Analytics', icon: BarChart3 } - ].map((tab) => { - const Icon = tab.icon; - return ( - - ); - })} + ].map((tab) => ( + + ))}
+ {/* Tab Content */} + {/* Browse Polls */} {activeTab === 'browse' && ( -
+
{polls.length === 0 ? (
-
- +
+

No polls yet

-

Create your first poll to get started with collecting votes!

+

+ Create your first poll to get started! +

@@ -228,18 +196,16 @@ const VotingSystem = () => { polls.map((poll) => { const totalVotes = getTotalVotes(poll); const hasVoted = votedPolls.has(poll.id); - return ( -
+

{poll.title}

- {!hasVoted ? (
{poll.options.map((option, idx) => ( @@ -251,21 +217,23 @@ const VotingSystem = () => { const votes = poll.votes[idx] || 0; const percentage = getVotePercentage(votes, totalVotes); return ( -
+
- {option} + {option} {votes} votes ({percentage}%)
-
-
+
+ transition={{ duration: 0.8 }} + />
); })} -
+
You voted in this poll @@ -275,7 +243,7 @@ const VotingSystem = () => { setCurrentPollForFeedback(poll); setShowFeedbackModal(true); }} - className="text-sm text-green-600 dark:text-green-400 hover:text-green-700 dark:hover:text-green-300 underline" + className="text-sm text-emerald-600 dark:text-emerald-400 hover:text-emerald-700 dark:hover:text-emerald-300 underline" > Share feedback @@ -288,17 +256,17 @@ const VotingSystem = () => { )}
)} - + + {/* Create Poll */} {activeTab === 'create' && (

Create New Poll

-

Design an engaging poll to gather opinions from your audience

+

Design a poll to gather opinions

- -
+
-
-
-