Skip to content
Snippets Groups Projects
Commit 80418a05 authored by mperezsa's avatar mperezsa
Browse files

Upload New File

parent fcf9c9aa
No related branches found
No related tags found
No related merge requests found
import { useState, useEffect } from "react";
const RegistrationForm = (Submit, validateRegistration) => {
const [user, setUser] = useState({
organizationName: "",
universityWebsite: "",
firstName: "",
lastName: "",
position: "Teacher",
profile: "",
email: "",
password: "",
});
const [errors, setErrors] = useState({});
const [isSubmitting, setIsSubmitting] = useState(false);
const handleChange = (e) => {
const fieldName = e.target.name;
const fieldValue = e.target.value;
setUser({ ...user, [fieldName]: fieldValue });
};
const handleSubmit = (e) => {
e.preventDefault();
setErrors(validateRegistration(user));
setIsSubmitting(true);
};
useEffect(() => {
// console.log(errors);
// console.log(isSubmitting);
if (Object.keys(errors).length === 0 && isSubmitting) {
Submit();
}
}, [errors]);
return { handleChange, handleSubmit, user, errors };
};
export default RegistrationForm;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment