@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
45 lines • 2.27 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useAlerts, useFetch } from "../ui-shared";
import { AlertVariant, PageSection, PageSectionVariants, } from "@patternfly/react-core";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { useLocation } from "react-router-dom";
import { useAdminClient } from "../admin-client";
import { AttributesForm, } from "../components/key-value-form/AttributeForm";
import { arrayToKeyValue } from "../components/key-value-form/key-value-convert";
import { convertFormValuesToObject } from "../util";
import { getLastId } from "../groups/groupIdUtils";
export const GroupAttributes = () => {
var _a;
const { adminClient } = useAdminClient();
const { t } = useTranslation();
const { addAlert, addError } = useAlerts();
const form = useForm({
mode: "onChange",
});
const location = useLocation();
const id = getLastId(location.pathname);
const [currentGroup, setCurrentGroup] = useState();
useFetch(() => adminClient.groups.findOne({ id }), (group) => {
form.reset({
attributes: arrayToKeyValue(group === null || group === void 0 ? void 0 : group.attributes),
});
setCurrentGroup(group);
}, [id]);
const save = async (attributeForm) => {
try {
const attributes = convertFormValuesToObject(attributeForm).attributes;
await adminClient.groups.update({ id: id }, { ...currentGroup, attributes });
setCurrentGroup({ ...currentGroup, attributes });
addAlert(t("groupUpdated"), AlertVariant.success);
}
catch (error) {
addError("groupUpdateError", error);
}
};
return (_jsx(PageSection, { variant: PageSectionVariants.light, children: _jsx(AttributesForm, { form: form, save: save, fineGrainedAccess: (_a = currentGroup === null || currentGroup === void 0 ? void 0 : currentGroup.access) === null || _a === void 0 ? void 0 : _a.manage, reset: () => form.reset({
attributes: arrayToKeyValue(currentGroup === null || currentGroup === void 0 ? void 0 : currentGroup.attributes),
}) }) }));
};
//# sourceMappingURL=GroupAttributes.js.map