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 { useParams } from "react-router-dom"; type RSAModalProps = { providerType: string; handleModalToggle: () => void; refresh: () => void; open: boolean; }; export const RSAModal = ({ providerType, handleModalToggle, open, refresh, }: RSAModalProps) => { const { t } = useTranslation("realm-settings"); const serverInfo = useServerInfo(); const adminClient = useAdminClient(); const { addAlert } = useAlerts(); const { handleSubmit, control } = useForm({}); const [isRSAalgDropdownOpen, setIsRSAalgDropdownOpen] = useState(false); const { id } = useParams<{ id: string }>(); const [keyFileName, setKeyFileName] = useState(""); const [certificateFileName, setCertificateFileName] = useState(""); const allComponentTypes = serverInfo.componentTypes?.["org.keycloak.keys.KeyProvider"] ?? []; const save = async (component: ComponentRepresentation) => { try { if (id) { await adminClient.components.update( { id }, { ...component, parentId: component.parentId, providerId: providerType, providerType: "org.keycloak.keys.KeyProvider", } ); addAlert(t("saveProviderSuccess"), AlertVariant.success); } else { await adminClient.components.create({ ...component, parentId: component.parentId, providerId: providerType, providerType: "org.keycloak.keys.KeyProvider", }); handleModalToggle(); addAlert(t("saveProviderSuccess"), AlertVariant.success); refresh(); } } catch (error) { addAlert( t("saveProviderError", { error: error.response?.data?.errorMessage || error, }), AlertVariant.danger ); } }; return ( {t("common:Add")} , , ]} >
} > ( { onChange(value); }} data-testid="display-name-input" > )} /> } > ( { onChange([value + ""]); }} /> )} /> } > ( { onChange([value + ""]); }} /> )} /> {providerType === "rsa" && ( <> } > ( )} /> } > ( { setKeyFileName(fileName); onChange([value]); }} /> )} /> } > ( { setCertificateFileName(fileName); onChange([value]); }} /> )} /> )}
); };