Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lwjameson committed Sep 24, 2024
1 parent 536d5d5 commit 16f0999
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 94 deletions.
99 changes: 64 additions & 35 deletions src/components/CreateGroupDialog/CreateGroupDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Button from "@mui/material/Button";
import TextField from "@mui/material/TextField";
import Dialog from "@mui/material/Dialog";
import DialogActions from "@mui/material/DialogActions";
import DialogContent from "@mui/material/DialogContent";
import DialogTitle from "@mui/material/DialogTitle";
import { GroupDefinition, RoleDefinition } from "../../types";
import { useEffect, useState } from "react";
import Button from '@mui/material/Button';
import TextField from '@mui/material/TextField';
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogTitle from '@mui/material/DialogTitle';
import { GroupDefinition, RoleDefinition } from '../../types';
import { useEffect, useState } from 'react';
import {
FormControl,
MenuItem,
Expand All @@ -14,7 +14,7 @@ import {
FormControlLabel,
Checkbox,
FormGroup,
} from "@mui/material";
} from '@mui/material';

export interface CreateGroupDialogProps {
open: boolean;
Expand All @@ -23,7 +23,14 @@ export interface CreateGroupDialogProps {

onClose(): void;

onSave(_name: string, _description: string, _roleId: string, _isAdmin: boolean, _isDefault: boolean): void;
onSave(
_name: string,
_description: string,
_roleId: string,
_isAdmin: boolean,
_isDefault: boolean,
_isReadOnly: boolean
): void;
}

const CreateGroupDialog = (props: CreateGroupDialogProps) => {
Expand All @@ -34,6 +41,7 @@ const CreateGroupDialog = (props: CreateGroupDialogProps) => {
const [roleId, setRoleId] = useState<string | undefined>();
const [isAdmin, setIsAdmin] = useState(false);
const [isDefault, setIsDefault] = useState(false);
const [isReadOnly, setIsReadOnly] = useState(false);

useEffect(() => {
if (group) {
Expand All @@ -42,23 +50,26 @@ const CreateGroupDialog = (props: CreateGroupDialogProps) => {
setRoleId(group.role_id);
setIsAdmin(group.is_admin);
setIsDefault(group.is_default);
setIsReadOnly(group.is_read_only);
} else {
setName(undefined);
setDescription(undefined);
setRoleId(undefined);
setIsAdmin(false);
setIsDefault(false);
setIsReadOnly(false);
}
}, [group]);

const handleSave = () => {
if (name && description && roleId) {
onSave(name, description, roleId, isAdmin, isDefault);
onSave(name, description, roleId, isAdmin, isDefault, isReadOnly);
setName(undefined);
setDescription(undefined);
setRoleId(undefined);
setIsAdmin(false);
setIsDefault(false);
setIsReadOnly(false);
}
};

Expand All @@ -70,59 +81,68 @@ const CreateGroupDialog = (props: CreateGroupDialogProps) => {
};

const handleChangeAdmin = (checked: boolean) => {
if(checked) {
if (checked) {
setIsAdmin(true);
setIsDefault(false);
} else {
setIsAdmin(false);
}
}
};

const handleChangeReadOnly = (checked: boolean) => {
if (checked) {
setIsReadOnly(true);
setIsAdmin(false);
} else {
setIsReadOnly(false);
}
};

const handleChangeDefault = (checked: boolean) => {
if(checked) {
if (checked) {
setIsDefault(true);
setIsAdmin(false);
} else {
setIsDefault(false);
}
}
};

const mode = group ? "Edit" : "Create";
const mode = group ? 'Edit' : 'Create';
const valid = name && description && roleId;
return (
<Dialog open={open} onClose={onClose}>
<DialogTitle>{`${mode} Group`}</DialogTitle>
<DialogContent>
<TextField
autoFocus
margin="dense"
id="name"
label="Group Name"
type="text"
margin='dense'
id='name'
label='Group Name'
type='text'
fullWidth
variant="standard"
value={name || ""}
variant='standard'
value={name || ''}
onChange={(e) => setName(e.target.value)}
/>
<TextField
margin="dense"
id="description"
label="Group Description"
type="text"
margin='dense'
id='description'
label='Group Description'
type='text'
fullWidth
variant="standard"
value={description || ""}
variant='standard'
value={description || ''}
onChange={(e) => setDescription(e.target.value)}
/>
<FormControl fullWidth>
<InputLabel id="roleId">Role</InputLabel>
<InputLabel id='roleId'>Role</InputLabel>
<Select
id="roleId"
label="Role"
id='roleId'
label='Role'
fullWidth
variant="standard"
variant='standard'
// @ts-ignore
value={roleId || ""}
value={roleId || ''}
onChange={(e) => setRoleId(e.target.value)}
>
{roles.map((role) => {
Expand All @@ -142,7 +162,16 @@ const CreateGroupDialog = (props: CreateGroupDialogProps) => {
onChange={(e) => handleChangeAdmin(e.target.checked)}
/>
}
label="Is Admin Group"
label='Is Admin Group'
/>
<FormControlLabel
control={
<Checkbox
checked={isReadOnly}
onChange={(e) => handleChangeReadOnly(e.target.checked)}
/>
}
label='Is Read-Only Group'
/>
<FormControlLabel
control={
Expand All @@ -151,7 +180,7 @@ const CreateGroupDialog = (props: CreateGroupDialogProps) => {
onChange={(e) => handleChangeDefault(e.target.checked)}
/>
}
label="Is Default User Group"
label='Is Default User Group'
/>
</FormGroup>
</DialogContent>
Expand Down
Loading

0 comments on commit 16f0999

Please sign in to comment.