Skip to content

Commit

Permalink
Routing issue resolved and response key mapping changes (#32)
Browse files Browse the repository at this point in the history
* Routing issue resolved

* response key mapping changes
  • Loading branch information
vidyaaKhandekar authored Nov 27, 2024
1 parent 9e46c95 commit f59d28f
Show file tree
Hide file tree
Showing 18 changed files with 186 additions and 117 deletions.
70 changes: 67 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,80 @@
// import { ChakraProvider } from "@chakra-ui/react";
// import theme from "./theme";
// import { AuthProvider } from "./utils/context/checkToken";
// import AppRouter from "./routes/AppRouter";

// function App() {
// return (
// <ChakraProvider theme={theme}>
// <AuthProvider>
// <AppRouter />
// </AuthProvider>
// </ChakraProvider>
// );
// }

// export default App;

import { ChakraProvider } from "@chakra-ui/react";
import theme from "./theme";
import authRoutes from "./routes/AuthRoutes";
import guestRoutes from "./routes/GuestRoutes";
import { Suspense, useEffect, useState } from "react";
import Loader from "./components/common/Loader";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import { useKeycloak } from "@react-keycloak/web";
import { AuthProvider } from "./utils/context/checkToken";
import AppRouter from "./routes/AppRouter";
import "./assets/styles/App.css";

function App() {
const [loading, setLoading] = useState(true);
const [routes, setRoutes] = useState<
{ path: string; component: React.ElementType }[]
>([]);
const [token, setToken] = useState(localStorage.getItem("authToken"));
const { keycloak } = useKeycloak();

useEffect(() => {
if (!token && keycloak?.token) {
localStorage.setItem("authToken", keycloak.token);
setToken(keycloak.token);
} else {
setToken(localStorage.getItem("authToken"));
}
if (token || keycloak?.token) {
setRoutes(authRoutes);
} else {
setRoutes(guestRoutes);
}
setLoading(false);
}, [keycloak?.token]);

if (loading) {
return (
<ChakraProvider theme={theme}>
<Loader />
</ChakraProvider>
);
}

return (
<ChakraProvider theme={theme}>
<AuthProvider>
<AppRouter />
<Suspense fallback={<Loader />}>
<Router>
<Routes>
{routes?.map((item, index) => (
<Route
key={item?.path + index}
path={item?.path}
element={<item.component />}
/>
))}
</Routes>
</Router>
</Suspense>
</AuthProvider>
</ChakraProvider>
);
}

export default App;
2 changes: 1 addition & 1 deletion src/components/WebView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface FormData {
name?: string;
current_class?: string;
previous_year_marks?: string;
phone_number?: string;
phoneNumber?: string;
username?: string;
email?: string;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/UserDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface UserData {

// Contact Information
email?: string;
phone_number?: string;
phoneNumber?: string;

// Educational Information
class?: string;
Expand Down
4 changes: 3 additions & 1 deletion src/components/common/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface CustomButton {
width?: string;
label?: string;
isDisabled?: boolean;
variant?: string;
}

const CommonButton: React.FC<CustomButton> = ({
Expand All @@ -15,10 +16,11 @@ const CommonButton: React.FC<CustomButton> = ({
width = "100%",
label = "Submit",
isDisabled = false,
variant = "solid",
}) => {
return (
<Button
className="custom-btn"
className={variant === "solid" ? "custom-btn" : "outline-custom-btn"}
type="submit"
mt={mt}
width={width}
Expand Down
16 changes: 8 additions & 8 deletions src/components/common/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SearchBar from "./SearchBar";
interface LayoutProps {
isScrollable?: boolean;
loading?: boolean;
children: React.ReactNode;
children?: React.ReactNode;
isMenu?: boolean;
isNavbar?: boolean;
afterHeader?: React.ReactNode;
Expand Down Expand Up @@ -46,13 +46,13 @@ const Layout: React.FC<LayoutProps> = ({
}) => {
const { onSearch } = _heading;

// if (loading) {
// return (
// <Box display="flex" justifyContent="center" alignItems="center">
// <Spinner size="lg" />
// </Box>
// );
// }
if (loading) {
return (
<Box display="flex" justifyContent="center" alignItems="center">
<Spinner size="lg" />
</Box>
);
}

return (
<Box>
Expand Down
24 changes: 2 additions & 22 deletions src/components/common/layout/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,9 @@ const Navbar: React.FC<{ isMenu?: boolean }> = ({ isMenu = true }) => {
const { t } = useTranslation();
const { keycloak } = useKeycloak();
const handleLogout = async () => {
localStorage.removeItem("authtoken");
navigate("/");
localStorage.removeItem("authToken");
keycloak.logout();

// const token = (await getToken()) as {
// token: string;
// refreshToken: string;
// } | null;

// if (token?.token && token?.refreshToken) {
// try {
// const response = await logoutUser(token.token, token.refreshToken); // Call the logout function
// removeContextData();
// checkToken();
// if (response.statusCode === 200) {
// setSuccess(t("NAVBAR_LOGGED_OUT_SUCCESSFULLY"));
// navigate("/signin");
// }
// } catch (error) {
// console.error("Logout failed:", (error as Error).message);
// }
// } else {
// console.error("No tokens found, user is not logged in");
// }
};

return (
Expand Down
2 changes: 1 addition & 1 deletion src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
// import '/styles/index.css'

import keycloak from "./keycloak";
import { ReactKeycloakProvider } from "@react-keycloak/web";
createRoot(document.getElementById("root")!).render(
Expand Down
47 changes: 47 additions & 0 deletions src/routes/AuthRoutes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { lazy } from "react";

const ExploreBenefits = lazy(() => import("../screens/benefit/Benefits"));
const BenefitsDetails = lazy(() => import("../screens/benefit/Details"));
const Preview = lazy(() => import("../screens/application/Preview"));
const MyApplications = lazy(
() => import("../screens/application/ApplicationStatus")
);
const UploadDocuments = lazy(
() => import("../components/common/layout/UploadDocuments")
);
const Home = lazy(() => import("../screens/Home"));
const UserProfile = lazy(() => import("../screens/UserProfile"));

const routes = [
{
path: "/uploaddocuments",
component: UploadDocuments,
},

{
path: "/userprofile",
component: UserProfile,
},
{
path: "/explorebenefits",
component: ExploreBenefits,
},
{
path: "/benefitsdetails/:id",
component: BenefitsDetails,
},
{
path: "/previewapplication/:id",
component: Preview,
},
{
path: "/applicationStatus",
component: MyApplications,
},
{
path: "*",
component: Home,
},
];

export default routes;
16 changes: 16 additions & 0 deletions src/routes/GuestRoutes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { lazy } from "react";

const Splash = lazy(() => import("../screens/auth/Splash"));
const Signup = lazy(() => import("../screens/auth/SignUp"));

const routes = [
{
path: "/signup",
component: Signup,
},
{
path: "*",
component: Splash,
},
];
export default routes;
4 changes: 1 addition & 3 deletions src/screens/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useContext, useEffect, useState } from "react";
import { Box, VStack } from "@chakra-ui/react";

import { getUser, getDocumentsList } from "../services/auth/auth";
import { useNavigate } from "react-router-dom";
import CommonButton from "../components/common/button/Button";
Expand All @@ -9,7 +8,7 @@ import { AuthContext } from "../utils/context/checkToken";
import { useTranslation } from "react-i18next";
import DocumentList from "../components/DocumentList";
import { useKeycloak } from "@react-keycloak/web";

import "../assets/styles/App.css";
import UploadDocumentEwallet from "../components/common/UploadDocumentEwallet";

const Home: React.FC = () => {
Expand Down Expand Up @@ -59,7 +58,6 @@ const Home: React.FC = () => {
_heading={{
beneficiary: true,
heading: `${userData?.firstName || ""} ${userData?.lastName || ""}`,
subHeading: t("PROFILE_LOGGED_IN_WITH_E_Wallet"),
label: keycloak.tokenParsed?.preferred_username,
}}
>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const UserProfile: React.FC = () => {
lineHeight="24px"
color="#433E3F"
>
{userData?.phone_number || "Phone No"}
{userData?.phoneNumber || "Phone No"}
</Text>
</VStack>
</HStack>
Expand Down
12 changes: 7 additions & 5 deletions src/screens/application/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ interface UserData {
}

const myApplicationData: ApplicationField[] = [
{ id: 1, label: "Full Name", value: "firstName" },
{ id: 2, label: "Last Name", value: "lastName" },
{ id: 1, label: "Full Name", value: "first_name" },
{ id: 2, label: "Last Name", value: "last_name" },
{ id: 3, label: "Gender", value: "gender" },
{ id: 4, label: "Age", value: "age" },
{ id: 5, label: "Samagra Id", value: "samagraId" },
{ id: 5, label: "Samagra Id", value: "samagra_id" },
{ id: 6, label: "Class", value: "class" },
{ id: 7, label: "Adhaar Card", value: "aadhaar" },
{ id: 8, label: "Marks", value: "previousYearMarks" },
{ id: 8, label: "Marks", value: "previous_year_marks" },
{ id: 9, label: "Caste", value: "caste" },
{ id: 10, label: "School Name", value: "currentSchoolName" },
{ id: 10, label: "School Name", value: "current_school_name" },
];

const Preview: React.FC = () => {
Expand Down Expand Up @@ -63,6 +63,8 @@ const Preview: React.FC = () => {
return;
}
const result = await getApplicationDetails(id);
console.log("in preview", result);

setUserData(result?.data?.application_data);
setBenefitName(result?.data?.external_application_id);
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions src/screens/auth/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const Signup: React.FC = () => {
if (otpToken) {
setLoading(false);
const verifyOTPResponse = await verifyOTP({
phone_number: formattedMobile,
phoneNumber: formattedMobile,
otp: Number(userDetails.otp),
token: otpToken,
});
Expand All @@ -132,7 +132,7 @@ const Signup: React.FC = () => {
const response = await registerUser({
firstName: userDetails.firstName,
lastName: userDetails.lastName,
phone_number: userDetails.mobile,
phoneNumber: userDetails.mobile,
});
if (response && response?.statusCode === 200) {
setLoading(false);
Expand Down
Loading

0 comments on commit f59d28f

Please sign in to comment.