1+ 'use client'
2+
3+ import { SignPetitionButton } from '@/app/petitions/components/SignPetitionButton'
4+ import { useEffect , useState } from 'react'
5+ import { useSession } from 'next-auth/react'
6+ import { checkPetitionSignature } from '@/app/petitions/petitionActions'
7+
8+ const neoBrutalistStyles = {
9+ button : "border-4 border-black p-4 text-lg font-bold transition-all hover:translate-x-1 hover:translate-y-1 hover:shadow-none bg-white shadow-[8px_8px_0px_0px_rgba(0,0,0,1)] text-black min-w-[200px] min-h-[60px] rounded-none" ,
10+ signed : "border-4 border-black p-4 text-lg font-bold bg-pink-400 shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] hover:bg-pink-500 text-white min-w-[200px] min-h-[60px] rounded-none"
11+ }
12+
13+ export function DFDASignPetitionButton ( ) {
14+ const { data : session } = useSession ( )
15+ const [ hasSigned , setHasSigned ] = useState ( false )
16+
17+ useEffect ( ( ) => {
18+ let mounted = true
19+
20+ async function checkSignature ( ) {
21+ if ( ! session ?. user ?. id ) {
22+ if ( mounted ) setHasSigned ( false )
23+ return
24+ }
25+
26+ try {
27+ const hasSignature = await checkPetitionSignature ( 'right-to-trial-act' )
28+ if ( mounted ) setHasSigned ( hasSignature )
29+ } catch ( error ) {
30+ console . error ( 'Failed to check signature status:' , error )
31+ if ( mounted ) setHasSigned ( false )
32+ }
33+ }
34+
35+ checkSignature ( )
36+
37+ return ( ) => {
38+ mounted = false
39+ }
40+ } , [ session ?. user ?. id ] )
41+
42+ return (
43+ < SignPetitionButton
44+ petitionId = "right-to-trial-act"
45+ hasSigned = { hasSigned }
46+ status = "ACTIVE"
47+ className = { neoBrutalistStyles . button }
48+ signedClassName = { neoBrutalistStyles . signed }
49+ onSignatureChange = { ( ) => {
50+ // Toggle the hasSigned state immediately for better UX
51+ setHasSigned ( prev => ! prev )
52+ } }
53+ />
54+ )
55+ }
0 commit comments