@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
47 lines • 3.13 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { ActionGroup, AlertVariant, Button, PageSection, } from "@patternfly/react-core";
import { FormProvider, useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { Link, useNavigate } from "react-router-dom";
import { FormSubmitButton, SelectControl } from "../../ui-shared";
import { useAdminClient } from "../../admin-client";
import { useAlerts } from "../../ui-shared";
import { FormAccess } from "../../components/form/FormAccess";
import { ViewHeader } from "../../components/view-header/ViewHeader";
import { useRealm } from "../../context/realm-context/RealmContext";
import { toAuthentication } from "../../authentication/routes/Authentication";
import { toFlow } from "../../authentication/routes/Flow";
import { NameDescription } from "../../authentication/form/NameDescription";
const TYPES = ["basic-flow", "client-flow"];
export default function CreateFlow() {
const { adminClient } = useAdminClient();
const { t } = useTranslation();
const navigate = useNavigate();
const { realm } = useRealm();
const { addAlert } = useAlerts();
const form = useForm();
const { handleSubmit, formState } = form;
const onSubmit = async (formValues) => {
var _a, _b;
const flow = { ...formValues, builtIn: false, topLevel: true };
try {
const { id } = await adminClient.authenticationManagement.createFlow(flow);
addAlert(t("flowCreatedSuccess"), AlertVariant.success);
navigate(toFlow({
realm,
id: id,
usedBy: "notInUse",
}));
}
catch (error) {
addAlert(t("flowCreateError", {
error: ((_b = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.errorMessage) || error,
}), AlertVariant.danger);
}
};
return (_jsxs(_Fragment, { children: [_jsx(ViewHeader, { titleKey: "createFlow", subKey: "authenticationCreateFlowHelp" }), _jsx(PageSection, { variant: "light", children: _jsx(FormProvider, { ...form, children: _jsxs(FormAccess, { isHorizontal: true, role: "manage-authorization", onSubmit: handleSubmit(onSubmit), children: [_jsx(NameDescription, {}), _jsx(SelectControl, { name: "providerId", label: t("flowType"), labelIcon: t("topLevelFlowTypeHelp"), "aria-label": t("selectFlowType"), controller: { defaultValue: TYPES[0] }, options: TYPES.map((type) => ({
key: type,
value: t(`top-level-flow-type.${type}`),
})) }), _jsxs(ActionGroup, { children: [_jsx(FormSubmitButton, { formState: formState, "data-testid": "create", allowInvalid: true, allowNonDirty: true, children: t("create") }), _jsx(Button, { "data-testid": "cancel", variant: "link", component: (props) => (_jsx(Link, { ...props, to: toAuthentication({ realm }) })), children: t("cancel") })] })] }) }) })] }));
}
//# sourceMappingURL=CreateFlow.js.map