UNPKG

@keycloakify/keycloak-admin-ui

Version:
24 lines 7.96 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { ActionGroup, Button, FormGroup, PageSection, Switch, } from "@patternfly/react-core"; import { useEffect } from "react"; import { Controller, useForm, useWatch } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { FormPanel, HelpItem } from "../ui-shared"; import { FormAccess } from "../components/form/FormAccess"; import { TimeSelector } from "../components/time-selector/TimeSelector"; import { convertToFormValues } from "../util"; import "./realm-settings-section.css"; export const RealmSettingsSessionsTab = ({ realm, save, }) => { const { t } = useTranslation(); const { setValue, control, handleSubmit, formState } = useForm(); const offlineSessionMaxEnabled = useWatch({ control, name: "offlineSessionMaxLifespanEnabled", }); const setupForm = () => { convertToFormValues(realm, setValue); }; useEffect(setupForm, []); return (_jsxs(PageSection, { variant: "light", children: [_jsx(FormPanel, { title: t("SSOSessionSettings"), className: "kc-sso-session-template", children: _jsxs(FormAccess, { isHorizontal: true, role: "manage-realm", onSubmit: handleSubmit(save), children: [_jsx(FormGroup, { label: t("SSOSessionIdle"), fieldId: "SSOSessionIdle", labelIcon: _jsx(HelpItem, { helpText: t("ssoSessionIdle"), fieldLabelId: "SSOSessionIdle" }), children: _jsx(Controller, { name: "ssoSessionIdleTimeout", defaultValue: realm.ssoSessionIdleTimeout, control: control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-sso-session-idle", "data-testid": "sso-session-idle-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), _jsx(FormGroup, { label: t("SSOSessionMax"), fieldId: "SSOSessionMax", labelIcon: _jsx(HelpItem, { helpText: t("ssoSessionMax"), fieldLabelId: "SSOSessionMax" }), children: _jsx(Controller, { name: "ssoSessionMaxLifespan", control: control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-sso-session-max", "data-testid": "sso-session-max-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), _jsx(FormGroup, { label: t("SSOSessionIdleRememberMe"), fieldId: "SSOSessionIdleRememberMe", labelIcon: _jsx(HelpItem, { helpText: t("ssoSessionIdleRememberMe"), fieldLabelId: "SSOSessionIdleRememberMe" }), children: _jsx(Controller, { name: "ssoSessionIdleTimeoutRememberMe", control: control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-sso-session-idle-remember-me", "data-testid": "sso-session-idle-remember-me-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), _jsx(FormGroup, { label: t("SSOSessionMaxRememberMe"), fieldId: "SSOSessionMaxRememberMe", labelIcon: _jsx(HelpItem, { helpText: t("ssoSessionMaxRememberMe"), fieldLabelId: "SSOSessionMaxRememberMe" }), children: _jsx(Controller, { name: "ssoSessionMaxLifespanRememberMe", control: control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-sso-session-max-remember-me", "data-testid": "sso-session-max-remember-me-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) })] }) }), _jsx(FormPanel, { title: t("clientSessionSettings"), className: "kc-client-session-template", children: _jsxs(FormAccess, { isHorizontal: true, role: "manage-realm", className: "pf-v5-u-mt-lg", onSubmit: handleSubmit(save), children: [_jsx(FormGroup, { label: t("clientSessionIdle"), fieldId: "clientSessionIdle", labelIcon: _jsx(HelpItem, { helpText: t("clientSessionIdleHelp"), fieldLabelId: "clientSessionIdle" }), children: _jsx(Controller, { name: "clientSessionIdleTimeout", control: control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-client-session-idle", "data-testid": "client-session-idle-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), _jsx(FormGroup, { label: t("clientSessionMax"), fieldId: "clientSessionMax", labelIcon: _jsx(HelpItem, { helpText: t("clientSessionMaxHelp"), fieldLabelId: "clientSessionMax" }), children: _jsx(Controller, { name: "clientSessionMaxLifespan", control: control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-client-session-max", "data-testid": "client-session-max-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) })] }) }), _jsx(FormPanel, { title: t("offlineSessionSettings"), className: "kc-offline-session-template", children: _jsxs(FormAccess, { isHorizontal: true, role: "manage-realm", className: "pf-v5-u-mt-lg", onSubmit: handleSubmit(save), children: [_jsx(FormGroup, { label: t("offlineSessionIdle"), fieldId: "offlineSessionIdle", labelIcon: _jsx(HelpItem, { helpText: t("offlineSessionIdleHelp"), fieldLabelId: "offlineSessionIdle" }), children: _jsx(Controller, { name: "offlineSessionIdleTimeout", control: control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-offline-session-idle", "data-testid": "offline-session-idle-input", "aria-label": "offline-session-idle-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), _jsx(FormGroup, { hasNoPaddingTop: true, label: t("offlineSessionMaxLimited"), fieldId: "kc-offlineSessionMaxLimited", labelIcon: _jsx(HelpItem, { helpText: t("offlineSessionMaxLimitedHelp"), fieldLabelId: "offlineSessionMaxLimited" }), children: _jsx(Controller, { name: "offlineSessionMaxLifespanEnabled", control: control, defaultValue: false, render: ({ field }) => (_jsx(Switch, { id: "kc-offline-session-max", "data-testid": "offline-session-max-switch", "aria-label": t("offlineSessionMaxLimited"), label: t("enabled"), labelOff: t("disabled"), isChecked: field.value, onChange: field.onChange })) }) }), offlineSessionMaxEnabled && (_jsx(FormGroup, { label: t("offlineSessionMax"), fieldId: "offlineSessionMax", id: "offline-session-max-label", labelIcon: _jsx(HelpItem, { helpText: t("offlineSessionMaxHelp"), fieldLabelId: "offlineSessionMax" }), children: _jsx(Controller, { name: "offlineSessionMaxLifespan", control: control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-offline-session-max", "data-testid": "offline-session-max-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }))] }) }), _jsx(FormPanel, { className: "kc-login-settings-template", title: t("loginSettings"), children: _jsxs(FormAccess, { isHorizontal: true, role: "manage-realm", className: "pf-v5-u-mt-lg", onSubmit: handleSubmit(save), children: [_jsx(FormGroup, { label: t("loginTimeout"), id: "kc-login-timeout-label", fieldId: "offlineSessionIdle", labelIcon: _jsx(HelpItem, { helpText: t("loginTimeoutHelp"), fieldLabelId: "loginTimeout" }), children: _jsx(Controller, { name: "accessCodeLifespanLogin", control: control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-login-timeout", "data-testid": "login-timeout-input", "aria-label": "login-timeout-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), _jsx(FormGroup, { label: t("loginActionTimeout"), fieldId: "loginActionTimeout", id: "login-action-timeout-label", labelIcon: _jsx(HelpItem, { helpText: t("loginActionTimeoutHelp"), fieldLabelId: "loginActionTimeout" }), children: _jsx(Controller, { name: "accessCodeLifespanUserAction", control: control, render: ({ field }) => (_jsx(TimeSelector, { className: "kc-login-action-timeout", "data-testid": "login-action-timeout-input", value: field.value, onChange: field.onChange, units: ["minute", "hour", "day"] })) }) }), _jsxs(ActionGroup, { children: [_jsx(Button, { variant: "primary", type: "submit", "data-testid": "sessions-tab-save", isDisabled: !formState.isDirty, children: t("save") }), _jsx(Button, { variant: "link", onClick: setupForm, children: t("revert") })] })] }) })] })); }; //# sourceMappingURL=SessionsTab.js.map