UNPKG

@keycloakify/keycloak-admin-ui

Version:
54 lines 2.14 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { AlertVariant } from "@patternfly/react-core"; import { FormProvider, useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { useNavigate, useParams } from "react-router-dom"; import { useAdminClient } from "../../admin-client"; import { useAlerts } from "../../ui-shared"; import { RoleForm } from "../../components/role-form/RoleForm"; import { useRealm } from "../../context/realm-context/RealmContext"; import { toClient } from "../../clients/routes/Client"; import { toClientRole } from "../../clients/routes/ClientRole"; export default function CreateClientRole() { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const form = useForm({ mode: "onChange" }); const navigate = useNavigate(); const { clientId } = useParams(); const { realm } = useRealm(); const { addAlert, addError } = useAlerts(); const onSubmit = async (formValues) => { var _a; const role = { ...formValues, name: (_a = formValues.name) === null || _a === void 0 ? void 0 : _a.trim(), attributes: {}, }; try { await adminClient.clients.createRole({ id: clientId, ...role, }); const createdRole = (await adminClient.clients.findRole({ id: clientId, roleName: role.name, })); addAlert(t("roleCreated"), AlertVariant.success); navigate(toClientRole({ realm, clientId: clientId, id: createdRole.id, tab: "details", })); } catch (error) { addError("roleCreateError", error); } }; return (_jsx(FormProvider, { ...form, children: _jsx(RoleForm, { form: form, onSubmit: onSubmit, cancelLink: toClient({ realm, clientId: clientId, tab: "roles", }), role: "manage-clients", editMode: false }) })); } //# sourceMappingURL=CreateClientRole.js.map