@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
47 lines • 2.27 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { AlertVariant, PageSection } from "@patternfly/react-core";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import { useAdminClient } from "../admin-client";
import { useAlerts } from "../ui-shared";
import { changeScope, } from "../components/client-scope/ClientScopeTypes";
import { ViewHeader } from "../components/view-header/ViewHeader";
import { useRealm } from "../context/realm-context/RealmContext";
import { convertFormValuesToObject } from "../util";
import { ScopeForm } from "../client-scopes/details/ScopeForm";
import { toClientScope } from "../client-scopes/routes/ClientScope";
export default function CreateClientScope() {
const { adminClient } = useAdminClient();
const { t } = useTranslation();
const navigate = useNavigate();
const { realm } = useRealm();
const { addAlert, addError } = useAlerts();
const onSubmit = async (formData) => {
var _a;
const clientScope = convertFormValuesToObject({
...formData,
name: (_a = formData.name) === null || _a === void 0 ? void 0 : _a.trim().replace(/ /g, "_"),
});
try {
await adminClient.clientScopes.create(clientScope);
const scope = await adminClient.clientScopes.findOneByName({
name: clientScope.name,
});
if (!scope) {
throw new Error(t("notFound"));
}
await changeScope(adminClient, { ...clientScope, id: scope.id }, clientScope.type);
addAlert(t("createClientScopeSuccess", AlertVariant.success));
navigate(toClientScope({
realm,
id: scope.id,
tab: "settings",
}));
}
catch (error) {
addError("createClientScopeError", error);
}
};
return (_jsxs(_Fragment, { children: [_jsx(ViewHeader, { titleKey: "createClientScope" }), _jsx(PageSection, { variant: "light", className: "pf-v5-u-p-0", children: _jsx(PageSection, { variant: "light", children: _jsx(ScopeForm, { save: onSubmit }) }) })] }));
}
//# sourceMappingURL=CreateClientScope.js.map