import React from "react"; import { useHistory, useParams } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { Controller, FormProvider, useForm } from "react-hook-form"; import { AlertVariant, ButtonVariant, Divider, DropdownItem, Form, PageSection, Tab, TabTitleText, } from "@patternfly/react-core"; import type IdentityProviderRepresentation from "keycloak-admin/lib/defs/identityProviderRepresentation"; import { FormAccess } from "../../components/form-access/FormAccess"; import { ScrollForm } from "../../components/scroll-form/ScrollForm"; import { ViewHeader } from "../../components/view-header/ViewHeader"; import { useFetch, useAdminClient } from "../../context/auth/AdminClient"; import { toUpperCase } from "../../util"; import { GeneralSettings } from "./GeneralSettings"; import { AdvancedSettings } from "./AdvancedSettings"; import { useConfirmDialog } from "../../components/confirm-dialog/ConfirmDialog"; import { useAlerts } from "../../components/alert/Alerts"; import { useRealm } from "../../context/realm-context/RealmContext"; import { KeycloakTabs } from "../../components/keycloak-tabs/KeycloakTabs"; import { ExtendedNonDiscoverySettings } from "./ExtendedNonDiscoverySettings"; import { DiscoverySettings } from "./DiscoverySettings"; import { OIDCGeneralSettings } from "./OIDCGeneralSettings"; import { OIDCAuthentication } from "./OIDCAuthentication"; type HeaderProps = { onChange: (value: boolean) => void; value: boolean; save: () => void; toggleDeleteDialog: () => void; }; const Header = ({ onChange, value, save, toggleDeleteDialog }: HeaderProps) => { const { t } = useTranslation("identity-providers"); const { id } = useParams<{ id: string }>(); const [toggleDisableDialog, DisableConfirm] = useConfirmDialog({ titleKey: "identity-providers:disableProvider", messageKey: t("disableConfirm", { provider: id }), continueButtonLabel: "common:disable", onConfirm: () => { onChange(!value); save(); }, }); return ( <> toggleDeleteDialog()}> {t("common:delete")} , ]} isEnabled={value} onToggle={(value) => { if (!value) { toggleDisableDialog(); } else { onChange(value); save(); } }} /> ); }; export const DetailSettings = () => { const { t } = useTranslation("identity-providers"); const { id } = useParams<{ id: string }>(); const form = useForm(); const { handleSubmit, setValue, getValues } = form; const adminClient = useAdminClient(); const { addAlert } = useAlerts(); const history = useHistory(); const { realm } = useRealm(); useFetch( () => adminClient.identityProviders.findOne({ alias: id }), (provider) => { Object.entries(provider).map((entry) => setValue(entry[0], entry[1])); }, [] ); const save = async (provider?: IdentityProviderRepresentation) => { const p = provider || getValues(); try { await adminClient.identityProviders.update( { alias: id }, { ...p, alias: id, providerId: id } ); addAlert(t("updateSuccess"), AlertVariant.success); } catch (error) { addAlert( t("updateError", { error: error.response?.data?.errorMessage || error, }), AlertVariant.danger ); } }; const [toggleDeleteDialog, DeleteConfirm] = useConfirmDialog({ titleKey: "identity-providers:deleteProvider", messageKey: t("identity-providers:deleteConfirm", { provider: id }), continueButtonLabel: "common:delete", continueButtonVariant: ButtonVariant.danger, onConfirm: async () => { try { await adminClient.identityProviders.del({ alias: id }); addAlert(t("deletedSuccess"), AlertVariant.success); history.push(`/${realm}/identity-providers`); } catch (error) { addAlert(t("deleteErrorError", { error }), AlertVariant.danger); } }, }); const sections = [t("generalSettings"), t("advancedSettings")]; const isOIDC = id === "oidc"; if (isOIDC) { sections.splice(1, 0, t("oidcSettings")); } return ( <> (
)} /> {t("common:settings")}} > {!isOIDC && } {isOIDC && } {isOIDC && ( <>
)}
); };