2025-12-08 16:31:30 +03:00

128 lines
4.4 KiB
TypeScript

'use client'
import { useEffect, useState } from 'react'
import { useRouter, useSearchParams } from 'next/navigation'
import confetti from 'canvas-confetti'
import Header from '@/components/Header'
import { Poll } from '@/types'
import { getPollById } from '@/lib/db/polls'
import { formatCUSD } from '@/lib/format'
export default function SuccessPage() {
const router = useRouter()
const searchParams = useSearchParams()
const pollId = searchParams.get('pollId')
const optionId = searchParams.get('optionId')
const amount = parseFloat(searchParams.get('amount') || '0')
const [poll, setPoll] = useState<Poll | null>(null)
const [isLoading, setIsLoading] = useState(true)
useEffect(() => {
// Fire confetti
confetti({
particleCount: 100,
spread: 70,
origin: { y: 0.6 },
})
const loadPoll = async () => {
if (!pollId) return
try {
const pollData = await getPollById(pollId)
setPoll(pollData)
} catch (error) {
console.error('Failed to load poll:', error)
} finally {
setIsLoading(false)
}
}
loadPoll()
}, [pollId])
if (isLoading) {
return (
<div className="min-h-screen flex items-center justify-center">
<div className="text-center">
<div className="text-4xl mb-4 animate-spin">โณ</div>
<p className="text-gray-600">Loading...</p>
</div>
</div>
)
}
const selectedOption = poll?.options.find(opt => opt.id === optionId)
return (
<div className="min-h-screen pb-20">
<Header />
<main className="max-w-4xl mx-auto p-4 space-y-6">
{/* Success Card */}
<div className="bg-gradient-to-br from-celo-green to-celo-yellow rounded-2xl p-8 shadow-2xl text-center text-white">
<div className="text-6xl mb-4 animate-bounce">๐ŸŽ‰</div>
<h1 className="text-3xl font-bold mb-2">Vote Cast Successfully!</h1>
<p className="text-white/90 mb-6">
Your vote has been recorded on the Celo blockchain
</p>
<div className="bg-white/20 backdrop-blur-sm rounded-xl p-6 mb-6">
<p className="text-sm opacity-90 mb-2">You voted</p>
<div className="flex items-center justify-center gap-2 text-2xl font-bold mb-1">
<span>{selectedOption?.emoji}</span>
<span>{selectedOption?.text}</span>
</div>
<p className="text-lg font-semibold">{formatCUSD(amount)}</p>
</div>
<div className="bg-white/10 rounded-lg p-4">
<p className="text-sm opacity-90">
Come back when the poll closes to see if you won!
</p>
</div>
</div>
{/* Share Section */}
<div className="bg-white rounded-2xl p-6 shadow-xl">
<h2 className="text-xl font-bold text-gray-800 mb-3">๐Ÿ“ฃ Share & Earn</h2>
<p className="text-gray-600 mb-4">
Share this poll with your friends on Farcaster and earn 0.01 cUSD when they vote!
</p>
<button
onClick={() => {
const shareUrl = `${process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'}/poll/${pollId}`
const text = `I just voted on PollCelo! ๐ŸŽฏ\n\n${poll?.question}\n\nVote with cUSD and win rewards! ๐Ÿ’ฐ`
// Open Warpcast composer
window.open(
`https://warpcast.com/~/compose?text=${encodeURIComponent(text)}&embeds[]=${encodeURIComponent(shareUrl)}`,
'_blank'
)
}}
className="w-full bg-gradient-to-r from-purple-500 to-purple-700 text-white font-bold py-3 px-6 rounded-xl shadow-md hover:shadow-lg transition-all"
>
๐Ÿ”— Share on Warpcast
</button>
</div>
{/* Actions */}
<div className="flex gap-3">
<button
onClick={() => router.push(`/poll/${pollId}`)}
className="flex-1 bg-white text-gray-700 font-semibold py-3 px-6 rounded-xl shadow-md hover:shadow-lg transition-all"
>
๐Ÿ“Š View Poll
</button>
<button
onClick={() => router.push('/history')}
className="flex-1 bg-celo-green text-white font-semibold py-3 px-6 rounded-xl shadow-md hover:shadow-lg transition-all"
>
๐Ÿ“œ History
</button>
</div>
</main>
</div>
)
}