Simplified form control in Login and Register. Fixed registration bug. Throw better errors
This commit is contained in:
1 parent
7ce28b7042
commit
08565c9eda
6 files changed
+8
-37
No files matched your search
@@ -44,7 +44,7 @@ const Login = () => {
|
||||
} else {
|
||||
setErrors({});
|
||||
}
|
||||
}, []);
|
||||
}, [form]);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
@@ -77,15 +77,6 @@ const Login = () => {
|
||||
};
|
||||
|
||||
const handleInput = (e) => {
|
||||
const fieldName = idMap[e.target.id];
|
||||
// Extract and validate individual fields as input changes
|
||||
const fieldSchema = loginValidation.extract(fieldName);
|
||||
const { error } = fieldSchema.validate(e.target.value);
|
||||
let errMsg = "";
|
||||
if (error) {
|
||||
errMsg = error.message;
|
||||
}
|
||||
setErrors({ ...errors, [fieldName]: errMsg });
|
||||
const newForm = { ...form, [idMap[e.target.id]]: e.target.value };
|
||||
setForm(newForm);
|
||||
};
|
||||
|
||||
@@ -52,18 +52,9 @@ const Register = () => {
|
||||
} else {
|
||||
setErrors({});
|
||||
}
|
||||
}, []);
|
||||
}, [form]);
|
||||
|
||||
const handleInput = (e) => {
|
||||
const fieldName = idMap[e.target.id];
|
||||
// Extract and validate individual fields as input changes
|
||||
const fieldSchema = registerValidation.extract(fieldName);
|
||||
const { error } = fieldSchema.validate(e.target.value);
|
||||
let errMsg = "";
|
||||
if (error) {
|
||||
errMsg = error.message;
|
||||
}
|
||||
setErrors({ ...errors, [fieldName]: errMsg });
|
||||
const newForm = { ...form, [idMap[e.target.id]]: e.target.value };
|
||||
setForm(newForm);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user