import React, { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { AlertVariant, FormGroup, PageSection, Switch, } from "@patternfly/react-core"; import { FormAccess } from "../components/form-access/FormAccess"; import { HelpItem } from "../components/help-enabler/HelpItem"; import { FormPanel } from "../components/scroll-form/FormPanel"; import { asyncStateFetch, useAdminClient } from "../context/auth/AdminClient"; import RealmRepresentation from "keycloak-admin/lib/defs/realmRepresentation"; import { useErrorHandler } from "react-error-boundary"; import { useRealm } from "../context/realm-context/RealmContext"; import { useAlerts } from "../components/alert/Alerts"; export const RealmSettingsLoginTab = () => { const { t } = useTranslation("realm-settings"); const [realm, setRealm] = useState(); const handleError = useErrorHandler(); const adminClient = useAdminClient(); const { realm: realmName } = useRealm(); const { addAlert } = useAlerts(); useEffect(() => { return asyncStateFetch( () => adminClient.realms.findOne({ realm: realmName }), (realm) => { setRealm(realm); }, handleError ); }, []); 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 ( <> { } hasNoPaddingTop > { save({ ...realm, registrationAllowed: value }); }} /> } hasNoPaddingTop > { save({ ...realm, resetPasswordAllowed: value }); }} /> } hasNoPaddingTop > { save({ ...realm, rememberMe: value }); }} /> } { } hasNoPaddingTop > { save({ ...realm, registrationEmailAsUsername: value }); }} /> } hasNoPaddingTop > { save({ ...realm, loginWithEmailAllowed: value }); }} /> } hasNoPaddingTop > { save({ ...realm, duplicateEmailsAllowed: value }); }} isDisabled={ realm?.loginWithEmailAllowed || realm?.registrationEmailAsUsername } /> } hasNoPaddingTop > { save({ ...realm, verifyEmail: value }); }} /> } ); };