@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
59 lines • 4.21 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { FormSubmitButton, useAlerts, useFetch, } from "../ui-shared";
import { ActionGroup, Button, PageSection, Tab, TabTitleText, } from "@patternfly/react-core";
import { FormProvider, useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { useAdminClient } from "../admin-client";
import { FormAccess } from "../components/form/FormAccess";
import { AttributesForm } from "../components/key-value-form/AttributeForm";
import { arrayToKeyValue } from "../components/key-value-form/key-value-convert";
import { RoutableTabs, useRoutableTab, } from "../components/routable-tabs/RoutableTabs";
import { useRealm } from "../context/realm-context/RealmContext";
import { useParams } from "../utils/useParams";
import { DetailOrganizationHeader } from "../organizations/DetailOraganzationHeader";
import { IdentityProviders } from "../organizations/IdentityProviders";
import { Members } from "../organizations/Members";
import { OrganizationForm, convertToOrg, } from "../organizations/OrganizationForm";
import { toEditOrganization, } from "../organizations/routes/EditOrganization";
export default function DetailOrganization() {
const { adminClient } = useAdminClient();
const { addAlert, addError } = useAlerts();
const { realm } = useRealm();
const { id } = useParams();
const { t } = useTranslation();
const form = useForm();
const save = async (org) => {
try {
const organization = convertToOrg(org);
await adminClient.organizations.updateById({ id }, organization);
addAlert(t("organizationSaveSuccess"));
}
catch (error) {
addError("organizationSaveError", error);
}
};
useFetch(() => adminClient.organizations.findOne({ id }), (org) => {
var _a;
if (!org) {
throw new Error(t("notFound"));
}
form.reset({
...org,
domains: (_a = org.domains) === null || _a === void 0 ? void 0 : _a.map((d) => d.name),
attributes: arrayToKeyValue(org.attributes),
});
}, [id]);
const useTab = (tab) => useRoutableTab(toEditOrganization({
realm,
id,
tab,
}));
const settingsTab = useTab("settings");
const attributesTab = useTab("attributes");
const membersTab = useTab("members");
const identityProvidersTab = useTab("identityProviders");
return (_jsx(PageSection, { variant: "light", className: "pf-v5-u-p-0", children: _jsxs(FormProvider, { ...form, children: [_jsx(DetailOrganizationHeader, { save: () => save(form.getValues()) }), _jsxs(RoutableTabs, { "data-testid": "organization-tabs", "aria-label": t("organization"), isBox: true, mountOnEnter: true, children: [_jsx(Tab, { id: "settings", "data-testid": "settingsTab", title: _jsx(TabTitleText, { children: t("settings") }), ...settingsTab, children: _jsx(PageSection, { children: _jsxs(FormAccess, { role: "anyone", onSubmit: form.handleSubmit(save), isHorizontal: true, children: [_jsx(OrganizationForm, { readOnly: true }), _jsxs(ActionGroup, { children: [_jsx(FormSubmitButton, { formState: form.formState, "data-testid": "save", children: t("save") }), _jsx(Button, { onClick: () => form.reset(), "data-testid": "reset", variant: "link", children: t("reset") })] })] }) }) }), _jsx(Tab, { id: "attributes", "data-testid": "attributeTab", title: _jsx(TabTitleText, { children: t("attributes") }), ...attributesTab, children: _jsx(PageSection, { variant: "light", children: _jsx(AttributesForm, { form: form, save: save, reset: () => form.reset({
...form.getValues(),
}), name: "attributes" }) }) }), _jsx(Tab, { id: "members", "data-testid": "membersTab", title: _jsx(TabTitleText, { children: t("members") }), ...membersTab, children: _jsx(Members, {}) }), _jsx(Tab, { id: "identityProviders", "data-testid": "identityProvidersTab", title: _jsx(TabTitleText, { children: t("identityProviders") }), ...identityProvidersTab, children: _jsx(IdentityProviders, {}) })] })] }) }));
}
//# sourceMappingURL=DetailOrganization.js.map