Skip to content

Commit

Permalink
Fix useRouter for confirmation (#1114)
Browse files Browse the repository at this point in the history
* Fix useRouter for confirmation

* Add profile and router as dependencies to useEffect

* Minor refactoring for router query
  • Loading branch information
software-project committed Apr 8, 2021
1 parent c2cc9c1 commit 8e911ab
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions sites/public/src/ConfirmationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const ConfirmationModal = (props: ConfirmationModalProps) => {
const [openModal, setOpenModal] = useState(false)
const [modalMessage, setModalMessage] = useState(null)
const router = useRouter()
const { token } = router.query
/* Form Handler */
// This is causing a linting issue with unbound-method, see open issue as of 10/21/2020:
// https://github.com/react-hook-form/react-hook-form/issues/2887
Expand All @@ -46,8 +45,8 @@ const ConfirmationModal = (props: ConfirmationModalProps) => {
}

useEffect(() => {
if (token && !profile) {
confirmAccount(token.toString())
if (router?.query?.token && !profile) {
confirmAccount(router.query.token.toString())
.then(() => {
setSiteAlertMessage(t(`authentication.createAccount.accountConfirmed`), "success")

Expand All @@ -60,7 +59,7 @@ const ConfirmationModal = (props: ConfirmationModalProps) => {
}
// This ensures useEffect is called only once
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
}, [router, profile])

return (
<Modal
Expand Down

0 comments on commit 8e911ab

Please sign in to comment.