forked from ashwinpra/gyfe
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: frontend-backend finally working together :D
- Loading branch information
1 parent
c5a043f
commit 9779866
Showing
27 changed files
with
853 additions
and
1,131 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,59 +1,20 @@ | ||
import React, { useState, useContext } from "react"; | ||
import { | ||
BrowserRouter as Router, | ||
Routes, | ||
Route, | ||
Navigate, | ||
} from "react-router-dom"; | ||
import { UserContext } from "./app-context/user-context"; | ||
import "./styles/App.scss"; | ||
import React from "react"; | ||
import Header from "./components/Header"; | ||
import Footer from "./components/Footer"; | ||
import Electives from "./components/Electives"; | ||
import MultiForm from "./components/MultiForm"; | ||
import About from "./components/About"; | ||
import Modal from "./components/Modal"; | ||
import { Toaster } from "react-hot-toast"; | ||
|
||
const App: React.FC = () => { | ||
const [openModal, setOpenModal] = useState(false); | ||
const { user } = useContext(UserContext); | ||
|
||
// const [isLoggedIn, setLogin] = useState<boolean>(() => { | ||
// const savedLoginstate = sessionStorage.getItem('loginStatus'); | ||
// return savedLoginstate == 'true'; // by default false if session not stored | ||
// }); | ||
|
||
// useEffect(() => { | ||
// sessionStorage.setItem('loginStatus',isLoggedIn.toString()); | ||
// }, [isLoggedIn]); | ||
|
||
// const updateStatus = () => { // Prop to control login status | ||
// setLogin(true); | ||
// } | ||
|
||
return ( | ||
<Router> | ||
<div className="App"> | ||
<Header /> | ||
<Routes> | ||
<Route path="/login" element={<MultiForm />} /> | ||
<Route | ||
path="/" | ||
element={ | ||
!!sessionStorage.getItem("ssoToken") ? ( | ||
<Electives /> | ||
) : ( | ||
<Navigate to="/login" /> | ||
) | ||
} | ||
/> | ||
</Routes> | ||
<About setOpenModal={setOpenModal} /> | ||
{openModal && <Modal closeModal={setOpenModal} />} | ||
<Footer /> | ||
</div> | ||
</Router> | ||
); | ||
return ( | ||
<> | ||
<Toaster position="bottom-center" /> | ||
<div> | ||
<Header /> | ||
<MultiForm /> | ||
</div> | ||
<Footer /> | ||
</> | ||
); | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React, { useState, createContext, useContext } from "react"; | ||
|
||
interface IProps { | ||
children: React.ReactNode; | ||
} | ||
interface IUser { | ||
rollNo: string; | ||
password: string; | ||
securityQuestion: string; | ||
securityAnswer: string; | ||
ssoToken: string | null; | ||
sessionToken: string | null; | ||
} | ||
interface IAuth { | ||
user: IUser; | ||
currentStep: number; | ||
} | ||
interface IContext { | ||
authState: IAuth; | ||
setAuth: React.Dispatch<React.SetStateAction<IAuth>>; | ||
logout: () => void; | ||
} | ||
|
||
const DEFAULT_USER: IUser = { | ||
rollNo: "", | ||
password: "", | ||
securityQuestion: "", | ||
securityAnswer: "", | ||
ssoToken: sessionStorage.getItem("ssoToken"), | ||
sessionToken: sessionStorage.getItem("sessionToken"), | ||
}; | ||
|
||
export const AppContext = createContext<IContext | null>(null); | ||
|
||
export const AppProvider: React.FC<IProps> = ({ children }) => { | ||
const [authState, setAuth] = useState<IAuth>({ | ||
user: DEFAULT_USER, | ||
currentStep: 0, | ||
}); | ||
|
||
const logout = () => { | ||
sessionStorage.removeItem("ssoToken"); | ||
sessionStorage.removeItem("sessionToken"); | ||
setAuth({ user: DEFAULT_USER, currentStep: 0 }); | ||
}; | ||
|
||
return ( | ||
<AppContext.Provider value={{ authState, setAuth, logout }}> | ||
{children} | ||
</AppContext.Provider> | ||
); | ||
}; | ||
|
||
export const useAppContext = () => { | ||
const context = useContext(AppContext); | ||
if (!context) { | ||
throw new Error("useAppContext must be used within an AppProvider"); | ||
} | ||
return { | ||
...context.authState, | ||
setAuth: context.setAuth, | ||
logout: context.logout, | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.