-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Select and search button and colors (#7108)
* Select and search button and colors * gave editors access to IX * missing translations * remoeved unnecesary tests * deleted unused vars
- Loading branch information
Showing
20 changed files
with
213 additions
and
161 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
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
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,35 +1,34 @@ | ||
import React, { ReactElement } from 'react'; | ||
import { Navigate, Outlet } from 'react-router-dom'; | ||
import { store } from 'app/store'; | ||
import { UserRole } from 'shared/types/userSchema'; | ||
import { ClientSettings } from 'app/apiResponseTypes'; | ||
|
||
const ProtectedRoute = ({ | ||
children, | ||
onlyAdmin, | ||
allowedRoles, | ||
}: { | ||
children: ReactElement; | ||
onlyAdmin?: boolean; | ||
allowedRoles?: string[]; | ||
}) => { | ||
const userId = store?.getState().user.get('_id'); | ||
|
||
if (onlyAdmin && store?.getState().user.get('role') === UserRole.ADMIN) { | ||
const userRole = store?.getState().user.get('role') || ''; | ||
if (allowedRoles && allowedRoles.includes(userRole)) { | ||
return children || <Outlet />; | ||
} | ||
|
||
if (!onlyAdmin && userId) { | ||
if (!allowedRoles && userId) { | ||
return children || <Outlet />; | ||
} | ||
|
||
return <Navigate to="/login" replace />; | ||
}; | ||
|
||
const adminsOnlyRoute = (element: ReactElement) => ( | ||
<ProtectedRoute onlyAdmin>{element}</ProtectedRoute> | ||
<ProtectedRoute allowedRoles={['admin']}>{element}</ProtectedRoute> | ||
); | ||
|
||
const privateRoute = (element: ReactElement, settings: ClientSettings | undefined) => | ||
!settings?.private ? element : <ProtectedRoute>{element}</ProtectedRoute>; | ||
|
||
const loggedInUsersRoute = (element: ReactElement) => <ProtectedRoute>{element}</ProtectedRoute>; | ||
export { loggedInUsersRoute, adminsOnlyRoute, privateRoute }; | ||
export { loggedInUsersRoute, adminsOnlyRoute, privateRoute, ProtectedRoute }; |
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
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
Oops, something went wrong.