forked from wishonia/wishonia
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor petition-related components and actions
Consolidate petition actions into a single file and update imports accordingly. Deleted redundant components and cleaned up petition handling logic for better maintainability. Took 30 minutes
- Loading branch information
Showing
14 changed files
with
209 additions
and
78 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
app/dfda/right-to-trial-act/components/DFDASignPetitionButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
'use client' | ||
|
||
import { SignPetitionButton } from '@/app/petitions/components/SignPetitionButton' | ||
import { useEffect, useState } from 'react' | ||
import { useSession } from 'next-auth/react' | ||
import { checkPetitionSignature } from '@/app/petitions/petitionActions' | ||
|
||
const neoBrutalistStyles = { | ||
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", | ||
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" | ||
} | ||
|
||
export function DFDASignPetitionButton() { | ||
const { data: session } = useSession() | ||
const [hasSigned, setHasSigned] = useState(false) | ||
|
||
useEffect(() => { | ||
let mounted = true | ||
|
||
async function checkSignature() { | ||
if (!session?.user?.id) { | ||
if (mounted) setHasSigned(false) | ||
return | ||
} | ||
|
||
try { | ||
const hasSignature = await checkPetitionSignature('right-to-trial-act') | ||
if (mounted) setHasSigned(hasSignature) | ||
} catch (error) { | ||
console.error('Failed to check signature status:', error) | ||
if (mounted) setHasSigned(false) | ||
} | ||
} | ||
|
||
checkSignature() | ||
|
||
return () => { | ||
mounted = false | ||
} | ||
}, [session?.user?.id]) | ||
|
||
return ( | ||
<SignPetitionButton | ||
petitionId="right-to-trial-act" | ||
hasSigned={hasSigned} | ||
status="ACTIVE" | ||
className={neoBrutalistStyles.button} | ||
signedClassName={neoBrutalistStyles.signed} | ||
onSignatureChange={() => { | ||
// Toggle the hasSigned state immediately for better UX | ||
setHasSigned(prev => !prev) | ||
}} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
app/dfda/right-to-trial-act/components/SignPetitionButton.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.