Skip to content

Commit

Permalink
add remaining routes'
Browse files Browse the repository at this point in the history
  • Loading branch information
magsyg committed Jul 11, 2023
1 parent dbe8f23 commit bed3179
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 22 deletions.
99 changes: 78 additions & 21 deletions frontend/src/AppRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { SaksdokumentAdminPage } from './PagesAdmin/SaksdokumentAdminPage';
import { ROUTES } from './routes';
import { PERM } from './permissions';
import { ProtectedRoute } from './Components';
import { SAMFUNDET_CHANGE_CLOSEDPERIOD } from './permissions/permissions';

export function AppRoutes() {
// Must be called within <BrowserRouter> because it uses hook useLocation().
Expand Down Expand Up @@ -105,45 +106,101 @@ export function AppRoutes() {
path={ROUTES.frontend.admin_events_create}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_ADD_EVENT]} Page={EventCreatorAdminPage} />}
/>
<Route path={ROUTES.frontend.admin_events_edit} element={<ProtectedRoute perms={[PERM.SAMFUNDET_CHANGE_EVENT]} Page={EventCreatorAdminPage} />} />
<Route
path={ROUTES.frontend.admin_events_edit}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_CHANGE_EVENT]} Page={EventCreatorAdminPage} />}
/>
{/*
Info pages
NOTE: edit/create uses custom views
*/}
<Route path={ROUTES.frontend.admin_information} element={<InformationAdminPage />} />
{/* Opening hours */}
<Route path={ROUTES.frontend.admin_opening_hours} element={<OpeningHoursAdminPage />} />
<Route
path={ROUTES.frontend.admin_information}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_VIEW_INFORMATIONPAGE]} Page={InformationAdminPage} />}
/>
{/* Opening hours, TODO ADD OPENING HOURS PERMISSIONS*/}
<Route
path={ROUTES.frontend.admin_opening_hours}
element={<ProtectedRoute perms={[]} Page={OpeningHoursAdminPage} />}
/>
{/* Closed period */}
<Route path={ROUTES.frontend.admin_closed} element={<ClosedPeriodAdminPage />} />
<Route path={ROUTES.frontend.admin_closed_create} element={<ClosedPeriodFormAdminPage />} />
<Route path={ROUTES.frontend.admin_closed_edit} element={<ClosedPeriodFormAdminPage />} />
<Route
path={ROUTES.frontend.admin_closed}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_VIEW_CLOSEDPERIOD]} Page={ClosedPeriodAdminPage} />}
/>
<Route
path={ROUTES.frontend.admin_closed_create}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_ADD_CLOSEDPERIOD]} Page={ClosedPeriodFormAdminPage} />}
/>
<Route
path={ROUTES.frontend.admin_closed_edit}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_CHANGE_CLOSEDPERIOD]} Page={ClosedPeriodFormAdminPage} />}
/>
{/* Images */}
<Route path={ROUTES.frontend.admin_images} element={<ImageAdminPage />} />
<Route path={ROUTES.frontend.admin_images_create} element={<ImageFormAdminPage />} />
<Route
path={ROUTES.frontend.admin_images}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_VIEW_IMAGE]} Page={ImageAdminPage} />}
/>
<Route
path={ROUTES.frontend.admin_images_create}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_ADD_IMAGE]} Page={ImageFormAdminPage} />}
/>
{/* Saksdokumenter */}
<Route path={ROUTES.frontend.admin_saksdokumenter} element={<SaksdokumentAdminPage />} />
<Route path={ROUTES.frontend.admin_saksdokumenter_create} element={<SaksdokumentFormAdminPage />} />
<Route path={ROUTES.frontend.admin_saksdokumenter_edit} element={<SaksdokumentFormAdminPage />} />
<Route
path={ROUTES.frontend.admin_saksdokumenter}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_VIEW_SAKSDOKUMENT]} Page={SaksdokumentAdminPage} />}
/>
<Route
path={ROUTES.frontend.admin_saksdokumenter_create}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_ADD_SAKSDOKUMENT]} Page={SaksdokumentFormAdminPage} />}
/>
<Route
path={ROUTES.frontend.admin_saksdokumenter_edit}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_CHANGE_SAKSDOKUMENT]} Page={SaksdokumentFormAdminPage} />}
/>
{/* Recruitment */}
<Route path={ROUTES.frontend.admin_recruitment} element={<RecruitmentAdminPage />} />
<Route path={ROUTES.frontend.admin_recruitment_create} element={<RecruitmentFormAdminPage />} />
<Route path={ROUTES.frontend.admin_recruitment_edit} element={<RecruitmentFormAdminPage />} />
<Route path={ROUTES.frontend.admin_recruitment_gang_overview} element={<RecruitmentGangOverviewPage />} />
<Route path={ROUTES.frontend.admin_recruitment_gang_position_overview} element={<RecruitmentGangAdminPage />} />
<Route
path={ROUTES.frontend.admin_recruitment}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_VIEW_RECRUITMENT]} Page={RecruitmentAdminPage} />}
/>
<Route
path={ROUTES.frontend.admin_recruitment_create}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_ADD_RECRUITMENT]} Page={RecruitmentFormAdminPage} />}
/>
<Route
path={ROUTES.frontend.admin_recruitment_edit}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_CHANGE_RECRUITMENT]} Page={RecruitmentFormAdminPage} />}
/>
{/* TODO ADD PERMISSIONS */}
<Route
path={ROUTES.frontend.admin_recruitment_gang_overview}
element={<ProtectedRoute perms={[]} Page={RecruitmentGangOverviewPage} />}
/>
<Route
path={ROUTES.frontend.admin_recruitment_gang_position_overview}
element={<ProtectedRoute perms={[]} Page={RecruitmentGangAdminPage} />}
/>

<Route
path={ROUTES.frontend.admin_recruitment_gang_position_create}
element={<RecruitmentPositionFormAdminPage />}
element={<ProtectedRoute perms={[]} Page={RecruitmentPositionFormAdminPage} />}
/>
<Route
path={ROUTES.frontend.admin_recruitment_gang_position_edit}
element={<RecruitmentPositionFormAdminPage />}
element={<ProtectedRoute perms={[]} Page={RecruitmentPositionFormAdminPage} />}
/>
{/*
Info pages
Custom layout for edit/create
*/}
<Route path={ROUTES.frontend.admin_information_create} element={<InformationFormAdminPage />} />
<Route path={ROUTES.frontend.admin_information_edit} element={<InformationFormAdminPage />} />
<Route
path={ROUTES.frontend.admin_information_create}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_ADD_INFORMATIONPAGE]} Page={InformationFormAdminPage} />}
/>
<Route
path={ROUTES.frontend.admin_information_edit}
element={<ProtectedRoute perms={[PERM.SAMFUNDET_CHANGE_INFORMATIONPAGE]} Page={InformationFormAdminPage} />}
/>
</Route>
{/*
SULTEN ROUTES
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Components/ProtectedRoute/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function ProtectedRoute({
return <Navigate to={ROUTES.frontend.login} replace state={{ from: location }} />;
}
if (requiresStaff && !user?.is_staff) {
return <Navigate to={redirectPath} replace />;
return <Navigate to={redirectPath} replace />; // Replace replace current navigation head instead of pushing it
}
if (perms) {
for (const permission of perms) {
Expand Down

0 comments on commit bed3179

Please sign in to comment.