From d5132cf2c10ae1ddaf634109bd2a9192b679dcf7 Mon Sep 17 00:00:00 2001 From: dorj222 Date: Sat, 28 Jan 2023 16:38:33 +0100 Subject: [PATCH] update Textfield and TextFieldWithSubmit --- web/components/admin/TextField.tsx | 36 +++++++++++--------- web/components/admin/TextFieldWithSubmit.tsx | 10 +++++- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/web/components/admin/TextField.tsx b/web/components/admin/TextField.tsx index 4536fea19..2c04f4a2d 100644 --- a/web/components/admin/TextField.tsx +++ b/web/components/admin/TextField.tsx @@ -54,18 +54,19 @@ export const TextField: FC = ({ useTrim, value, }) => { - const [hasChanged, setHasChanged] = useState(false); + const [hasPwdChanged, setHasPwdChanged] = useState(false); + const [showPwdButton, setShowPwdButton] = useState(false); const regex = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#$%^&*]).{8,192}$/; const [form] = Form.useForm(); const handleChange = (e: any) => { // if an extra onChange handler was sent in as a prop, let's run that too. if (onChange) { const val = type === TEXTFIELD_TYPE_NUMBER ? e : e.target.value; - + setShowPwdButton(true); if (fieldName === 'adminPassword' && regex.test(val)) { - setHasChanged(true); + setHasPwdChanged(true); } else { - setHasChanged(false); + setHasPwdChanged(false); } onChange({ fieldName, value: useTrim ? val.trim() : val }); @@ -143,7 +144,7 @@ export const TextField: FC = ({ ) : null} - {fieldName !== 'adminPassword' ? ( + {type !== TEXTFIELD_TYPE_PASSWORD ? (
= ({ = ({ value={value as number | (readonly string[] & number)} /> -
- -
+ {showPwdButton && ( +
+ +
+ )}

{tip}

diff --git a/web/components/admin/TextFieldWithSubmit.tsx b/web/components/admin/TextFieldWithSubmit.tsx index bf39ab9e9..67613ac55 100644 --- a/web/components/admin/TextFieldWithSubmit.tsx +++ b/web/components/admin/TextFieldWithSubmit.tsx @@ -118,6 +118,14 @@ export const TextFieldWithSubmit: FC = ({ 'textfield-with-submit-container': true, submittable: hasChanged, }); + + const isPasswordInput = () => { + if (fieldName === 'adminPassword') { + return false; + } + return true; + }; + return (
@@ -135,7 +143,7 @@ export const TextFieldWithSubmit: FC = ({
{tip}
- {fieldName !== 'adminPassword' && ( + {isPasswordInput() && (