diff --git a/app/src/tasks/TaskForm.tsx b/app/src/tasks/TaskForm.tsx index bade110a..65ec0ea7 100644 --- a/app/src/tasks/TaskForm.tsx +++ b/app/src/tasks/TaskForm.tsx @@ -15,7 +15,12 @@ import FormControl from "react-bootstrap/FormControl"; import FormGroup from "react-bootstrap/FormGroup"; import FormLabel from "react-bootstrap/FormLabel"; import FormSelect from "react-bootstrap/FormSelect"; -import React, { ChangeEvent, ChangeEventHandler, Suspense } from "react"; +import React, { + ChangeEvent, + ChangeEventHandler, + Suspense, + useEffect, +} from "react"; import Row from "react-bootstrap/Row"; import { ApiClientContext } from "../ApiClientContext"; import { LinkContainer } from "react-router-bootstrap"; @@ -626,6 +631,13 @@ function HpkeConfigSelect(props: Props) { const { hpkeConfigs } = useLoaderData() as { hpkeConfigs: Promise; }; + const { setFieldValue } = props; + + useEffect(() => { + hpkeConfigs.then((configs) => { + if (configs.length === 1) setFieldValue("hpke_config_id", configs[0].id); + }); + }, [hpkeConfigs, setFieldValue]); return ( @@ -633,8 +645,13 @@ function HpkeConfigSelect(props: Props) { fieldKey="hpke_config_id" setFocusedField={props.setFocusedField} /> - - ...}> + + + ...}> {(hpkeConfigs: HpkeConfig[]) => hpkeConfigs.map((hpkeConfig) => ( @@ -646,6 +663,9 @@ function HpkeConfigSelect(props: Props) { + + {props.errors.hpke_config_id} + ); }