-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Routing issue resolved and response key mapping changes (#32)
* Routing issue resolved * response key mapping changes
- Loading branch information
1 parent
9e46c95
commit f59d28f
Showing
18 changed files
with
186 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.