Skip to content

Commit 14c193a

Browse files
committed
[Feat] Enhance NewForm component to conditionally render event types based on user roles
1 parent fff7dd0 commit 14c193a

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/Components/New/NewForm.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import dayjs from "dayjs";
33
import { orderBy } from "lodash";
44
import ReactMarkdown from 'react-markdown';
55
import MdEditor from 'react-markdown-editor-lite';
6+
import { useAuth } from "react-oidc-context";
67
import remarkGfm from 'remark-gfm';
78
import remarkIns from 'remark-ins';
89
import { Dic, MDDecsPlugins } from "~/Helpers/Entities";
910
import { useStatus } from "~/Services/Status";
11+
import { Roles } from "../Auth/With";
1012
import { EventType, IsIncident } from "../Event/Enums";
1113
import { useNewForm } from "./useNewForm";
1214

@@ -25,11 +27,19 @@ import { useNewForm } from "./useNewForm";
2527
*
2628
* @author Aloento
2729
* @since 1.0.0
28-
* @version 0.2.0
30+
* @version 0.2.1
2931
*/
3032
export function NewForm() {
3133
const { DB } = useStatus();
3234
const { State, Actions, Validation, OnSubmit, Loading } = useNewForm();
35+
const auth = useAuth();
36+
37+
const groups: string[] = (auth.user?.profile as any)?.groups || [];
38+
const isCreatorOnly = !groups.includes(Roles.Operators) && !groups.includes(Roles.Admins);
39+
40+
const availableTypes = isCreatorOnly
41+
? [EventType.Maintenance]
42+
: Object.values(EventType).slice(1);
3343

3444
return (
3545
<>
@@ -48,8 +58,9 @@ export function NewForm() {
4858
onScale-change={(e) => Actions.setType(e.target.value as EventType)}
4959
invalid={!!Validation.type}
5060
helperText={Validation.type}
61+
disabled={isCreatorOnly}
5162
>
52-
{Object.values(EventType).slice(1).map((type, i) =>
63+
{availableTypes.map((type, i) =>
5364
<ScaleDropdownSelectItem value={type} key={i}>
5465
{type}
5566
</ScaleDropdownSelectItem>)}

0 commit comments

Comments
 (0)