diff --git a/src/ui/components/userDetail/userRoles/UserRolesList.tsx b/src/ui/components/userDetail/userRoles/UserRolesList.tsx index 61657aac..88db25bd 100644 --- a/src/ui/components/userDetail/userRoles/UserRolesList.tsx +++ b/src/ui/components/userDetail/userRoles/UserRolesList.tsx @@ -113,7 +113,7 @@ export default function UserRolesList(props: UserRolesListProps) { { setRoleToDelete(undefined); diff --git a/src/ui/components/userroles/components/EditPermissions.tsx b/src/ui/components/userroles/components/EditPermissions.tsx deleted file mode 100644 index d29d9ff2..00000000 --- a/src/ui/components/userroles/components/EditPermissions.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import { useState } from "react"; - -import Badge from "../../badge"; - -import { Role } from "../types"; -import "./editPermissions.scss"; - -type CheckboxInputFieldProps = Omit & { - label?: string; - focusText?: string; - permissions: string[]; - onPermissionsChange: (permissions: string[]) => void; - selectedRole: Role; -}; - -export default function EditPermissions(props: CheckboxInputFieldProps) { - const { focusText = "", permissions, selectedRole, ...rest } = props; - const [isFocused, setIsFocused] = useState(false); - - return ( -
-
- {props.label && ( - - )} -
- setIsFocused(true)} - onBlur={() => setIsFocused(false)} - onKeyDown={(e) => { - if (e.key === "Enter") { - const newTag = e.currentTarget.value.trim(); - if (newTag && permissions.includes(newTag) === false) { - alert("90"); - } - e.currentTarget.value = ""; - } - }} - {...rest} - className={"text-small text-black input-field"} - /> -
-
- {focusText && isFocused ?

{focusText}

: null} -
-
Permissions
-
- {selectedRole.permissions.map((permission) => { - return ( -
- - -
- ); - })} - - {permissions.map((tag) => { - return ( -
- -
- ); - })} -
-
-
- ); -} diff --git a/src/ui/components/userroles/components/RolesTable.tsx b/src/ui/components/userroles/components/RolesTable.tsx index d65b68cf..7ef01e14 100644 --- a/src/ui/components/userroles/components/RolesTable.tsx +++ b/src/ui/components/userroles/components/RolesTable.tsx @@ -17,7 +17,8 @@ import { useCallback, useEffect, useState } from "react"; import useRolesService from "../../../../api/userroles/role"; import Badge from "../../badge"; -import Button from "../../button"; + +import { ReactComponent as TrashIcon } from "../../../../assets/trash.svg"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "../../table"; import { PlaceholderTableRows } from "../../usersListTable/UsersListTable"; @@ -63,35 +64,9 @@ export function RolesTable() { - -
- { - if (e.currentTarget.checked) { - setSelectedRolesToDelete(roles.map(({ role }) => role)); - } else { - setSelectedRolesToDelete([]); - } - }} - /> - User Roles -
-
+ User Roles -
- Permissions - -
+
Permissions
@@ -113,38 +88,30 @@ export function RolesTable() { setSelectedRole(roles[index]); setShowEditDialog(true); }}> + {role} -
- { +
+
+ {permissions.map((permission) => { + return ( + + ); + })} +
+
- - -
- {permissions.map((permission) => { - return ( - - ); - })} + className="delete-role"> + +
@@ -152,10 +119,11 @@ export function RolesTable() { })}
- {showDeleteDialog ? ( + {showDeleteDialog && selectedRole ? ( setShowDeleteDialog(false)} selectedRoles={selectedRolesToDelete} + selectedRole={selectedRole?.role} resetSelectedRoles={() => setSelectedRolesToDelete([])} /> ) : null} diff --git a/src/ui/components/userroles/components/dialogs/DeleteRoles.tsx b/src/ui/components/userroles/components/dialogs/DeleteRoles.tsx index f009b826..a1f64e50 100644 --- a/src/ui/components/userroles/components/dialogs/DeleteRoles.tsx +++ b/src/ui/components/userroles/components/dialogs/DeleteRoles.tsx @@ -25,10 +25,12 @@ import { useUserRolesContext } from "../../context/UserRolesContext"; import "./deleteRoles.scss"; export default function DeleteRolesDialog({ + selectedRole, selectedRoles, closeDialog, resetSelectedRoles, }: { + selectedRole: string; selectedRoles: string[]; closeDialog: () => void; resetSelectedRoles: () => void; @@ -40,26 +42,20 @@ export default function DeleteRolesDialog({ const [isDeletingRoles, setIsDeletingRoles] = useState(false); async function handleDeleteRoles() { - if (selectedRoles.length < 1) { + if (typeof selectedRole !== "string") { return; } - const promises = []; - setIsDeletingRoles(true); - for (let i = 0; i < selectedRoles.length; i++) { - promises.push(deleteRole(selectedRoles[i])); - } - try { - await Promise.all(promises); + await deleteRole(selectedRole); showToast({ iconImage: getImageUrl("checkmark-green.svg"), toastType: "success", children: "Role deleted successfully!", }); const filteredRoles = roles.filter((r) => { - return selectedRoles.includes(r.role) === false; + return r.role !== selectedRole; }); setRoles(filteredRoles); @@ -81,7 +77,8 @@ export default function DeleteRolesDialog({ Delete Roles?

- Are you sure you want to delete the selected Roles? This action is irreversible. + Are you sure you want to delete Role: {selectedRole}? This action is + irreversible.

+ { + setIsInEditingMode(true); + }} + />