UNPKG

@keycloakify/keycloak-admin-ui

Version:
38 lines 2.3 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { AlertVariant, Button, ButtonVariant, Form, Modal, } from "@patternfly/react-core"; import { FormProvider, useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { SelectControl } from "../ui-shared"; import { useAlerts } from "../ui-shared"; import { useRealm } from "../context/realm-context/RealmContext"; import { REALM_FLOWS } from "../authentication/AuthenticationSection"; import { useAdminClient } from "../admin-client"; export const BindFlowDialog = ({ flowAlias, onClose }) => { const { adminClient } = useAdminClient(); const { t } = useTranslation(); const form = useForm(); const { addAlert, addError } = useAlerts(); const { realm, realmRepresentation: realmRep, refresh } = useRealm(); const onSubmit = async ({ bindingType }) => { try { await adminClient.realms.update({ realm }, { ...realmRep, [bindingType]: flowAlias }); refresh(); addAlert(t("updateFlowSuccess"), AlertVariant.success); } catch (error) { addError("updateFlowError", error); } onClose(true); }; const flowKeys = Array.from(REALM_FLOWS.keys()); return (_jsx(Modal, { title: t("bindFlow"), variant: "small", onClose: () => onClose(), actions: [ _jsx(Button, { "data-testid": "save", type: "submit", form: "bind-form", children: t("save") }, "confirm"), _jsx(Button, { "data-testid": "cancel", variant: ButtonVariant.link, onClick: () => onClose(), children: t("cancel") }, "cancel"), ], isOpen: true, children: _jsx(Form, { id: "bind-form", isHorizontal: true, onSubmit: form.handleSubmit(onSubmit), children: _jsx(FormProvider, { ...form, children: _jsx(SelectControl, { id: "chooseBindingType", name: "bindingType", label: t("chooseBindingType"), options: flowKeys .filter((f) => f !== "dockerAuthenticationFlow") .map((key) => ({ key, value: t(`flow.${REALM_FLOWS.get(key)}`), })), controller: { defaultValue: flowKeys[0] }, menuAppendTo: "parent", "aria-label": t("chooseBindingType") }) }) }) })); }; //# sourceMappingURL=BindFlowDialog.js.map