1
import type AuthenticationFlowRepresentation from "@keycloak/keycloak-admin-client/lib/defs/authenticationFlowRepresentation";
9
} from "@patternfly/react-core";
10
import { useEffect } from "react";
11
import { FormProvider, useForm } from "react-hook-form";
13
import { useTranslation } from "react-i18next";
14
import { adminClient } from "../admin-client";
15
import { useAlerts } from "../components/alert/Alerts";
16
import { NameDescription } from "./form/NameDescription";
18
type EditFlowModalProps = {
19
flow: AuthenticationFlowRepresentation;
20
toggleDialog: () => void;
23
export const EditFlowModal = ({ flow, toggleDialog }: EditFlowModalProps) => {
24
const { t } = useTranslation();
25
const { addAlert, addError } = useAlerts();
26
const form = useForm<AuthenticationFlowRepresentation>({ mode: "onChange" });
27
const { reset, handleSubmit } = form;
29
useEffect(() => reset(flow), [flow]);
31
const onSubmit = async (formValues: AuthenticationFlowRepresentation) => {
33
await adminClient.authenticationManagement.updateFlow(
35
{ ...flow, ...formValues },
37
addAlert(t("updateFlowSuccess"), AlertVariant.success);
39
addError("updateFlowError", error);
47
onClose={toggleDialog}
48
variant={ModalVariant.small}
61
variant={ButtonVariant.link}
62
onClick={() => toggleDialog()}
69
<FormProvider {...form}>
72
onSubmit={handleSubmit(onSubmit)}