UNPKG

@keycloakify/keycloak-admin-ui

Version:
55 lines 3.12 kB
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime"; import { AlertVariant, Divider, FormGroup, PageSection, Switch, } from "@patternfly/react-core"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { HelpItem } from "../../ui-shared"; import { useAdminClient } from "../../admin-client"; import { useAlerts } from "../../ui-shared"; import { FormAccess } from "../../components/form/FormAccess"; import { RoleMapping } from "../../components/role-mapping/RoleMapping"; import { useAccess } from "../../context/access/Access"; export const DedicatedScope = ({ client: initialClient, }) => { var _a, _b; const { adminClient } = useAdminClient(); const { t } = useTranslation(); const { addAlert, addError } = useAlerts(); const [client, setClient] = useState(initialClient); const { hasAccess } = useAccess(); const isManager = hasAccess("manage-clients") || ((_a = client.access) === null || _a === void 0 ? void 0 : _a.manage); const assignRoles = async (rows) => { try { const realmRoles = rows .filter((row) => row.client === undefined) .map((row) => row.role) .flat(); await Promise.all([ adminClient.clients.addRealmScopeMappings({ id: client.id, }, realmRoles), ...rows .filter((row) => row.client !== undefined) .map((row) => adminClient.clients.addClientScopeMappings({ id: client.id, client: row.client.id, }, [row.role])), ]); addAlert(t("clientScopeSuccess"), AlertVariant.success); } catch (error) { addError("clientScopeError", error); } }; const update = async () => { const newClient = { ...client, fullScopeAllowed: !client.fullScopeAllowed }; try { await adminClient.clients.update({ id: client.id }, newClient); addAlert(t("clientScopeSuccess"), AlertVariant.success); setClient(newClient); } catch (error) { addError("clientScopeError", error); } }; return (_jsxs(PageSection, { children: [_jsx(FormAccess, { role: "manage-clients", fineGrainedAccess: (_b = client.access) === null || _b === void 0 ? void 0 : _b.manage, isHorizontal: true, children: _jsx(FormGroup, { hasNoPaddingTop: true, label: t("fullScopeAllowed"), labelIcon: _jsx(HelpItem, { helpText: t("fullScopeAllowedHelp"), fieldLabelId: "fullScopeAllowed" }), fieldId: "fullScopeAllowed", children: _jsx(Switch, { id: "fullScopeAllowed", label: t("on"), labelOff: t("off"), isChecked: client.fullScopeAllowed, onChange: update, "aria-label": t("fullScopeAllowed") }) }) }), !client.fullScopeAllowed && (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsx(RoleMapping, { name: client.clientId, id: client.id, type: "clients", save: assignRoles, isManager: isManager })] }))] })); }; //# sourceMappingURL=DedicatedScope.js.map