import React, { useEffect, useState } from "react"; import { useHistory, useParams } from "react-router-dom"; import { ActionGroup, AlertVariant, Button, FormGroup, Tab, Tabs, TabTitleText, TextArea, TextInput, ValidatedOptions, } from "@patternfly/react-core"; import { useTranslation } from "react-i18next"; import { Controller, useForm } from "react-hook-form"; import { FormAccess } from "../components/form-access/FormAccess"; import { useAlerts } from "../components/alert/Alerts"; import { useAdminClient, useFetch } from "../context/auth/AdminClient"; import RoleRepresentation from "keycloak-admin/lib/defs/roleRepresentation"; import { RoleAttributes } from "./RoleAttributes"; import "./RealmRolesSection.css"; import { useRealm } from "../context/realm-context/RealmContext"; export const RolesTabs = () => { const { t } = useTranslation("roles"); const { errors, control, setValue } = useForm(); const history = useHistory(); const [name, setName] = useState(""); const adminClient = useAdminClient(); const [activeTab, setActiveTab] = useState(0); const { realm } = useRealm(); const { id } = useParams<{ id: string }>(); const { addAlert } = useAlerts(); useEffect(() => { return useFetch( () => adminClient.roles.findOneById({ id }), (fetchedRole) => { setName(fetchedRole.name!); setupForm(fetchedRole); } ); }, []); const setupForm = (role: RoleRepresentation) => { Object.entries(role).map((entry) => { setValue(entry[0], entry[1]); }); }; const save = async (role: RoleRepresentation) => { try { await adminClient.roles.updateById({ id }, role); setupForm(role as RoleRepresentation); addAlert(t("roleSaveSuccess"), AlertVariant.success); } catch (error) { addAlert(`${t("roleSaveError")} '${error}'`, AlertVariant.danger); } }; const form = useForm(); return ( <> setActiveTab(key as number)} isBox > {t("details")}}> {name ? ( ) : undefined} (