import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation"; import { ActionGroup, Button, ClipboardCopy, FormGroup, PageSection, Select, SelectOption, SelectVariant, Stack, StackItem, Switch, } from "@patternfly/react-core"; import { useEffect, useState } from "react"; import { Controller, FormProvider, useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { HelpItem } from "ui-shared"; import { adminClient } from "../admin-client"; import { FormattedLink } from "../components/external-link/FormattedLink"; import { FormAccess } from "../components/form/FormAccess"; import { KeyValueInput } from "../components/key-value-form/KeyValueInput"; import { KeycloakTextInput } from "../components/keycloak-text-input/KeycloakTextInput"; import { useRealm } from "../context/realm-context/RealmContext"; import { addTrailingSlash, convertAttributeNameToForm, convertToFormValues, } from "../util"; import { UnmanagedAttributePolicy, UserProfileConfig, } from "@keycloak/keycloak-admin-client/lib/defs/userProfileMetadata"; import { useFetch } from "../utils/useFetch"; import { UIRealmRepresentation } from "./RealmSettingsTabs"; type RealmSettingsGeneralTabProps = { realm: UIRealmRepresentation; save: (realm: UIRealmRepresentation) => void; }; type FormFields = Omit; export const RealmSettingsGeneralTab = ({ realm, save, }: RealmSettingsGeneralTabProps) => { const { t } = useTranslation(); const { realm: realmName } = useRealm(); const form = useForm(); const { register, control, handleSubmit, setValue, formState: { isDirty, errors }, } = form; const [open, setOpen] = useState(false); const requireSslTypes = ["all", "external", "none"]; const [userProfileConfig, setUserProfileConfig] = useState(); const unmanagedAttributePolicies = [ UnmanagedAttributePolicy.Disabled, UnmanagedAttributePolicy.Enabled, UnmanagedAttributePolicy.AdminView, UnmanagedAttributePolicy.AdminEdit, ]; const [isUnmanagedAttributeOpen, setIsUnmanagedAttributeOpen] = useState(false); const setupForm = () => { convertToFormValues(realm, setValue); if (realm.attributes?.["acr.loa.map"]) { const result = Object.entries( JSON.parse(realm.attributes["acr.loa.map"]), ).flatMap(([key, value]) => ({ key, value })); result.concat({ key: "", value: "" }); setValue( convertAttributeNameToForm("attributes.acr.loa.map") as any, result, ); } }; useFetch( () => adminClient.users.getProfile({ realm: realmName }), (config) => setUserProfileConfig(config), [], ); useEffect(setupForm, []); return ( { if ( UnmanagedAttributePolicy.Disabled === userProfileConfig?.unmanagedAttributePolicy ) { userProfileConfig.unmanagedAttributePolicy = undefined; } save({ ...data, upConfig: userProfileConfig }); })} > ( {field.value} )} /> } > } > ( )} /> } > } fieldId="kc-user-managed-access" > ( )} /> } > } fieldId="kc-endpoints" > ); };