diff --git a/src/components/Employee/ManageEmployee.jsx b/src/components/Employee/ManageEmployee.jsx
index 2ece873e..224153c8 100644
--- a/src/components/Employee/ManageEmployee.jsx
+++ b/src/components/Employee/ManageEmployee.jsx
@@ -30,7 +30,9 @@ const ManageEmployee = () => {
const [isloading, setLoading] = useState(false);
const navigation = useNavigate();
const [currentEmployee, setCurrentEmployee] = useState();
-
+ const [currentAddressLength, setCurrentAddressLength] = useState(0);
+ const [permanentAddressLength, setPermanentAddressLength] = useState(0);
+
const userSchema = z.object({
...(employeeId ? { Id: z.number().optional() } : {}),
FirstName: z.string().min(1, { message: "First Name is required" }),
@@ -217,6 +219,8 @@ const ManageEmployee = () => {
}
: {} // Empty object resets the form
);
+ setCurrentAddressLength(currentEmployee?.currentAddress?.length || 0);
+ setPermanentAddressLength(currentEmployee?.permanentAddress?.length || 0);
}, [currentEmployee, reset]);
return (
@@ -430,12 +434,17 @@ const ManageEmployee = () => {
aria-label="Current Address"
aria-describedby="basic-icon-default-message2"
{...register("CurrentAddress")}
+ onChange={(e) => {
+ setCurrentAddressLength(e.target.value.length);
+ // let react-hook-form still handle it
+ register("CurrentAddress").onChange(e);
+ }}
>
+
+ {500 - currentAddressLength} characters left
+
{errors.CurrentAddress && (
-
+
{errors.CurrentAddress.message}
)}
@@ -452,12 +461,16 @@ const ManageEmployee = () => {
aria-label="Permanent Address"
aria-describedby="basic-icon-default-message2"
{...register("PermanentAddress")}
+ onChange={(e) => {
+ setPermanentAddressLength(e.target.value.length);
+ register("PermanentAddress").onChange(e);
+ }}
>
+
+ {500 - permanentAddressLength} characters left
+
{errors.PermanentAddress && (
-
+
{errors.PermanentAddress.message}
)}
diff --git a/src/components/Project/ManageProjectInfo.jsx b/src/components/Project/ManageProjectInfo.jsx
index 08808fa8..88cbb5d7 100644
--- a/src/components/Project/ManageProjectInfo.jsx
+++ b/src/components/Project/ManageProjectInfo.jsx
@@ -21,8 +21,9 @@ const ManageProjectInfo = ( {project,handleSubmitForm, onClose} ) =>
const [CurrentProject,setCurrentProject] = useState()
const [ isloading, setLoading ] = useState( false )
-
-
+ const [addressLength, setAddressLength] = useState(0);
+ const maxAddressLength = 500;
+
const projectSchema = z.object( {
...(project?.id ? { id: z.number().optional() } : {}),
name: z.string().min( 1, {message: "Project Name is required"} ),
@@ -79,7 +80,9 @@ const ManageProjectInfo = ( {project,handleSubmitForm, onClose} ) =>
projectStatusId: String(project.projectStatusId) || "0" ,
} :{}
+
)
+ setAddressLength(project?.projectAddress?.length || 0);
},[project,reset,])
@@ -205,16 +208,20 @@ const ManageProjectInfo = ( {project,handleSubmitForm, onClose} ) =>
+
+ {maxAddressLength - addressLength} characters left
+
{errors.projectAddress &&
{errors.projectAddress.message}
}
-
-
+
+
+ {maxDescriptionLength - descriptionLength} characters left
+
{errors.description && (
{errors.description.message}
)}
diff --git a/src/components/master/CreateRole.jsx b/src/components/master/CreateRole.jsx
index 48c2fa3c..ae9ce302 100644
--- a/src/components/master/CreateRole.jsx
+++ b/src/components/master/CreateRole.jsx
@@ -73,6 +73,11 @@ const onSubmit = (values) => {
};
+const [descriptionLength, setDescriptionLength] = useState(0);
+const maxDescriptionLength = 255;
+useEffect(() => {
+ setDescriptionLength(0);
+}, []);
return (
@@ -91,11 +96,20 @@ const onSubmit = (values) => {
-
+
+
+ {maxDescriptionLength - descriptionLength} characters left
+
+
{errors.description && (
{errors.description.message}
)}
diff --git a/src/components/master/EditJobRole.jsx b/src/components/master/EditJobRole.jsx
index 0f12e5ea..55d9228c 100644
--- a/src/components/master/EditJobRole.jsx
+++ b/src/components/master/EditJobRole.jsx
@@ -64,13 +64,17 @@ const EditJobRole = ({data,onClose}) => {
};
- useEffect(()=>{
+ useEffect(() => {
reset({
- role:data?.name,
- description:data?.description
- })
+ role: data?.name,
+ description: data?.description
+ });
+ setDescriptionLength(data?.description?.length || 0);
+ }, [data, reset]);
- },[data,reset])
+ const [descriptionLength, setDescriptionLength] = useState(data?.description?.length || 0);
+ const maxDescriptionLength = 255;
+
return (<>
-
- {errors.description && (
-
{errors.description.message}
- )}
+
+
+ {maxDescriptionLength - descriptionLength} characters left
+
+ {errors.description && (
+
{errors.description.message}
+ )}
+
diff --git a/src/components/master/EditRole.jsx b/src/components/master/EditRole.jsx
index 51652f05..4cb658e4 100644
--- a/src/components/master/EditRole.jsx
+++ b/src/components/master/EditRole.jsx
@@ -121,13 +121,18 @@ const EditMaster=({master,onClose})=> {
};
- useEffect(()=>{
+ useEffect(() => {
reset({
role: master?.item?.role,
description: master?.item?.description,
permissions: initialPermissions,
- })
- },[master,reset])
+ });
+ setDescriptionLength(master?.item?.description?.length || 0);
+ }, [master, reset]);
+
+ const [descriptionLength, setDescriptionLength] = useState(master?.item?.description?.length || 0);
+ const maxDescriptionLength = 255;
+
return (
@@ -144,14 +149,21 @@ const EditMaster=({master,onClose})=> {
-
- {errors.description && (
-
{errors.description.message}
- )}
+
+
+ {maxDescriptionLength - descriptionLength} characters left
+
+ {errors.description && (
+
{errors.description.message}
+ )}