import { AlertVariant, Button, ButtonVariant, Form, FormGroup, Modal, ModalVariant, ValidatedOptions, } from "@patternfly/react-core"; import { useTranslation } from "react-i18next"; import { useForm } from "react-hook-form"; import type GroupRepresentation from "@keycloak/keycloak-admin-client/lib/defs/groupRepresentation"; import { useAdminClient } from "../context/auth/AdminClient"; import { useAlerts } from "../components/alert/Alerts"; import { capitalize } from "lodash-es"; import { useParams } from "react-router-dom"; import type FederatedIdentityRepresentation from "@keycloak/keycloak-admin-client/lib/defs/federatedIdentityRepresentation"; import type { UserParams } from "./routes/User"; import { KeycloakTextInput } from "../components/keycloak-text-input/KeycloakTextInput"; type UserIdpModalProps = { federatedId?: string; handleModalToggle: () => void; refresh: (group?: GroupRepresentation) => void; }; export const UserIdpModal = ({ federatedId, handleModalToggle, refresh, }: UserIdpModalProps) => { const { t } = useTranslation("users"); const { adminClient } = useAdminClient(); const { addAlert, addError } = useAlerts(); const { register, handleSubmit, formState: { isValid, errors }, } = useForm({ mode: "onChange", }); const { id } = useParams(); const submitForm = async (fedIdentity: FederatedIdentityRepresentation) => { try { await adminClient.users.addToFederatedIdentity({ id: id!, federatedIdentityId: federatedId!, federatedIdentity: fedIdentity, }); addAlert(t("users:idpLinkSuccess"), AlertVariant.success); handleModalToggle(); refresh(); } catch (error) { addError("users:couldNotLinkIdP", error); } }; return ( {t("link")} , , ]} >
); };