add more validations
This commit is contained in:
46
frontend/src/app/hooks/useOrganizationForm.jsx
Normal file
46
frontend/src/app/hooks/useOrganizationForm.jsx
Normal file
@@ -0,0 +1,46 @@
|
||||
"use client";
|
||||
import { useState } from "react";
|
||||
|
||||
const useOrganizationForm = () => {
|
||||
const [organizationName, setOrganizationName] = useState("");
|
||||
const [error, setError] = useState(false);
|
||||
const [triggerAlert, setTriggerAlert] = useState(false);
|
||||
|
||||
const handleChange = (e) => {
|
||||
const value = e.target.value;
|
||||
setOrganizationName(value);
|
||||
|
||||
if (value.trim() !== "") {
|
||||
setError(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleValidation = (e) => {
|
||||
e.preventDefault();
|
||||
setError(true);
|
||||
};
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (!organizationName.trim()) {
|
||||
setError(true);
|
||||
return;
|
||||
}
|
||||
setTriggerAlert(true);
|
||||
|
||||
console.log("Submitted organization:", organizationName);
|
||||
};
|
||||
|
||||
return {
|
||||
organizationName,
|
||||
error,
|
||||
triggerAlert,
|
||||
handleChange,
|
||||
handleValidation,
|
||||
handleSubmit,
|
||||
setTriggerAlert,
|
||||
};
|
||||
};
|
||||
|
||||
export default useOrganizationForm;
|
||||
Reference in New Issue
Block a user