-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #287 from Tauffer-Consulting/dev
Dev
- Loading branch information
Showing
16 changed files
with
310 additions
and
118 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { useWorkspaces } from "@context/workspaces"; | ||
import ReportProblemIcon from "@mui/icons-material/ReportProblem"; | ||
import { Box, Button, type SxProps, type Theme, Tooltip } from "@mui/material"; | ||
import { type Roles } from "@utils/roles"; | ||
import React, { type ReactNode } from "react"; | ||
|
||
interface IProps { | ||
children?: ReactNode; | ||
allowedRoles: Roles[]; | ||
sx?: SxProps<Theme>; | ||
} | ||
|
||
export const AuthorizationComponent: React.FC<IProps> = ({ | ||
allowedRoles, | ||
children, | ||
sx, | ||
}) => { | ||
const { workspace } = useWorkspaces(); | ||
|
||
const authorized = allowedRoles.some( | ||
(item) => workspace?.user_permission === item, | ||
); | ||
|
||
return authorized ? ( | ||
<>{children}</> | ||
) : React.isValidElement(children) && children.type === Button ? ( | ||
<Tooltip | ||
title="You don't have enough permissions to access this feature" | ||
sx={sx} | ||
> | ||
<span> | ||
<Button disabled variant="contained"> | ||
<ReportProblemIcon /> | ||
Unauthorized | ||
</Button> | ||
</span> | ||
</Tooltip> | ||
) : ( | ||
<Box | ||
sx={{ | ||
height: "100%", | ||
width: "100%", | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
...sx, | ||
}} | ||
> | ||
<Tooltip title="You don't have enough permissions to access this feature"> | ||
<ReportProblemIcon fontSize="large" color="warning" /> | ||
</Tooltip> | ||
</Box> | ||
); | ||
}; |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import PrivateLayout from "@components/PrivateLayout"; | ||
import { useAuthentication } from "@context/authentication"; | ||
import { | ||
Button, | ||
Card, | ||
CardContent, | ||
CardHeader, | ||
Divider, | ||
Typography, | ||
} from "@mui/material"; | ||
import React from "react"; | ||
import { type NavigateFunction, useNavigate } from "react-router-dom"; | ||
|
||
export const ForbiddenPage: React.FC = () => { | ||
const { isLogged } = useAuthentication(); | ||
const navigate = useNavigate(); | ||
|
||
return ( | ||
<> | ||
{isLogged ? ( | ||
<PrivateLayout> | ||
<ForbiddenCard navigate={navigate} /> | ||
</PrivateLayout> | ||
) : ( | ||
<ForbiddenCard navigate={navigate} /> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
const ForbiddenCard: React.FC<{ navigate: NavigateFunction }> = ({ | ||
navigate, | ||
}) => ( | ||
<Card | ||
sx={{ | ||
maxWidth: 400, | ||
margin: "auto", | ||
marginTop: 4, | ||
boxShadow: "0 4px 8px rgba(0, 0, 0, 0.1)", | ||
}} | ||
> | ||
<CardHeader | ||
title="Forbidden" | ||
sx={{ | ||
backgroundColor: (theme) => theme.palette.error.main, | ||
color: "white", | ||
textAlign: "center", | ||
}} | ||
/> | ||
<Divider /> | ||
<CardContent | ||
sx={{ | ||
display: "flex", | ||
flexDirection: "column", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
minHeight: "50vh", | ||
}} | ||
> | ||
<Typography variant="body1" align="center"> | ||
You are not authorized to access this page. | ||
</Typography> | ||
<Button | ||
onClick={() => { | ||
navigate(-1); | ||
}} | ||
variant="outlined" | ||
sx={{ marginTop: 2 }} | ||
> | ||
<Typography component="span">{`< Go back `}</Typography> | ||
</Button> | ||
</CardContent> | ||
</Card> | ||
); |
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.