@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
71 lines • 4.35 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useAlerts, useFetch } from "../ui-shared";
import { AlertVariant, PageSection, Tab, TabTitleText, } from "@patternfly/react-core";
import { useState } from "react";
import { FormProvider, useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { useParams } from "react-router-dom";
import { useAdminClient } from "../admin-client";
import { KeycloakSpinner } from "../ui-shared";
import { RoutableTabs, useRoutableTab, } from "../components/routable-tabs/RoutableTabs";
import { useRealm } from "../context/realm-context/RealmContext";
import { UserFederationLdapForm, serializeFormData, } from "../user-federation/UserFederationLdapForm";
import { LdapMapperList } from "../user-federation/ldap/mappers/LdapMapperList";
import { toUserFederationLdap, } from "../user-federation/routes/UserFederationLdap";
import { toUserFederationLdapMapper } from "../user-federation/routes/UserFederationLdapMapper";
import { ExtendedHeader } from "../user-federation/shared/ExtendedHeader";
export default function UserFederationLdapSettings() {
var _a;
const { adminClient } = useAdminClient();
const { t } = useTranslation();
const form = useForm({ mode: "onChange" });
const { realm } = useRealm();
const { id } = useParams();
const { addAlert, addError } = useAlerts();
const [component, setComponent] = useState();
const [refreshCount, setRefreshCount] = useState(0);
const refresh = () => setRefreshCount((count) => count + 1);
useFetch(() => adminClient.components.findOne({ id: id }), (component) => {
if (!component) {
throw new Error(t("notFound"));
}
setComponent(component);
setupForm(component);
}, [id, refreshCount]);
const useTab = (tab) => useRoutableTab(toUserFederationLdap({ realm, id: id, tab }));
const settingsTab = useTab("settings");
const mappersTab = useTab("mappers");
const setupForm = (component) => {
var _a, _b, _c, _d;
form.reset(component);
form.setValue("config.periodicChangedUsersSync", ((_b = (_a = component.config) === null || _a === void 0 ? void 0 : _a["changedSyncPeriod"]) === null || _b === void 0 ? void 0 : _b[0]) !== "-1");
form.setValue("config.periodicFullSync", ((_d = (_c = component.config) === null || _c === void 0 ? void 0 : _c["fullSyncPeriod"]) === null || _d === void 0 ? void 0 : _d[0]) !== "-1");
};
const onSubmit = async (formData) => {
try {
await adminClient.components.update({ id: id }, serializeFormData(formData));
addAlert(t("userProviderSaveSuccess"), AlertVariant.success);
refresh();
}
catch (error) {
addError("userProviderSaveError", error);
}
};
if (!component) {
return _jsx(KeycloakSpinner, {});
}
return (_jsxs(FormProvider, { ...form, children: [_jsx(ExtendedHeader, { provider: "LDAP", noDivider: true, editMode: (_a = component.config) === null || _a === void 0 ? void 0 : _a.editMode, save: () => form.handleSubmit(onSubmit)() }), _jsx(PageSection, { variant: "light", className: "pf-v5-u-p-0", children: _jsxs(RoutableTabs, { defaultLocation: toUserFederationLdap({
realm,
id: id,
tab: "settings",
}), isBox: true, children: [_jsx(Tab, { id: "settings", title: _jsx(TabTitleText, { children: t("settings") }), ...settingsTab, children: _jsx(PageSection, { variant: "light", children: _jsx(UserFederationLdapForm, { id: id, onSubmit: onSubmit }) }) }), _jsx(Tab, { id: "mappers", title: _jsx(TabTitleText, { children: t("mappers") }), "data-testid": "ldap-mappers-tab", ...mappersTab, children: _jsx(LdapMapperList, { toCreate: toUserFederationLdapMapper({
realm,
id: id,
mapperId: "new",
}), toDetail: (mapperId) => toUserFederationLdapMapper({
realm,
id: id,
mapperId,
}) }) })] }) })] }));
}
//# sourceMappingURL=UserFederationLdapSettings.js.map