Skip to content

Commit

Permalink
Update eligibility toast
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgxvii committed Sep 12, 2024
1 parent 787c3c7 commit 78e6a0e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pages/eligibility.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const Eligibility: NextPage = () => {
const IS_ELIGIBLE = "yes"
const router = useRouter()
const [eligibility, setEligibility] = useState<boolean>()
const [toastVisible, setToastVisible] = useState(false)
const questions: any[] = eligibilityQuestions

const checkEligibility = async (values: any) => {
Expand All @@ -36,18 +37,25 @@ const Eligibility: NextPage = () => {
})

const onSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
if (toastVisible == true) return

event.preventDefault()
const formData = new FormData(event.currentTarget)
const formValues = Object.fromEntries(formData.entries())
const eligible = await checkEligibility(formValues)
setEligibility(eligible)

if (eligible) {
setToastVisible(true)
sessionStorage.setItem("eligible", JSON.stringify(formValues))
toast.success("Congrats, you're eligible!", {
autoClose: 1000,
position: toast.POSITION.TOP_CENTER,
closeButton: false,
onClose: () => router.replace("/registration"),
onClose: () => {
setToastVisible(false)
router.replace("/registration")
},
})
}
}
Expand Down

0 comments on commit 78e6a0e

Please sign in to comment.