Ignore:
Timestamp:
06/17/24 21:59:14 (5 months ago)
Author:
223021 <daniel.ilievski.2@…>
Branches:
main
Children:
08f82ec
Parents:
b248810
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • jobvista-frontend/src/auth/RoutesConfig.js

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