adds delete action to realm details page (#236)

This commit is contained in:
Eugenia 2020-11-24 16:11:35 -05:00 committed by GitHub
parent 2e64f144d5
commit 17b1fab80e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 3 deletions

View file

@ -27,8 +27,6 @@
"disabled": "Disabled", "disabled": "Disabled",
"disable": "Disable", "disable": "Disable",
"selectOne": "Select an option", "selectOne": "Select an option",
"reload": "Reload",
"signOut": "Sign out", "signOut": "Sign out",
"manageAccount": "Manage account", "manageAccount": "Manage account",
"serverInfo": "Server info", "serverInfo": "Server info",

View file

@ -4,6 +4,8 @@ import {
ActionGroup, ActionGroup,
AlertVariant, AlertVariant,
Button, Button,
ButtonVariant,
DropdownItem,
FormGroup, FormGroup,
PageSection, PageSection,
Tab, Tab,
@ -22,6 +24,7 @@ import { ViewHeader } from "../components/view-header/ViewHeader";
import { useAdminClient } from "../context/auth/AdminClient"; import { useAdminClient } from "../context/auth/AdminClient";
import RoleRepresentation from "keycloak-admin/lib/defs/roleRepresentation"; import RoleRepresentation from "keycloak-admin/lib/defs/roleRepresentation";
import { useConfirmDialog } from "../components/confirm-dialog/ConfirmDialog";
export const RolesForm = () => { export const RolesForm = () => {
const { t } = useTranslation("roles"); const { t } = useTranslation("roles");
@ -34,6 +37,8 @@ export const RolesForm = () => {
const adminClient = useAdminClient(); const adminClient = useAdminClient();
const selectedRoleName = name;
const { id } = useParams<{ id: string }>(); const { id } = useParams<{ id: string }>();
const { addAlert } = useAlerts(); const { addAlert } = useAlerts();
@ -62,9 +67,39 @@ export const RolesForm = () => {
} }
}; };
const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({
titleKey: "roles:roleDeleteConfirm",
messageKey: t("roles:roleDeleteConfirmDialog", { selectedRoleName }),
continueButtonLabel: "common:delete",
continueButtonVariant: ButtonVariant.danger,
onConfirm: async () => {
try {
await adminClient.roles.delByName({
name: name,
});
addAlert(t("roleDeletedSuccess"), AlertVariant.success);
} catch (error) {
addAlert(`${t("roleDeleteError")} ${error}`, AlertVariant.danger);
}
},
});
return ( return (
<> <>
<ViewHeader titleKey={name} subKey="" /> <DeleteConfirm />
<ViewHeader
titleKey={name}
subKey=""
dropdownItems={[
<DropdownItem
key="action"
component="button"
onClick={() => toggleDeleteDialog()}
>
{t("deleteRole")}
</DropdownItem>,
]}
/>
<PageSection variant="light"> <PageSection variant="light">
<Tabs <Tabs

View file

@ -10,6 +10,7 @@
"roleName": "Role name", "roleName": "Role name",
"roleDetails": "Role details", "roleDetails": "Role details",
"composite": "Composite", "composite": "Composite",
"deleteRole": "Delete this role",
"description": "Description", "description": "Description",
"details": "Details", "details": "Details",
"roleList": "Role list", "roleList": "Role list",