aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/views/register
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-04-29 23:15:47 +0800
committercrupest <crupest@outlook.com>2022-04-29 23:15:47 +0800
commit96440778a85cd5106959b7a779080ad90e6ccbdb (patch)
tree069d1be2cc5190ba6a6975c76c568801bea0badd /FrontEnd/src/views/register
parentb46c397989df15149803cc1607448dd83c8781a7 (diff)
downloadtimeline-96440778a85cd5106959b7a779080ad90e6ccbdb.tar.gz
timeline-96440778a85cd5106959b7a779080ad90e6ccbdb.tar.bz2
timeline-96440778a85cd5106959b7a779080ad90e6ccbdb.zip
...
Diffstat (limited to 'FrontEnd/src/views/register')
-rw-r--r--FrontEnd/src/views/register/index.tsx26
1 files changed, 25 insertions, 1 deletions
diff --git a/FrontEnd/src/views/register/index.tsx b/FrontEnd/src/views/register/index.tsx
index 9108b789..a08dca09 100644
--- a/FrontEnd/src/views/register/index.tsx
+++ b/FrontEnd/src/views/register/index.tsx
@@ -7,8 +7,27 @@ const RegisterPage: React.FC = () => {
const [confirmPassword, setConfirmPassword] = React.useState<string>("");
const [registerCode, setRegisterCode] = React.useState<string>("");
+ const [dirty, setDirty] = React.useState<boolean[]>(new Array(4).fill(false));
+
const [error, setError] = React.useState<InputPanelError>();
+ 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 (
<div>
<InputPanel
@@ -30,11 +49,16 @@ const RegisterPage: React.FC = () => {
{ type: "text", label: "register.registerCode" },
]}
values={[username, password, confirmPassword, registerCode]}
- onChange={(values) => {
+ onChange={(values, index) => {
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}
/>