import React, { useState } from "react"; import { AlertVariant, Button, ButtonVariant, FileUpload, Form, FormGroup, Modal, ModalVariant, Select, SelectOption, SelectVariant, Switch, TextInput, } from "@patternfly/react-core"; import { useTranslation } from "react-i18next"; import { Controller, useForm } from "react-hook-form"; import { useAdminClient } from "../context/auth/AdminClient"; import { useAlerts } from "../components/alert/Alerts"; import type ComponentRepresentation from "keycloak-admin/lib/defs/componentRepresentation"; import { HelpItem } from "../components/help-enabler/HelpItem"; import { useServerInfo } from "../context/server-info/ServerInfoProvider"; import { useRealm } from "../context/realm-context/RealmContext"; type RSAModalProps = { providerType?: string; handleModalToggle?: () => void; refresh?: () => void; open: boolean; }; export const RSAModal = ({ providerType, handleModalToggle, open, refresh, }: // save, RSAModalProps) => { const { t } = useTranslation("groups"); const serverInfo = useServerInfo(); const adminClient = useAdminClient(); const { addAlert } = useAlerts(); const { handleSubmit, control } = useForm({}); const [isRSAalgDropdownOpen, setIsRSAalgDropdownOpen] = useState(false); const [displayName, setDisplayName] = useState(""); const realm = useRealm(); const [keyFileName, setKeyFileName] = useState(""); const [certificateFileName, setCertificateFileName] = useState(""); const allComponentTypes = serverInfo.componentTypes![ "org.keycloak.keys.KeyProvider" ]; const save = async (component: ComponentRepresentation) => { try { await adminClient.components.create({ parentId: realm.realm, name: displayName !== "" ? displayName : providerType, providerId: providerType, providerType: "org.keycloak.keys.KeyProvider", ...component, }); refresh!(); addAlert(t("realm-settings:saveProviderSuccess"), AlertVariant.success); handleModalToggle!(); } catch (error) { addAlert( t("realm-settings:saveProviderError") + error.response?.data?.errorMessage || error, AlertVariant.danger ); } }; return ( {t("common:Add")} , , ]} >
} > ( { onChange(value); setDisplayName(value); }} data-testid="display-name-input" > )} /> } > ( { onChange([value + ""]); }} /> )} /> } > ( { onChange([value + ""]); }} /> )} /> {providerType === "rsa" && ( <> } > ( )} /> } > ( { setKeyFileName(fileName); onChange([value]); }} /> )} /> } > ( { setCertificateFileName(fileName); onChange([value]); }} /> )} /> )}
); };