From d3352023765816e6a6ad7f14f02dc768ad3df611 Mon Sep 17 00:00:00 2001 From: sagar takle Date: Tue, 3 Dec 2024 14:37:56 +0530 Subject: [PATCH] fix: QRcode scan for search page , benefit details --- upon proceed --- ask for login, come back to same screen again (#55) * fix: QRcode scan for search page , benefit details --- upon proceed --- ask for login, come back to same screen again * fix: add routes --------- Co-authored-by: sagar --- src/App.tsx | 5 +++ src/locales/en.json | 1 + src/locales/hi.json | 3 +- src/routes/GuestRoutes.tsx | 10 ++++++ src/screens/benefit/Benefits.tsx | 28 ++++++++------- src/screens/benefit/Details.tsx | 59 ++++++++++++++++++++------------ 6 files changed, 71 insertions(+), 35 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 6977eb4..b2f8c50 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -21,6 +21,11 @@ function App() { useEffect(() => { if (token) { setRoutes(authRoutes); + const redirectUrl = localStorage.getItem("redirectUrl"); + if (redirectUrl) { + window.location.href = redirectUrl; + localStorage.removeItem("redirectUrl"); + } } else { setRoutes(guestRoutes); } diff --git a/src/locales/en.json b/src/locales/en.json index 795a245..68b47ee 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -55,6 +55,7 @@ "BENEFIT_DETAILS_MANDATORY_DOCUMENTS": "Mandatory Documents", "BENEFIT_DETAILS_APPLICATION_SUBMITTED": "Application Already Submitted", "BENEFIT_DETAILS_PROCEED_TO_APPLY": "Proceed To Apply", + "BENEFIT_DETAILS_LOGIN_TO_APPLY": "Login To Apply", "SUBMIT_DIALOGUE_HEADING_TEXT": "Application Submitted", "SUBMIT_DIALOGUE_SUBHEADING_TEXT": "Confirmation", "SUBMIT_DIALOGUE_CONTENT_TEXT": "Your application to the ", diff --git a/src/locales/hi.json b/src/locales/hi.json index d729c2e..bfceb12 100644 --- a/src/locales/hi.json +++ b/src/locales/hi.json @@ -4,5 +4,6 @@ "ENGLISH": "अंग्रेजी", "HINDI": "हिन्दी", "SELECT_LANGUAGE": "भाषा चुनें", - "SIGN_IN/SIGN_UI_WITH_YOUR_E-WALLET": "अपने ई-वॉलेट से साइन इन/साइन अप करें" + "SIGN_IN/SIGN_UI_WITH_YOUR_E-WALLET": "अपने ई-वॉलेट से साइन इन/साइन अप करें", + "BENEFIT_DETAILS_LOGIN_TO_APPLY": "आवेदन करने के लिए लॉगिन करें।" } diff --git a/src/routes/GuestRoutes.tsx b/src/routes/GuestRoutes.tsx index 6d25062..1535746 100644 --- a/src/routes/GuestRoutes.tsx +++ b/src/routes/GuestRoutes.tsx @@ -2,6 +2,8 @@ import { lazy } from "react"; import SignIn from "../screens/auth/SignIn"; const Splash = lazy(() => import("../screens/auth/Splash")); +const ExploreBenefits = lazy(() => import("../screens/benefit/Benefits")); +const BenefitsDetails = lazy(() => import("../screens/benefit/Details")); const Signup = lazy(() => import("../screens/auth/SignUpWithPassword")); const routes = [ @@ -9,6 +11,14 @@ const routes = [ path: "/signup", component: Signup, }, + { + path: "/explorebenefits", + component: ExploreBenefits, + }, + { + path: "/benefits/:id", + component: BenefitsDetails, + }, { path: "/signin", component: SignIn, diff --git a/src/screens/benefit/Benefits.tsx b/src/screens/benefit/Benefits.tsx index f4abcb3..e178159 100644 --- a/src/screens/benefit/Benefits.tsx +++ b/src/screens/benefit/Benefits.tsx @@ -53,21 +53,24 @@ const ExploreBenefits: React.FC = () => { useEffect(() => { const init = async () => { try { - const user = await getUser(); + const token = localStorage.getItem("authToken"); + if (token) { + const user = await getUser(); - const filters: Filter = { - "caste-eligibility": user?.data?.caste, - annualIncome: user?.data?.annualIncome, - }; + const filters: Filter = { + "caste-eligibility": user?.data?.caste, + annualIncome: user?.data?.annualIncome, + }; - const newFilter: Filter = {}; - Object.keys(filters).forEach((key) => { - if (filters[key] && filters[key] !== "") { - newFilter[key] = filters[key]?.toLowerCase() || filters[key]; - } - }); + const newFilter: Filter = {}; + Object.keys(filters).forEach((key) => { + if (filters[key] && filters[key] !== "") { + newFilter[key] = filters[key]?.toLowerCase() || filters[key]; + } + }); - setFilter(newFilter); + setFilter(newFilter); + } setInitState("no"); } catch (e) { setError(`Failed to initialize user data: ${(e as Error).message}`); @@ -128,6 +131,7 @@ const ExploreBenefits: React.FC = () => { ], }} isSearchbar={true} + isMenu={Boolean(localStorage.getItem("authToken"))} > {error && ( setError(null)}> diff --git a/src/screens/benefit/Details.tsx b/src/screens/benefit/Details.tsx index ad073be..c5cd862 100644 --- a/src/screens/benefit/Details.tsx +++ b/src/screens/benefit/Details.tsx @@ -8,7 +8,6 @@ import { useDisclosure, HStack, Icon, - Spinner, Modal, ModalOverlay, ModalContent, @@ -134,8 +133,6 @@ const BenefitsDetails: React.FC = () => { let mounted = true; const init = async () => { try { - const user = await getUser(); - const result = await getOne({ id }); const resultItem = (result as { data: { responses: Array } }).data?.responses?.[0] @@ -153,19 +150,23 @@ const BenefitsDetails: React.FC = () => { ) ?.list?.filter((e: { value: unknown }) => e.value) .map((e: { value: unknown }) => e.value) || []; - if (mounted) { setItem({ ...resultItem, document: docs }); - setAuthUser(user?.data || {}); + const token = localStorage.getItem("authToken"); + if (token) { + const user = await getUser(); + + setAuthUser(user?.data || {}); - const appResult = await getApplication({ - user_id: user?.data?.user_id, - benefit_id: id, - }); + const appResult = await getApplication({ + user_id: user?.data?.user_id, + benefit_id: id, + }); - if (appResult?.data?.applications?.length > 0) { - setIsApplied(true); + if (appResult?.data?.applications?.length > 0) { + setIsApplied(true); + } } setLoading(false); } @@ -260,7 +261,10 @@ const BenefitsDetails: React.FC = () => { } return ( - + @@ -306,16 +310,27 @@ const BenefitsDetails: React.FC = () => { {document} ))} - + {localStorage.getItem("authToken") ? ( + + ) : ( + { + localStorage.setItem("redirectUrl", window.location.href); + navigate("/signin"); + }} + label={t("BENEFIT_DETAILS_LOGIN_TO_APPLY")} + /> + )}