diff --git a/web/components/admin/TextField.tsx b/web/components/admin/TextField.tsx index 2c04f4a2d..6e2bd5e74 100644 --- a/web/components/admin/TextField.tsx +++ b/web/components/admin/TextField.tsx @@ -31,6 +31,7 @@ export type TextFieldProps = { useTrim?: boolean; useTrimLead?: boolean; value?: string | number; + isAdminPwdField?: boolean; onBlur?: FieldUpdaterFunc; onChange?: FieldUpdaterFunc; }; @@ -53,6 +54,7 @@ export const TextField: FC = ({ type, useTrim, value, + isAdminPwdField, }) => { const [hasPwdChanged, setHasPwdChanged] = useState(false); const [showPwdButton, setShowPwdButton] = useState(false); @@ -63,7 +65,7 @@ export const TextField: FC = ({ if (onChange) { const val = type === TEXTFIELD_TYPE_NUMBER ? e : e.target.value; setShowPwdButton(true); - if (fieldName === 'adminPassword' && regex.test(val)) { + if (isAdminPwdField && regex.test(val)) { setHasPwdChanged(true); } else { setHasPwdChanged(false); @@ -144,7 +146,7 @@ export const TextField: FC = ({ ) : null} - {type !== TEXTFIELD_TYPE_PASSWORD ? ( + {!isAdminPwdField ? (
{}, onBlur: () => {}, diff --git a/web/components/admin/TextFieldWithSubmit.tsx b/web/components/admin/TextFieldWithSubmit.tsx index 944257f03..5dc633d4c 100644 --- a/web/components/admin/TextFieldWithSubmit.tsx +++ b/web/components/admin/TextFieldWithSubmit.tsx @@ -24,6 +24,7 @@ export type TextFieldWithSubmitProps = TextFieldProps & { apiPath: string; configPath?: string; initialValue?: string; + isAdminPwdField?: boolean; }; export const TextFieldWithSubmit: FC = ({ @@ -38,13 +39,13 @@ export const TextFieldWithSubmit: FC = ({ const [hasChanged, setHasChanged] = useState(false); - const [isPwdInput, setPwdInputField] = useState(false); const serverStatusData = useContext(ServerStatusContext); const { setFieldInConfigState } = serverStatusData || {}; let resetTimer = null; - const { fieldName, required, tip, status, value, onChange, onSubmit } = textFieldProps; + const { fieldName, required, tip, status, value, isAdminPwdField, onChange, onSubmit } = + textFieldProps; // Clear out any validation states and messaging const resetStates = () => { @@ -67,13 +68,6 @@ export const TextFieldWithSubmit: FC = ({ } }, [value]); - useEffect(() => { - if (fieldName === 'adminPassword') { - setPwdInputField(true); - } - setPwdInputField(false); - }, [fieldName]); - // if field is required but value is empty, or equals initial value, then don't show submit/update button. otherwise clear out any result messaging and display button. const handleChange = ({ fieldName: changedFieldName, value: changedValue }: UpdateArgs) => { if (onChange) { @@ -144,7 +138,7 @@ export const TextFieldWithSubmit: FC = ({
{tip}
- {isPwdInput && ( + {!isAdminPwdField && (