diff --git a/src/common/component/styled/Input.tsx b/src/common/component/styled/Input.tsx index 78766939..2f4b31d6 100644 --- a/src/common/component/styled/Input.tsx +++ b/src/common/component/styled/Input.tsx @@ -93,6 +93,7 @@ interface Props | "onBlur" | "pattern" | "disabled" + | "minLength" >, HTMLInputElement > { diff --git a/src/routes/login/index.tsx b/src/routes/login/index.tsx index 1cf151c8..c3c20957 100644 --- a/src/routes/login/index.tsx +++ b/src/routes/login/index.tsx @@ -138,6 +138,7 @@ export default function LoginPage() { className="large" name="email" value={email} + type="email" required placeholder={t("placeholder_email")} data-type="email" diff --git a/src/routes/reg/Register.tsx b/src/routes/reg/Register.tsx index d1129ceb..86ae45e2 100644 --- a/src/routes/reg/Register.tsx +++ b/src/routes/reg/Register.tsx @@ -55,10 +55,6 @@ export default function Reg() { const handleReg = async (evt: FormEvent) => { evt.preventDefault(); const { email, password, confirmPassword } = input; - if (password.length < 6) { - toast.error("Password can't be less than 6 digits!"); - return; - } if (password !== confirmPassword) { toast.error("Not Same Password!"); return; @@ -123,6 +119,7 @@ export default function Reg() { name="email" value={email} required + type="email" placeholder={t("placeholder_email")} data-type="email" onChange={handleInput} @@ -133,6 +130,7 @@ export default function Reg() { value={password} name="password" required + minLength={6} data-type="password" onChange={handleInput} placeholder={t("placeholder_pwd")} @@ -141,6 +139,7 @@ export default function Reg() { required onBlur={handleCompare} type="password" + minLength={6} name={"confirmPassword"} value={confirmPassword} data-type="confirmPassword" diff --git a/src/routes/setting/MyAccount.tsx b/src/routes/setting/MyAccount.tsx index 77e485c9..33260640 100644 --- a/src/routes/setting/MyAccount.tsx +++ b/src/routes/setting/MyAccount.tsx @@ -100,12 +100,12 @@ const StyledWrapper = styled.div` border-radius: 8px; } `; -type EditFields = "name" | "email"; +type EditField = "name" | "email" | ""; export default function MyAccount() { const { t } = useTranslation("member"); const { t: ct } = useTranslation(); const [passwordModal, setPasswordModal] = useState(false); - const [editModal, setEditModal] = useState(null); + const [editModal, setEditModal] = useState(""); const [removeConfirmVisible, setRemoveConfirmVisible] = useState(false); const [uploadAvatar, { isSuccess: uploadSuccess }] = useUpdateAvatarMutation(); const EditModalInfo = { @@ -132,12 +132,12 @@ export default function MyAccount() { }, [uploadSuccess]); const handleBasicEdit = (evt: MouseEvent) => { - const { edit } = evt.currentTarget.dataset as { edit: EditFields }; + const { edit } = evt.currentTarget.dataset as { edit: EditField }; setEditModal(edit); }; const closeBasicEditModal = () => { - setEditModal(null); + setEditModal(""); }; const togglePasswordModal = () => { @@ -198,6 +198,7 @@ export default function MyAccount() { {editModal && ( = ({ label = "Username", valueKey = "name", value = "", + type = "text", title = "Change your username", intro = "Enter a new username and your existing password.", closeModal }) => { + const formRef = useRef(null); const { t } = useTranslation(); const [input, setInput] = useState(value); const [update, { isLoading, isSuccess }] = useUpdateInfoMutation(); @@ -48,6 +35,13 @@ const ProfileBasicEditModal: FC = ({ setInput(evt.target.value); }; const handleUpdate = () => { + if (!formRef || !formRef.current) return; + const formEle = formRef.current as HTMLFormElement; + if (!formEle.checkValidity()) { + formEle.reportValidity(); + return; + + } update({ [valueKey]: input }); }; useEffect(() => { @@ -59,7 +53,7 @@ const ProfileBasicEditModal: FC = ({ }, [isSuccess]); return ( - = ({ } > -
- - -
-
+
+ + +
+
); };