source: jobvista-frontend/src/App.js@ 0f0add0

main
Last change on this file since 0f0add0 was befb988, checked in by 223021 <daniel.ilievski.2@…>, 2 weeks ago

Added an edit profile page for both job seekers and recruiters, where they can upload profile pictures/company logos and edit their profile data. Added profile page specifically for recruiters. Refactored existing code.

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[d8b6c91]1import logo from './logo.svg';
2import './App.css';
[b248810]3import {useDispatch, useSelector} from "react-redux";
[d8b6c91]4import {BrowserRouter} from "react-router-dom";
5import {Header} from "./views/static/Header";
[befb988]6import RoutesConfig from "./auth/RoutesConfig";
7import React, {useEffect, useState} from "react";
[d8b6c91]8import {AuthActions} from "./redux/actions/authActions";
9import {AUTH_TOKEN} from "./axios/axiosInstance";
[b248810]10import {jwtDecode} from "jwt-decode";
11import {NoAccess} from "./views/static/NoAccess";
[befb988]12import {Loading} from "./views/static/Loading";
13import {ToastContainer} from "react-toastify";
[d8b6c91]14
15function App() {
16 const dispatch = useDispatch();
17
18 useEffect(() => {
19 dispatch(AuthActions.updateToken(localStorage.getItem(AUTH_TOKEN)))
20 }, [dispatch])
21
[b248810]22 const [user, setUser] = useState(null);
23 const [loading, setLoading] = useState(true);
[befb988]24 const [minimumLoadingTime, setMinimumLoadingTime] = useState(true);
25
[b248810]26 const auth = useSelector(state => state.auth);
27
[befb988]28 useEffect(() => {
29 // Simulate a minimum loading time of 1 second
30 const timer = setTimeout(() => {
31 setMinimumLoadingTime(false);
32 }, 1000);
33
34 // Clear timeout if component unmounts
35 return () => clearTimeout(timer);
36 }, []);
37
[b248810]38 useEffect(() => {
39 const token = localStorage.getItem(AUTH_TOKEN);
40 if (token !== null) {
41 try {
42 const decodedToken = jwtDecode(token);
43 setUser({
44 name: decodedToken.name,
45 role: decodedToken.role,
[befb988]46 hasAccess: decodedToken.access,
47 id: decodedToken.id
[b248810]48 });
49 setLoading(false);
50 } catch (error) {
51 console.error('Failed to decode token', error);
52 setLoading(false);
53 }
54 } else {
55 setLoading(false);
56 }
57 }, [auth]);
58
[befb988]59 if (loading || minimumLoadingTime) {
60 return <Loading />; // Replace LoadingSpinner with your loading indicator component
[b248810]61 }
62
[d8b6c91]63 return (
64 <div className="App">
65 <BrowserRouter>
[b248810]66 {user === null ? (
67 <>
68 <Header />
69 <RoutesConfig />
70 </>
71 ) : user.hasAccess ? (
72 <>
73 <Header />
74 <RoutesConfig />
[befb988]75 {/*<Loading/>*/}
[b248810]76 </>
77 ) : (
78 <NoAccess user={user}/>
79 )}
[d8b6c91]80 </BrowserRouter>
[befb988]81 <ToastContainer/>
[d8b6c91]82 </div>
83 );
84}
85
86export default App;
Note: See TracBrowser for help on using the repository browser.