UNPKG

@keycloakify/keycloak-admin-ui

Version:
39 lines 2.77 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Button, ButtonVariant, Form, FormGroup, Modal, ModalVariant, Text, TextContent, } from "@patternfly/react-core"; import { Controller, FormProvider, useForm, useWatch } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { SelectControl } from "../../ui-shared"; import { FileUpload } from "../../components/json-file-upload/patternfly/FileUpload"; import { useServerInfo } from "../../context/server-info/ServerInfoProvider"; import { StoreSettings } from "../../clients/keys/StoreSettings"; export const ImportKeyDialog = ({ save, toggleDialog, }) => { var _a, _b; const { t } = useTranslation(); const form = useForm(); const { control, handleSubmit } = form; const baseFormats = (_b = (_a = useServerInfo().cryptoInfo) === null || _a === void 0 ? void 0 : _a.supportedKeystoreTypes) !== null && _b !== void 0 ? _b : []; const formats = baseFormats.concat([ "Certificate PEM", "Public Key PEM", "JSON Web Key Set", ]); const format = useWatch({ control, name: "keystoreFormat", defaultValue: formats[0], }); return (_jsxs(Modal, { variant: ModalVariant.medium, title: t("generateKeys"), isOpen: true, onClose: toggleDialog, actions: [ _jsx(Button, { id: "modal-confirm", "data-testid": "confirm", onClick: () => { handleSubmit((importFile) => { save(importFile); toggleDialog(); })(); }, children: t("import") }, "confirm"), _jsx(Button, { id: "modal-cancel", "data-testid": "cancel", variant: ButtonVariant.link, onClick: () => { toggleDialog(); }, children: t("cancel") }, "cancel"), ], children: [_jsx(TextContent, { children: _jsx(Text, { children: t("generateKeysDescription") }) }), _jsx(Form, { className: "pf-v5-u-pt-lg", children: _jsxs(FormProvider, { ...form, children: [_jsx(SelectControl, { name: "keystoreFormat", label: t("archiveFormat"), labelIcon: t("archiveFormatHelp"), controller: { defaultValue: formats[0], }, options: formats }), baseFormats.includes(format) && _jsx(StoreSettings, { hidePassword: true }), _jsx(FormGroup, { label: t("importFile"), fieldId: "importFile", children: _jsx(Controller, { name: "file", control: control, defaultValue: { filename: "" }, render: ({ field }) => (_jsx(FileUpload, { id: "importFile", value: field.value.value, filename: field.value.filename, onChange: (value, filename) => field.onChange({ value, filename }) })) }) })] }) })] })); }; //# sourceMappingURL=ImportKeyDialog.js.map