Skip to content

Commit

Permalink
Merge pull request #56 from mewanDimalsha/main
Browse files Browse the repository at this point in the history
some bugs in the backend-app.js are fixed
  • Loading branch information
mewanDimalsha authored Jun 24, 2024
2 parents 60bd125 + 0d92301 commit c62f977
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 507 deletions.
102 changes: 36 additions & 66 deletions Frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { BrowserRouter, Routes, Route, Navigate } from "react-router-dom";
import { useEffect, useState } from "react"; // Import useEffect
// App.tsx
import { BrowserRouter, Routes, Route } from "react-router-dom";
import { useEffect, useState } from "react";
import { useDisclosure } from "@chakra-ui/react";
import { GoogleLogin } from "@react-oauth/google";
import jwt_decode from "jwt-decode";
import axios from "axios";

import StudentHome from "./Pages/StudentHome";
import Admin from "./Pages/Admin/Admin";
import AdminWrapper from "./Pages/Admin/AdminWrapper";
import AdminHome1 from "./Pages/Admin/AdminHome1";
import AdminHome2 from "./Pages/Admin/AdminHome2";
import AdminHome3 from "./Pages/Admin/AdminHome3";
Expand All @@ -18,96 +16,68 @@ import LoginModal from "./components/LoginModal";

import { DUserTokenInterface } from "./models/TokenMoodel";
import { PreviousRequest } from "./models/PreviousRequest";
// import Yes from "./Pages/Yes";

function App() {
const { isOpen, onOpen, onClose } = useDisclosure();
const [userToken, setUserToken] = useState<DUserTokenInterface | null>(null);
const [previousRequest, setPreviousRequest] = useState<PreviousRequest | null>(null);
const [previousRequest, setPreviousRequest] =
useState<PreviousRequest | null>(null);
const [error, setError] = useState<string | null>(null);

useEffect(() => {
const fetchPreviousRequest = async () => {
try {
const response = await axios.get(
`http://localhost:5000/findrequest/${userToken?.email}`
);
setPreviousRequest(response.data);
} catch (error) {
setError("Error fetching previous request data");
console.error(error);
}
};

if (userToken == null) {
onOpen();
} else {
onClose();
console.log("Closed the modal");
axios
.get(`http://localhost:5000/findrequest/${userToken.email}`)
.then((response) => {
setPreviousRequest(response.data);
console.log(response.data);
});
fetchPreviousRequest();
}
}, [userToken, onOpen, onClose]);


return (
<BrowserRouter>
<Routes>
<Route
index
element={
<>
<LoginModal isOpen={isOpen} onClose={onClose} setUserToken={setUserToken} /> {/* <Modal
closeOnOverlayClick={false}
<LoginModal
isOpen={isOpen}
onClose={onClose}
size="sm"
isCentered
>
<ModalOverlay bg="blackAlpha.300" backdropFilter="blur(3px) " />
<ModalContent p="5">
<ModalHeader
display="flex"
flexDirection="column"
alignItems="center"
justifyContent="center"
p = "2"
>
ACES Project Fund Requests
</ModalHeader>
<ModalBody
display="flex"
flexDirection="column"
alignItems="center"
justifyContent="center"
>
<Text pb="4" fontSize="sm">
You need to login with your eng email
</Text>
<GoogleLogin
onSuccess={(credentialResponse) => {
console.log(credentialResponse);
var decodedUserToken: DUserTokenInterface = jwt_decode(
credentialResponse.credential!
);
setUserToken(decodedUserToken);
console.log(decodedUserToken);
onClose();
}}
onError={() => {
onOpen();
console.log("Login Failed");
}}
/>
</ModalBody>
</ModalContent>
</Modal> */}
setUserToken={setUserToken}
/>
{error && <p>{error}</p>}
<StudentHome
previousRequest={previousRequest}
userToken={userToken}
/>
</>
}
/>
{/* <Route path="/" element={<Navigate to="/student" replace />} /> */}
<Route path="/student" element={<StudentHome previousRequest={previousRequest} userToken={userToken} />} />
<Route
path="/student"
element={
<StudentHome
previousRequest={previousRequest}
userToken={userToken}
/>
}
/>
<Route path="/admin" element={<Admin />} />
<Route path="/admin1" element={<AdminHome1 />} />
<Route path="/admin1/:id" element={<AdminHome1 />} />{" "}
{/* Use :id for dynamic parameter */}
<Route path="/admin2" element={<AdminHome2 />} />
<Route path="/admin3" element={<AdminHome3 />} />
<Route path="/yes" element={<Yes />} />
Expand All @@ -116,6 +86,6 @@ function App() {
</Routes>
</BrowserRouter>
);
}
}

export default App
export default App;
Loading

0 comments on commit c62f977

Please sign in to comment.