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