import React, { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { Controller, useForm } from "react-hook-form"; import { useErrorHandler } from "react-error-boundary"; import { ActionGroup, AlertVariant, Button, ClipboardCopy, FormGroup, PageSection, Select, SelectOption, SelectVariant, Stack, StackItem, Switch, TextInput, } from "@patternfly/react-core"; import RealmRepresentation from "keycloak-admin/lib/defs/realmRepresentation"; import { getBaseUrl } from "../util"; import { useAdminClient, asyncStateFetch } from "../context/auth/AdminClient"; import { useRealm } from "../context/realm-context/RealmContext"; import { useAlerts } from "../components/alert/Alerts"; import { FormAccess } from "../components/form-access/FormAccess"; import { HelpItem } from "../components/help-enabler/HelpItem"; import { FormattedLink } from "../components/external-link/FormattedLink"; export const RealmSettingsGeneralTab = () => { const { t } = useTranslation("realm-settings"); const adminClient = useAdminClient(); const handleError = useErrorHandler(); const { realm: realmName } = useRealm(); const { addAlert } = useAlerts(); const { register, control, setValue, handleSubmit } = useForm(); const [realm, setRealm] = useState(); const [open, setOpen] = useState(false); const baseUrl = getBaseUrl(adminClient); const requireSslTypes = ["all", "external", "none"]; useEffect(() => { return asyncStateFetch( () => adminClient.realms.findOne({ realm: realmName }), (realm) => { setRealm(realm); setupForm(realm); }, handleError ); }, []); const setupForm = (realm: RealmRepresentation) => { Object.entries(realm).map((entry) => setValue(entry[0], entry[1])); }; const save = async (realm: RealmRepresentation) => { try { await adminClient.realms.update({ realm: realmName }, realm); setRealm(realm); addAlert(t("saveSuccess"), AlertVariant.success); } catch (error) { addAlert(t("saveError", { error }), AlertVariant.danger); } }; return ( <> {realmName} } > } > ( )} /> } fieldId="kc-user-manged-access" > ( )} /> } fieldId="kc-endpoints" > ); };