UNPKG

@keycloakify/keycloak-admin-ui

Version:
54 lines 3.52 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Controller, FormProvider, useForm, useFormContext, } from "react-hook-form"; import { Button, ButtonVariant, Form, FormGroup, Modal, ModalVariant, Text, TextContent, } from "@patternfly/react-core"; import { HelpItem, SelectControl } from "../../ui-shared"; import { StoreSettings } from "../../clients/keys/StoreSettings"; import { FileUpload } from "../../components/json-file-upload/patternfly/FileUpload"; import { useServerInfo } from "../../context/server-info/ServerInfoProvider"; const CERT_PEM = "Certificate PEM"; const extensions = new Map([ ["PKCS12", "p12"], ["JKS", "jks"], ["BCFKS", "bcfks"], ]); export const getFileExtension = (format) => extensions.get(format); export const KeyForm = ({ isSaml = false, hasPem = false, useFile = false, }) => { var _a; const { t } = useTranslation(); const [filename, setFilename] = useState(); const { control, watch } = useFormContext(); const format = watch("format"); const { cryptoInfo } = useServerInfo(); const supportedKeystoreTypes = [ ...((_a = cryptoInfo === null || cryptoInfo === void 0 ? void 0 : cryptoInfo.supportedKeystoreTypes) !== null && _a !== void 0 ? _a : []), ...(hasPem ? [CERT_PEM] : []), ]; return (_jsxs(Form, { className: "pf-v5-u-pt-lg", children: [_jsx(SelectControl, { name: "format", label: t("archiveFormat"), labelIcon: t("archiveFormatHelp"), controller: { defaultValue: supportedKeystoreTypes[0], }, menuAppendTo: "parent", options: supportedKeystoreTypes }), useFile && (_jsx(FormGroup, { label: t("importFile"), labelIcon: _jsx(HelpItem, { helpText: t("importFileHelp"), fieldLabelId: "importFile" }), fieldId: "importFile", children: _jsx(Controller, { name: "file", defaultValue: "", control: control, render: ({ field }) => (_jsx(FileUpload, { id: "importFile", value: field.value, filename: filename, browseButtonText: t("browse"), onChange: (value, filename) => { setFilename(filename); field.onChange(value); } })) }) })), format !== CERT_PEM && (_jsx(StoreSettings, { hidePassword: useFile, isSaml: isSaml }))] })); }; export const GenerateKeyDialog = ({ clientId, save, toggleDialog, }) => { const { t } = useTranslation(); const form = useForm({ defaultValues: { keyAlias: clientId }, mode: "onChange", }); const { handleSubmit, formState: { isValid }, } = form; return (_jsxs(Modal, { variant: ModalVariant.medium, title: t("generateKeys"), isOpen: true, onClose: toggleDialog, actions: [ _jsx(Button, { id: "modal-confirm", "data-testid": "confirm", isDisabled: !isValid, onClick: () => { handleSubmit((config) => { save(config); toggleDialog(); })(); }, children: t("generate") }, "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(FormProvider, { ...form, children: _jsx(KeyForm, {}) })] })); }; //# sourceMappingURL=GenerateKeyDialog.js.map