1 | import {Navigate, Route, Router, Routes} from 'react-router-dom'
|
---|
2 | import {Dashboard} from "../views/dashboard/Dashboard";
|
---|
3 | import {SignInForm} from "../views/auth/SignInForm";
|
---|
4 | import {SignUpRecruiterForm} from "../views/auth/SignUpRecruiterForm";
|
---|
5 | import {SignUpJobSeekerForm} from "../views/auth/SignUpJobSeekerForm";
|
---|
6 | import {Workspace} from "../views/job_advertisements/JobManagementHub";
|
---|
7 | import {JobAdDetails} from "../views/job_advertisements/JobAdDetails";
|
---|
8 | import {ApplicationsByJobAd} from "../views/applications/ApplicationsByJobAd";
|
---|
9 | import {ApplicationsByJobSeeker} from "../views/applications/ApplicationsByJobSeeker";
|
---|
10 |
|
---|
11 | import {AdminPanel} from "../views/admin_panel/AdminPanel";
|
---|
12 | import {RecruiterProfile} from "../views/profiles/RecruiterProfile";
|
---|
13 | import {AboutUs} from "../views/static/AboutUs";
|
---|
14 | import {JobSeekerEditProfile} from "../views/profiles/JobSeekerEditProfile";
|
---|
15 | import {RecruiterEditProfile} from "../views/profiles/RecruiterEditProfile";
|
---|
16 | import Roles from "../enumerations/Roles";
|
---|
17 | import {useSelector} from "react-redux";
|
---|
18 | import {useEffect, useState} from "react";
|
---|
19 | import {ErrorPage} from "../views/static/ErrorPage";
|
---|
20 | import {NoAccess} from "../views/static/NoAccess";
|
---|
21 |
|
---|
22 | export const PrivateRoutes = [
|
---|
23 | {
|
---|
24 | component: AdminPanel,
|
---|
25 | path: '/admin-panel',
|
---|
26 | title: 'Admin Panel',
|
---|
27 | exact: true,
|
---|
28 | permission: [
|
---|
29 | Roles.ADMIN
|
---|
30 | ]
|
---|
31 | },
|
---|
32 | {
|
---|
33 | component: Workspace,
|
---|
34 | path: '/job-management-hub',
|
---|
35 | title: 'Job Management Hub',
|
---|
36 | exact: true,
|
---|
37 | permission: [
|
---|
38 | Roles.RECRUITER,
|
---|
39 | ]
|
---|
40 | },
|
---|
41 | {
|
---|
42 | component: ApplicationsByJobAd,
|
---|
43 | path: '/job-management-hub/applications/:advertisement_id',
|
---|
44 | title: 'Applications by Job Ad',
|
---|
45 | exact: true,
|
---|
46 | permission: [
|
---|
47 | Roles.RECRUITER
|
---|
48 | ]
|
---|
49 | },
|
---|
50 | {
|
---|
51 | component: ApplicationsByJobSeeker,
|
---|
52 | path: '/my-applications',
|
---|
53 | title: 'My Applications',
|
---|
54 | exact: true,
|
---|
55 | permission: [
|
---|
56 | Roles.JOBSEEKER
|
---|
57 | ]
|
---|
58 | },
|
---|
59 |
|
---|
60 | {
|
---|
61 | component: JobSeekerEditProfile,
|
---|
62 | path: '/job-seeker/edit-profile',
|
---|
63 | title: 'Edit Job Seeker Profile',
|
---|
64 | exact: true,
|
---|
65 | permission: [
|
---|
66 | Roles.JOBSEEKER
|
---|
67 | ]
|
---|
68 | },
|
---|
69 | {
|
---|
70 | component: RecruiterEditProfile,
|
---|
71 | path: '/recruiter/edit-profile',
|
---|
72 | title: 'Edit Recruiter Profile',
|
---|
73 | exact: true,
|
---|
74 | permission: [
|
---|
75 | Roles.RECRUITER
|
---|
76 | ]
|
---|
77 | },
|
---|
78 | ]
|
---|
79 |
|
---|
80 | export const PublicRoutes = [
|
---|
81 | {
|
---|
82 | component: Dashboard,
|
---|
83 | path: "/",
|
---|
84 | exact: true,
|
---|
85 | permission: [
|
---|
86 | Roles.RECRUITER,
|
---|
87 | Roles.JOBSEEKER,
|
---|
88 | Roles.ADMIN,
|
---|
89 | Roles.GUEST
|
---|
90 | ]
|
---|
91 | },
|
---|
92 | {
|
---|
93 | component: SignInForm,
|
---|
94 | path: '/signin',
|
---|
95 | title: 'Sign In',
|
---|
96 | exact: true,
|
---|
97 | permission: [
|
---|
98 | Roles.GUEST,
|
---|
99 | Roles.RECRUITER,
|
---|
100 | Roles.JOBSEEKER,
|
---|
101 | Roles.ADMIN
|
---|
102 | ]
|
---|
103 | },
|
---|
104 |
|
---|
105 | {
|
---|
106 | component: SignUpRecruiterForm,
|
---|
107 | path: '/signup/recruiter',
|
---|
108 | title: 'Sign Up as Recruiter',
|
---|
109 | permission: [
|
---|
110 | Roles.GUEST,
|
---|
111 | Roles.RECRUITER,
|
---|
112 | Roles.JOBSEEKER,
|
---|
113 | Roles.ADMIN
|
---|
114 | ]
|
---|
115 | },
|
---|
116 | {
|
---|
117 | component: SignUpJobSeekerForm,
|
---|
118 | path: '/signup/job-seeker',
|
---|
119 | title: 'Sign Up as Job Seeker',
|
---|
120 | permission: [
|
---|
121 | Roles.GUEST,
|
---|
122 | Roles.RECRUITER,
|
---|
123 | Roles.JOBSEEKER,
|
---|
124 | Roles.ADMIN
|
---|
125 | ]
|
---|
126 | },
|
---|
127 | {
|
---|
128 | component: JobAdDetails,
|
---|
129 | path: '/job-advertisements/:id',
|
---|
130 | title: 'Job Advertisement Details',
|
---|
131 | exact: true,
|
---|
132 | permission: [
|
---|
133 | Roles.RECRUITER,
|
---|
134 | Roles.JOBSEEKER,
|
---|
135 | Roles.ADMIN,
|
---|
136 | Roles.GUEST
|
---|
137 | ]
|
---|
138 | },
|
---|
139 | {
|
---|
140 | component: RecruiterProfile,
|
---|
141 | path: '/recruiters/:id',
|
---|
142 | title: 'Recruiter Profile',
|
---|
143 | exact: true,
|
---|
144 | permission: [
|
---|
145 | Roles.RECRUITER,
|
---|
146 | Roles.JOBSEEKER,
|
---|
147 | Roles.ADMIN,
|
---|
148 | Roles.GUEST
|
---|
149 | ]
|
---|
150 | },
|
---|
151 | {
|
---|
152 | component: AboutUs,
|
---|
153 | path: '/about',
|
---|
154 | title: 'About Us',
|
---|
155 | exact: true,
|
---|
156 | permission: [
|
---|
157 | Roles.GUEST,
|
---|
158 | Roles.RECRUITER,
|
---|
159 | Roles.JOBSEEKER,
|
---|
160 | Roles.ADMIN
|
---|
161 | ]
|
---|
162 | },
|
---|
163 | {
|
---|
164 | component: NoAccess,
|
---|
165 | path: '/no-access',
|
---|
166 | title: 'No Access',
|
---|
167 | exact: true,
|
---|
168 | permission: [
|
---|
169 | Roles.GUEST,
|
---|
170 | Roles.RECRUITER,
|
---|
171 | ]
|
---|
172 | },
|
---|
173 | ]
|
---|
174 |
|
---|
175 | const AllRoutes = [...PrivateRoutes, ...PublicRoutes];
|
---|
176 |
|
---|
177 | const filterRoutes = (roleParam) => {
|
---|
178 | return AllRoutes.filter(route => {
|
---|
179 | return route.permission.includes(roleParam);
|
---|
180 | });
|
---|
181 | };
|
---|
182 | const RoutesConfig = () => {
|
---|
183 | const currentUser = useSelector(state => state.auth.currentUser);
|
---|
184 | const [role, setRole] = useState(Roles.GUEST);
|
---|
185 |
|
---|
186 | useEffect(() => {
|
---|
187 | if (currentUser) {
|
---|
188 | setRole(currentUser.role);
|
---|
189 | }
|
---|
190 | }, [currentUser]);
|
---|
191 |
|
---|
192 | return (
|
---|
193 | <Routes>
|
---|
194 | {filterRoutes(role).map(route => (
|
---|
195 | <Route
|
---|
196 | key={route.path}
|
---|
197 | path={route.path}
|
---|
198 | element={<route.component/>}
|
---|
199 | exact={route.exact}
|
---|
200 | />
|
---|
201 | ))}
|
---|
202 | <Route path="*" element={<ErrorPage to="/"/>}/>
|
---|
203 | </Routes>
|
---|
204 |
|
---|
205 | // <Routes>
|
---|
206 | // <Route path="/" element={<Dashboard/>}></Route>
|
---|
207 | // <Route path="/signin" element={<SignInForm/>}></Route>
|
---|
208 | // <Route path="/signup/recruiter" element={<SignUpRecruiterForm/>}></Route>
|
---|
209 | // <Route path="/signup/job-seeker" element={<SignUpJobSeekerForm/>}></Route>
|
---|
210 | // <Route path="/job-management-hub" element={<Workspace/>}></Route>
|
---|
211 | // <Route path="/my-applications" element={<ApplicationsByJobSeeker/>}></Route>
|
---|
212 | // <Route path="/job-advertisements/:id" element={<JobAdDetails/>}></Route>
|
---|
213 | // <Route path="/recruiters/:id" element={<RecruiterProfile/>}></Route>
|
---|
214 | // <Route path="/job-management-hub/applications/:advertisement_id" element={<ApplicationsByJobAd/>}></Route>
|
---|
215 | // <Route path="/admin-panel" element={<AdminPanel/>}></Route>
|
---|
216 | // <Route path="/about" element={<AboutUs/>}></Route>
|
---|
217 | // <Route path="/job-seeker/edit-profile" element={<JobSeekerEditProfile/>}></Route>
|
---|
218 | // <Route path="/recruiter/edit-profile" element={<RecruiterEditProfile/>}></Route>
|
---|
219 | // </Routes>
|
---|
220 | )
|
---|
221 | }
|
---|
222 |
|
---|
223 | export default RoutesConfig |
---|