Skip to content

Commit

Permalink
fix: QRcode scan for search page , benefit details --- upon proceed -…
Browse files Browse the repository at this point in the history
…-- 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 <[email protected]>
  • Loading branch information
sagarkoshti1990 and sagar authored Dec 3, 2024
1 parent 6fcb6e0 commit d335202
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 35 deletions.
5 changes: 5 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ",
Expand Down
3 changes: 2 additions & 1 deletion src/locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "आवेदन करने के लिए लॉगिन करें।"
}
10 changes: 10 additions & 0 deletions src/routes/GuestRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@ 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 = [
{
path: "/signup",
component: Signup,
},
{
path: "/explorebenefits",
component: ExploreBenefits,
},
{
path: "/benefits/:id",
component: BenefitsDetails,
},
{
path: "/signin",
component: SignIn,
Expand Down
28 changes: 16 additions & 12 deletions src/screens/benefit/Benefits.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -128,6 +131,7 @@ const ExploreBenefits: React.FC = () => {
],
}}
isSearchbar={true}
isMenu={Boolean(localStorage.getItem("authToken"))}
>
{error && (
<Modal isOpen={!!error} onClose={() => setError(null)}>
Expand Down
59 changes: 37 additions & 22 deletions src/screens/benefit/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
useDisclosure,
HStack,
Icon,
Spinner,
Modal,
ModalOverlay,
ModalContent,
Expand Down Expand Up @@ -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<any> } }).data?.responses?.[0]
Expand All @@ -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);
}
Expand Down Expand Up @@ -260,7 +261,10 @@ const BenefitsDetails: React.FC = () => {
}

return (
<Layout _heading={{ heading: item?.descriptor?.name || "", handleBack }}>
<Layout
_heading={{ heading: item?.descriptor?.name || "", handleBack }}
isMenu={Boolean(localStorage.getItem("authToken"))}
>
<Box className="card-scroll invisible_scroll">
<Box maxW="2xl" m={4}>
<Heading size="md" color="#484848" fontWeight={500}>
Expand Down Expand Up @@ -306,16 +310,27 @@ const BenefitsDetails: React.FC = () => {
<ListItem key={document}>{document}</ListItem>
))}
</UnorderedList>
<CommonButton
mt={6}
onClick={handleConfirmation}
label={
isApplied
? t("BENEFIT_DETAILS_APPLICATION_SUBMITTED")
: t("BENEFIT_DETAILS_PROCEED_TO_APPLY")
}
isDisabled={isApplied}
/>
{localStorage.getItem("authToken") ? (
<CommonButton
mt={6}
onClick={handleConfirmation}
label={
isApplied
? t("BENEFIT_DETAILS_APPLICATION_SUBMITTED")
: t("BENEFIT_DETAILS_PROCEED_TO_APPLY")
}
isDisabled={isApplied}
/>
) : (
<CommonButton
mt={6}
onClick={() => {
localStorage.setItem("redirectUrl", window.location.href);
navigate("/signin");
}}
label={t("BENEFIT_DETAILS_LOGIN_TO_APPLY")}
/>
)}
</Box>
</Box>

Expand Down

0 comments on commit d335202

Please sign in to comment.