import { useState } from "react"; import { useTranslation } from "react-i18next"; import { Controller, FormProvider, useForm, useWatch } from "react-hook-form"; import { Button, ButtonVariant, Form, FormGroup, Modal, ModalVariant, Select, SelectOption, SelectVariant, Text, TextContent, } from "@patternfly/react-core"; import { HelpItem } from "../../components/help-enabler/HelpItem"; import { StoreSettings } from "./StoreSettings"; import { FileUpload } from "../../components/json-file-upload/patternfly/FileUpload"; import { useServerInfo } from "../../context/server-info/ServerInfoProvider"; type ImportKeyDialogProps = { toggleDialog: () => void; save: (importFile: ImportFile) => void; }; export type ImportFile = { keystoreFormat: string; keyAlias: string; storePassword: string; file: { value?: string; filename: string }; }; export const ImportKeyDialog = ({ save, toggleDialog, }: ImportKeyDialogProps) => { const { t } = useTranslation("clients"); const form = useForm(); const { control, handleSubmit } = form; const [openArchiveFormat, setOpenArchiveFormat] = useState(false); const baseFormats = useServerInfo().cryptoInfo?.supportedKeystoreTypes ?? []; const formats = baseFormats.concat([ "Certificate PEM", "Public Key PEM", "JSON Web Key Set", ]); const format = useWatch({ control, name: "keystoreFormat", defaultValue: formats[0], }); return ( { handleSubmit((importFile) => { save(importFile); toggleDialog(); })(); }} > {t("import")} , , ]} > {t("clients-help:generateKeysDescription")}
} fieldId="archiveFormat" > ( )} /> {baseFormats.includes(format) && ( )} ( field.onChange({ value, filename }) } /> )} />
); };