@keycloakify/keycloak-admin-ui
Version:
Repackaged Keycloak Admin UI
31 lines • 2.56 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { SelectControl, TextControl, useFetch, } from "../../../ui-shared";
import { Button, ButtonVariant, Form, Modal, ModalVariant, } from "@patternfly/react-core";
import { useEffect, useState } from "react";
import { FormProvider, useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { useAdminClient } from "../../../admin-client";
const types = ["basic-flow", "form-flow"];
export const AddSubFlowModal = ({ name, onConfirm, onCancel, }) => {
const { adminClient } = useAdminClient();
const { t } = useTranslation();
const form = useForm();
const [formProviders, setFormProviders] = useState();
useFetch(() => adminClient.authenticationManagement.getFormProviders(), setFormProviders, []);
useEffect(() => {
if ((formProviders === null || formProviders === void 0 ? void 0 : formProviders.length) === 1) {
form.setValue("provider", formProviders[0].id);
}
}, [formProviders]);
return (_jsx(Modal, { variant: ModalVariant.medium, title: t("addStepTo", { name }), onClose: onCancel, actions: [
_jsx(Button, { "data-testid": "modal-add", type: "submit", form: "sub-flow-form", children: t("add") }, "add"),
_jsx(Button, { "data-testid": "cancel", variant: ButtonVariant.link, onClick: onCancel, children: t("cancel") }, "cancel"),
], isOpen: true, children: _jsx(Form, { id: "sub-flow-form", onSubmit: form.handleSubmit(onConfirm), isHorizontal: true, children: _jsxs(FormProvider, { ...form, children: [_jsx(TextControl, { name: "name", label: t("name"), labelIcon: t("clientIdHelp"), rules: { required: { value: true, message: t("required") } } }), _jsx(TextControl, { name: "description", label: t("description"), labelIcon: t("flowNameDescriptionHelp") }), _jsx(SelectControl, { name: "type", menuAppendTo: "parent", label: t("flowType"), options: types.map((type) => ({
key: type,
value: t(`flow-type.${type}`),
})), controller: { defaultValue: types[0] } }), formProviders && formProviders.length > 1 && (_jsx(SelectControl, { name: "provider", label: t("provider"), labelIcon: t("authenticationFlowTypeHelp"), options: formProviders.map((provider) => ({
key: provider.id,
value: provider.displayName,
})), controller: { defaultValue: "" } }))] }) }) }));
};
//# sourceMappingURL=AddSubFlowModal.js.map