mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
add optional fallback to AdminRoute
This commit is contained in:
@@ -15,10 +15,15 @@ import { TOP_BAR_HEIGHT } from "@src/layouts/Navigation/TopBar";
|
||||
/**
|
||||
* Lock pages for admins only
|
||||
*/
|
||||
export default function AdminRoute({ children }: PropsWithChildren<{}>) {
|
||||
export default function AdminRoute({
|
||||
children,
|
||||
fallback,
|
||||
}: PropsWithChildren<{ fallback?: React.ReactNode }>) {
|
||||
const [userRoles] = useAtom(userRolesAtom, projectScope);
|
||||
|
||||
if (!userRoles.includes("ADMIN"))
|
||||
if (!userRoles.includes("ADMIN")) {
|
||||
if (fallback) return fallback as JSX.Element;
|
||||
|
||||
return (
|
||||
<EmptyState
|
||||
role="alert"
|
||||
@@ -39,6 +44,7 @@ export default function AdminRoute({ children }: PropsWithChildren<{}>) {
|
||||
style={{ marginTop: -TOP_BAR_HEIGHT, marginBottom: -TOP_BAR_HEIGHT }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return children as JSX.Element;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user