disable test connection button if form fields not entered

This commit is contained in:
jenny-s51 2021-06-22 10:17:45 -04:00
parent 24df1b3f27
commit e6136b0d7e

View file

@ -6,6 +6,7 @@ import {
AlertVariant, AlertVariant,
Button, Button,
Checkbox, Checkbox,
formatBreakpointMods,
FormGroup, FormGroup,
PageSection, PageSection,
Switch, Switch,
@ -51,12 +52,15 @@ export const RealmSettingsEmailTab = ({
control, control,
handleSubmit, handleSubmit,
errors, errors,
watch,
setValue, setValue,
reset: resetForm, reset: resetForm,
getValues, getValues,
} = useForm<RealmRepresentation>(); } = useForm<RealmRepresentation>();
const userForm = useForm<UserRepresentation>({ mode: "onChange" }); const userForm = useForm<UserRepresentation>({ mode: "onChange" });
const watchFromValue = watch("smtpServer.from", "");
const watchHostValue = watch("smtpServer.host", "");
useEffect(() => { useEffect(() => {
reset(); reset();
@ -402,6 +406,9 @@ export const RealmSettingsEmailTab = ({
variant="secondary" variant="secondary"
onClick={() => saveAndTestEmail()} onClick={() => saveAndTestEmail()}
data-testid="test-connection-button" data-testid="test-connection-button"
isDisabled={
!(emailRegexPattern.test(watchFromValue) && watchHostValue)
}
> >
{t("realm-settings:testConnection")} {t("realm-settings:testConnection")}
</Button> </Button>