/* eslint-disable */ // @ts-nocheck import type RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation"; import { FormGroup, PageSection, Switch } from "../../shared/@patternfly/react-core"; import { useTranslation } from "react-i18next"; import { FormPanel, HelpItem } from "../../shared/keycloak-ui-shared"; import { useAdminClient } from "../admin-client"; import { useAlerts } from "../../shared/keycloak-ui-shared"; import { WEBAUTHN_PASSWORDLESS_POLICY } from "../authentication/policies/Policies"; import { toAuthentication } from "../authentication/routes/Authentication"; import { FormAccess } from "../components/form/FormAccess"; import { SettingsShortcut } from "../components/settings-shortcut/SettingsShortcut"; import { useRealm } from "../context/realm-context/RealmContext"; import useIsFeatureEnabled, { Feature } from "../utils/useIsFeatureEnabled"; type RealmSettingsLoginTabProps = { realm: RealmRepresentation; refresh: () => void; }; type SwitchType = { [K in keyof RealmRepresentation]: boolean }; export const RealmSettingsLoginTab = ({ realm, refresh, }: RealmSettingsLoginTabProps) => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const { addAlert, addError } = useAlerts(); const { realm: realmName } = useRealm(); const isFeatureEnabled = useIsFeatureEnabled(); const passkeysVisible = isFeatureEnabled(Feature.Passkeys); const updateSwitchValue = async (switches: SwitchType | SwitchType[]) => { const name = Array.isArray(switches) ? Object.keys(switches[0])[0] : Object.keys(switches)[0]; try { await adminClient.realms.update( { realm: realmName, }, Array.isArray(switches) ? switches.reduce((realm, s) => Object.assign(realm, s), realm) : Object.assign(realm, switches), ); addAlert(t("enableSwitchSuccess", { switch: t(name) })); refresh(); } catch (error) { addError("enableSwitchError", error); } }; return ( } hasNoPaddingTop > { await updateSwitchValue({ registrationAllowed: value }); }} aria-label={t("registrationAllowed")} /> } hasNoPaddingTop > { await updateSwitchValue({ resetPasswordAllowed: value }); }} aria-label={t("resetPasswordAllowed")} /> } hasNoPaddingTop > { await updateSwitchValue({ rememberMe: value }); }} aria-label={t("rememberMe")} /> {passkeysVisible && ( } hasNoPaddingTop > { await updateSwitchValue({ webAuthnPolicyPasswordlessPasskeysEnabled: value, }); }} aria-label={t("webAuthnPolicyPasskeysEnabled")} />{" "} )} } hasNoPaddingTop > { await updateSwitchValue([ { registrationEmailAsUsername: value, }, { duplicateEmailsAllowed: false, }, ]); }} aria-label={t("registrationEmailAsUsername")} /> } hasNoPaddingTop > { await updateSwitchValue([ { loginWithEmailAllowed: value, }, { duplicateEmailsAllowed: false }, ]); }} aria-label={t("loginWithEmailAllowed")} /> } hasNoPaddingTop > { await updateSwitchValue({ duplicateEmailsAllowed: value, }); }} isDisabled={ realm.loginWithEmailAllowed || realm.registrationEmailAsUsername } aria-label={t("duplicateEmailsAllowed")} /> } hasNoPaddingTop > { await updateSwitchValue({ verifyEmail: value }); }} aria-label={t("verifyEmail")} /> } hasNoPaddingTop > { await updateSwitchValue({ editUsernameAllowed: value }); }} aria-label={t("editUsernameAllowed")} /> ); };