UNPKG

@keycloakify/keycloak-admin-ui

Version:
25 lines 2.1 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Button, Form, Modal, ModalVariant } from "@patternfly/react-core"; import { useState } from "react"; import { FormProvider, useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { DynamicComponents } from "../../../components/dynamic/DynamicComponents"; import { useServerInfo } from "../../../context/server-info/ServerInfoProvider"; import { ValidatorSelect } from "../../../realm-settings/user-profile/attribute/ValidatorSelect"; export const AddValidatorDialog = ({ selectedValidators, toggleDialog, onConfirm, }) => { var _a; const { t } = useTranslation(); const [selectedValidator, setSelectedValidator] = useState(); const allSelected = ((_a = useServerInfo().componentTypes) === null || _a === void 0 ? void 0 : _a["org.keycloak.validate.Validator"].length) === selectedValidators.length; const form = useForm(); const { handleSubmit } = form; const save = (newValidator) => { onConfirm({ ...newValidator, id: selectedValidator === null || selectedValidator === void 0 ? void 0 : selectedValidator.id }); toggleDialog(); }; return (_jsx(Modal, { variant: ModalVariant.small, title: t("addValidator"), isOpen: true, onClose: toggleDialog, actions: [ _jsx(Button, { "data-testid": "save-validator-role-button", variant: "primary", type: "submit", form: "add-validator", children: t("save") }, "save"), _jsx(Button, { "data-testid": "cancel-validator-role-button", variant: "link", onClick: toggleDialog, children: t("cancel") }, "cancel"), ], children: allSelected ? (t("emptyValidators")) : (_jsxs(Form, { id: "add-validator", onSubmit: handleSubmit(save), children: [_jsx(ValidatorSelect, { selectedValidators: selectedValidators.map((validator) => validator.key), onChange: setSelectedValidator }), selectedValidator && (_jsx(FormProvider, { ...form, children: _jsx(DynamicComponents, { properties: selectedValidator.properties }) }))] })) })); }; //# sourceMappingURL=AddValidatorDialog.js.map