/* eslint-disable */ // @ts-nocheck import type ComponentRepresentation from "@keycloak/keycloak-admin-client/lib/defs/componentRepresentation"; import { TextControl, useAlerts, useFetch } from "../../../../shared/keycloak-ui-shared"; import { ActionGroup, AlertVariant, Button, PageSection, } from "../../../../shared/@patternfly/react-core"; import { FormProvider, useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; import { useAdminClient } from "../../../admin-client"; import { DynamicComponents } from "../../../components/dynamic/DynamicComponents"; import { FormAccess } from "../../../components/form/FormAccess"; import { ViewHeader } from "../../../components/view-header/ViewHeader"; import { useServerInfo } from "../../../context/server-info/ServerInfoProvider"; import { KEY_PROVIDER_TYPE } from "../../../util"; import { useParams } from "../../../utils/useParams"; import { KeyProviderParams, ProviderType } from "../../routes/KeyProvider"; import { toKeysTab } from "../../routes/KeysTab"; type KeyProviderFormProps = { id?: string; providerType: ProviderType; onClose?: () => void; }; export const KeyProviderForm = ({ providerType, onClose, }: KeyProviderFormProps) => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const { id } = useParams<{ id: string }>(); const { addAlert, addError } = useAlerts(); const serverInfo = useServerInfo(); const allComponentTypes = serverInfo.componentTypes?.[KEY_PROVIDER_TYPE] ?? []; const form = useForm({ mode: "onChange", }); const { handleSubmit, reset } = form; const save = async (component: ComponentRepresentation) => { if (component.config) Object.entries(component.config).forEach( ([key, value]) => (component.config![key] = Array.isArray(value) ? value : [value]), ); try { if (id) { await adminClient.components.update( { id }, { ...component, providerType: KEY_PROVIDER_TYPE, }, ); addAlert(t("saveProviderSuccess"), AlertVariant.success); } else { await adminClient.components.create({ ...component, providerId: providerType, providerType: KEY_PROVIDER_TYPE, }); addAlert(t("saveProviderSuccess"), AlertVariant.success); onClose?.(); } } catch (error) { addError("saveProviderError", error); } }; useFetch( async () => { if (id) return await adminClient.components.findOne({ id }); }, (result) => { if (result) { reset({ ...result }); } }, [], ); return ( {id && ( )} type.id === providerType) ?.properties || [] } /> ); }; export default function KeyProviderFormPage() { const { t } = useTranslation(); const params = useParams(); const navigate = useNavigate(); return ( <> navigate(toKeysTab({ realm: params.realm, tab: "providers" })) } /> ); }