UNPKG

@keycloakify/keycloak-admin-ui

Version:
63 lines 7.65 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { FormGroup, PageSection, Switch } from "@patternfly/react-core"; import { useTranslation } from "react-i18next"; import { FormPanel, HelpItem } from "../ui-shared"; import { useAdminClient } from "../admin-client"; import { useAlerts } from "../ui-shared"; import { FormAccess } from "../components/form/FormAccess"; import { useRealm } from "../context/realm-context/RealmContext"; export const RealmSettingsLoginTab = ({ realm, refresh, }) => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const { addAlert, addError } = useAlerts(); const { realm: realmName } = useRealm(); const updateSwitchValue = async (switches) => { 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 (_jsxs(PageSection, { variant: "light", children: [_jsx(FormPanel, { className: "kc-login-screen", title: t("loginScreenCustomization"), children: _jsxs(FormAccess, { isHorizontal: true, role: "manage-realm", children: [_jsx(FormGroup, { label: t("registrationAllowed"), fieldId: "kc-user-reg", labelIcon: _jsx(HelpItem, { helpText: t("userRegistrationHelpText"), fieldLabelId: "registrationAllowed" }), hasNoPaddingTop: true, children: _jsx(Switch, { id: "kc-user-reg-switch", "data-testid": "user-reg-switch", value: realm.registrationAllowed ? "on" : "off", label: t("on"), labelOff: t("off"), isChecked: realm.registrationAllowed, onChange: (_event, value) => { updateSwitchValue({ registrationAllowed: value }); }, "aria-label": t("registrationAllowed") }) }), _jsx(FormGroup, { label: t("resetPasswordAllowed"), fieldId: "kc-forgot-pw", labelIcon: _jsx(HelpItem, { helpText: t("forgotPasswordHelpText"), fieldLabelId: "resetPasswordAllowed" }), hasNoPaddingTop: true, children: _jsx(Switch, { id: "kc-forgot-pw-switch", "data-testid": "forgot-pw-switch", name: "resetPasswordAllowed", value: realm.resetPasswordAllowed ? "on" : "off", label: t("on"), labelOff: t("off"), isChecked: realm.resetPasswordAllowed, onChange: (_event, value) => { updateSwitchValue({ resetPasswordAllowed: value }); }, "aria-label": t("resetPasswordAllowed") }) }), _jsx(FormGroup, { label: t("rememberMe"), fieldId: "kc-remember-me", labelIcon: _jsx(HelpItem, { helpText: t("rememberMeHelpText"), fieldLabelId: "rememberMe" }), hasNoPaddingTop: true, children: _jsx(Switch, { id: "kc-remember-me-switch", "data-testid": "remember-me-switch", value: realm.rememberMe ? "on" : "off", label: t("on"), labelOff: t("off"), isChecked: realm.rememberMe, onChange: (_event, value) => { updateSwitchValue({ rememberMe: value }); }, "aria-label": t("rememberMe") }) })] }) }), _jsx(FormPanel, { className: "kc-email-settings", title: t("emailSettings"), children: _jsxs(FormAccess, { isHorizontal: true, role: "manage-realm", children: [_jsx(FormGroup, { label: t("registrationEmailAsUsername"), fieldId: "kc-email-as-username", labelIcon: _jsx(HelpItem, { helpText: t("emailAsUsernameHelpText"), fieldLabelId: "registrationEmailAsUsername" }), hasNoPaddingTop: true, children: _jsx(Switch, { id: "kc-email-as-username-switch", "data-testid": "email-as-username-switch", value: realm.registrationEmailAsUsername ? "on" : "off", label: t("on"), labelOff: t("off"), isChecked: realm.registrationEmailAsUsername, onChange: (_event, value) => { updateSwitchValue([ { registrationEmailAsUsername: value, }, { duplicateEmailsAllowed: false, }, ]); }, "aria-label": t("registrationEmailAsUsername") }) }), _jsx(FormGroup, { label: t("loginWithEmailAllowed"), fieldId: "kc-login-with-email", labelIcon: _jsx(HelpItem, { helpText: t("loginWithEmailHelpText"), fieldLabelId: "loginWithEmailAllowed" }), hasNoPaddingTop: true, children: _jsx(Switch, { id: "kc-login-with-email-switch", "data-testid": "login-with-email-switch", value: realm.loginWithEmailAllowed ? "on" : "off", label: t("on"), labelOff: t("off"), isChecked: realm.loginWithEmailAllowed, onChange: (_event, value) => { updateSwitchValue([ { loginWithEmailAllowed: value, }, { duplicateEmailsAllowed: false }, ]); }, "aria-label": t("loginWithEmailAllowed") }) }), _jsx(FormGroup, { label: t("duplicateEmailsAllowed"), fieldId: "kc-duplicate-emails", labelIcon: _jsx(HelpItem, { helpText: t("duplicateEmailsHelpText"), fieldLabelId: "duplicateEmailsAllowed" }), hasNoPaddingTop: true, children: _jsx(Switch, { id: "kc-duplicate-emails-switch", "data-testid": "duplicate-emails-switch", label: t("on"), labelOff: t("off"), isChecked: realm.duplicateEmailsAllowed, onChange: (_event, value) => { updateSwitchValue({ duplicateEmailsAllowed: value, }); }, isDisabled: realm.loginWithEmailAllowed || realm.registrationEmailAsUsername, "aria-label": t("duplicateEmailsAllowed") }) }), _jsx(FormGroup, { label: t("verifyEmail"), fieldId: "kc-verify-email", labelIcon: _jsx(HelpItem, { helpText: t("verifyEmailHelpText"), fieldLabelId: "verifyEmail" }), hasNoPaddingTop: true, children: _jsx(Switch, { id: "kc-verify-email-switch", "data-testid": "verify-email-switch", name: "verifyEmail", value: realm.verifyEmail ? "on" : "off", label: t("on"), labelOff: t("off"), isChecked: realm.verifyEmail, onChange: (_event, value) => { updateSwitchValue({ verifyEmail: value }); }, "aria-label": t("verifyEmail") }) })] }) }), _jsx(FormPanel, { className: "kc-user-info-settings", title: t("userInfoSettings"), children: _jsx(FormAccess, { isHorizontal: true, role: "manage-realm", children: _jsx(FormGroup, { label: t("editUsernameAllowed"), fieldId: "kc-edit-username", labelIcon: _jsx(HelpItem, { helpText: t("editUsernameHelp"), fieldLabelId: "editUsernameAllowed" }), hasNoPaddingTop: true, children: _jsx(Switch, { id: "kc-edit-username-switch", "data-testid": "edit-username-switch", value: realm.editUsernameAllowed ? "on" : "off", label: t("on"), labelOff: t("off"), isChecked: realm.editUsernameAllowed, onChange: (_event, value) => { updateSwitchValue({ editUsernameAllowed: value }); }, "aria-label": t("editUsernameAllowed") }) }) }) })] })); }; //# sourceMappingURL=LoginTab.js.map