import React, { useState } from "react"; import { AlertVariant, Button, ButtonVariant, 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 AESGeneratedModalProps = { providerType?: string; handleModalToggle?: () => void; refresh?: () => void; open: boolean; }; export const AESGeneratedModal = ({ providerType, handleModalToggle, open, refresh, }: // save, AESGeneratedModalProps) => { const { t } = useTranslation("groups"); const serverInfo = useServerInfo(); const adminClient = useAdminClient(); const { addAlert } = useAlerts(); const { handleSubmit, control } = useForm({}); const [isKeySizeDropdownOpen, setIsKeySizeDropdownOpen] = useState(false); const [displayName, setDisplayName] = useState(""); const realm = useRealm(); 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 === "aes-generated" && ( } > ( )} /> )}
); };