From a971bf85cfe26558e4f02160b22b02c7826f0c52 Mon Sep 17 00:00:00 2001 From: Adw8 Date: Thu, 25 Jul 2024 17:07:02 +0530 Subject: [PATCH] Implement useEffect for navigation --- src/App.tsx | 2 +- src/pages/UserVerification.tsx | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 9169acf..c8342e7 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -19,7 +19,7 @@ function App() { } - > + /> }> } /> { const [userId, setUserId] = useState(''); + const [applicationSubmitted, setApplicationSubmitted] = useState(false); const navigate = useNavigate(); + useEffect(()=>{ + if (applicationSubmitted) { + console.log('application is submitted'); + navigate(`/sign-with-nitro-key/${userId}`) + } + }, [applicationSubmitted, userId, navigate]); + const config = { lang: "en", //language of WebSDK texts and comments (ISO 639-1 format) theme: "light", @@ -29,17 +36,23 @@ const UserVerification = () => { const accessToken = { "token": process.env.REACT_APP_SUMSUB_TOKEN!, - "userId": "deepstack1234" + "userId": "deepstack32" } const messageHandler = (event: any, payload: any ) => { - if (event === 'idCheck.onApplicantLoaded'){ - setUserId(payload.applicantId) + if (event === 'idCheck.onApplicantLoaded') { + setUserId(payload.applicantId); } if (event === 'idCheck.onApplicantSubmitted'){ console.log('Application is submitted'); - navigate(`/sign-with-nitro-key/${userId}`); + setApplicationSubmitted(true); + } + + if (event === 'idCheck.onApplicantStatusChanged') { + if (payload.reviewStatus === 'pending') { + setApplicationSubmitted(true); + } } console.log(event);