From ba6d4877abe3a8e54b1fda08c9a04afd40bc1522 Mon Sep 17 00:00:00 2001 From: Eugenia <32821331+jenny-s51@users.noreply.github.com> Date: Tue, 29 Sep 2020 13:54:42 -0400 Subject: [PATCH] Create realm role page (#114) * add Realm Roles page * add section for no realm roles * update role-model, fixed UI to match designs * fix paths * add storybook demo and role actions kebab * fix build and clean up * fix formatting * fix lint * fix test and update snapshot * update snapshot after rebase * PR feedback from Stan * add back pf addons * localize NoRealmRoles component * changes to PR suggested by Sarah * adds new role form * fix path * rename fields * HTTP post is working * move create msg * cleaning up * address PR feedback from Stan * added validation and changed to text area Co-authored-by: Erik Jan de Wit --- src/App.tsx | 3 +- src/common-messages.json | 1 + src/realm-roles/add/NewRoleForm.tsx | 96 +++++++++++++++++++++++++++++ src/realm-roles/messages.json | 4 +- src/realm/messages.json | 1 - 5 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 src/realm-roles/add/NewRoleForm.tsx diff --git a/src/App.tsx b/src/App.tsx index 062f4bee99..872df38f70 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -6,6 +6,7 @@ import { Header } from "./PageHeader"; import { PageNav } from "./PageNav"; import { Help } from "./components/help-enabler/HelpHeader"; import { NewRealmForm } from "./realm/add/NewRealmForm"; +import { NewRoleForm } from "./realm-roles/add/NewRoleForm"; import { NewClientForm } from "./clients/add/NewClientForm"; import { NewClientScopeForm } from "./client-scopes/add/NewClientScopeForm"; @@ -34,7 +35,7 @@ export const App = () => { } isManagedSidebar sidebar={}> - + { + const { t } = useTranslation("roles"); + const httpClient = useContext(HttpClientContext)!; + const [addAlert, Alerts] = useAlerts(); + const { realm } = useContext(RealmContext); + + const { register, control, errors, handleSubmit } = useForm< + RoleRepresentation + >(); + + const save = async (role: RoleRepresentation) => { + try { + await httpClient.doPost(`admin/realms/${realm}/roles`, role); + addAlert(t("roleCreated"), AlertVariant.success); + } catch (error) { + addAlert(`${t("roleCreateError")} '${error}'`, AlertVariant.danger); + } + }; + + return ( + <> + + + + {t("createRole")} + + + + +
+ + + + + ( +