import React from "react"; import InputPanel, { InputPanelError } from "../common/input/InputPanel"; const RegisterPage: React.FC = () => { const [username, setUsername] = React.useState(""); const [password, setPassword] = React.useState(""); const [confirmPassword, setConfirmPassword] = React.useState(""); const [registerCode, setRegisterCode] = React.useState(""); const [dirty, setDirty] = React.useState(new Array(4).fill(false)); const [error, setError] = React.useState(); const validate = (): InputPanelError => { const e: InputPanelError = {}; if (dirty[0] && username.length === 0) { e[0] = "register.error.usernameEmpty"; } if (dirty[1] && password.length === 0) { e[1] = "register.error.passwordEmpty"; } if (dirty[2] && confirmPassword !== password) { e[2] = "register.error.confirmPasswordWrong"; } if (dirty[3] && registerCode.length === 0) { e[3] = "register.error.registerCodeEmpty"; } return e; }; return (
{ setUsername(values[0]); setPassword(values[1]); setConfirmPassword(values[2]); setRegisterCode(values[3]); const newDirty = dirty.slice(); newDirty[index] = true; setDirty(newDirty); setError(validate()); }} error={error} />
); }; export default RegisterPage;