afix username/password fields

This commit is contained in:
jenny-s51 2021-06-22 11:19:13 -04:00
parent e565b3a3f8
commit 0a7387be6c

View file

@ -1,6 +1,6 @@
import React, { useContext, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { Controller, useForm } from "react-hook-form";
import { Controller, useForm, useWatch } from "react-hook-form";
import {
ActionGroup,
AlertVariant,
@ -42,7 +42,6 @@ export const RealmSettingsEmailTab = ({
const { addAlert } = useAlerts();
const { whoAmI } = useContext(WhoAmIContext);
const [isAuthenticationEnabled, setAuthenticationEnabled] = useState("true");
const [realm, setRealm] = useState(initialRealm);
const [userEmailModalOpen, setUserEmailModalOpen] = useState(false);
const [currentUser, setCurrentUser] = useState<UserRepresentation>();
@ -61,6 +60,12 @@ export const RealmSettingsEmailTab = ({
const watchFromValue = watch("smtpServer.from", "");
const watchHostValue = watch("smtpServer.host", "");
const authenticationEnabled = useWatch({
control,
name: "smtpServer.authentication",
defaultValue: realm?.smtpServer!.authentication,
});
useEffect(() => {
reset();
}, [realm]);
@ -329,7 +334,7 @@ export const RealmSettingsEmailTab = ({
<Controller
name="smtpServer.authentication"
control={control}
defaultValue="true"
defaultValue={authenticationEnabled}
render={({ onChange, value }) => (
<Switch
id="kc-authentication"
@ -339,13 +344,12 @@ export const RealmSettingsEmailTab = ({
isChecked={value === "true"}
onChange={(value) => {
onChange("" + value);
setAuthenticationEnabled(String(value));
}}
/>
)}
/>
</FormGroup>
{isAuthenticationEnabled === "true" && (
{authenticationEnabled === "true" && (
<>
<FormGroup
label={t("username")}