Merge branch 'Ashutosh_Enhancement#132_Int_To_Guid' of https://git.marcoaiot.com/admin/marco.pms.web into Ashutosh_Enhancement#132_Int_To_Guid
This commit is contained in:
commit
0c8f201d0c
@ -23,9 +23,9 @@ const ManageEmployee = () => {
|
|||||||
employee,
|
employee,
|
||||||
error,
|
error,
|
||||||
loading: empLoading,
|
loading: empLoading,
|
||||||
} = useEmployeeProfile( employeeId );
|
} = useEmployeeProfile(employeeId);
|
||||||
|
|
||||||
dispatch( changeMaster( "Job Role" ) );
|
dispatch(changeMaster("Job Role"));
|
||||||
|
|
||||||
const [disabledEmail, setDisabledEmail] = useState(false);
|
const [disabledEmail, setDisabledEmail] = useState(false);
|
||||||
const { data: job_role, loading } = useMaster();
|
const { data: job_role, loading } = useMaster();
|
||||||
@ -41,7 +41,8 @@ const ManageEmployee = () => {
|
|||||||
MiddleName: z.string().optional(),
|
MiddleName: z.string().optional(),
|
||||||
LastName: z.string().min(1, { message: "Last Name is required" }),
|
LastName: z.string().min(1, { message: "Last Name is required" }),
|
||||||
Email: z
|
Email: z
|
||||||
.string().max(80,"Email cannot exceed 80 characters")
|
.string()
|
||||||
|
.max(80, "Email cannot exceed 80 characters")
|
||||||
.optional()
|
.optional()
|
||||||
.refine((val) => !val || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val), {
|
.refine((val) => !val || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val), {
|
||||||
message: "Invalid email format",
|
message: "Invalid email format",
|
||||||
@ -96,8 +97,10 @@ const ManageEmployee = () => {
|
|||||||
}),
|
}),
|
||||||
AadharNumber: z
|
AadharNumber: z
|
||||||
.string()
|
.string()
|
||||||
.regex(/^\d{12}$/, "Aadhar card must be exactly 12 digits long")
|
.optional()
|
||||||
.nonempty("Aadhar card is required"),
|
.refine((val) => !val || /^\d{12}$/.test(val), {
|
||||||
|
message: "Aadhar card must be exactly 12 digits long",
|
||||||
|
}),
|
||||||
Gender: z
|
Gender: z
|
||||||
.string()
|
.string()
|
||||||
.min(1, { message: "Gender is required" })
|
.min(1, { message: "Gender is required" })
|
||||||
@ -152,8 +155,7 @@ const ManageEmployee = () => {
|
|||||||
mode: "onChange",
|
mode: "onChange",
|
||||||
});
|
});
|
||||||
|
|
||||||
const AadharNumberValue = watch( "AadharNumber" ) || "";
|
const AadharNumberValue = watch("AadharNumber") || "";
|
||||||
|
|
||||||
|
|
||||||
const onSubmit = (data) => {
|
const onSubmit = (data) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@ -184,11 +186,11 @@ const ManageEmployee = () => {
|
|||||||
.then((response) => {
|
.then((response) => {
|
||||||
showToast("Employee details updated successfully.", "success");
|
showToast("Employee details updated successfully.", "success");
|
||||||
clearCacheKey("employeeListByProject");
|
clearCacheKey("employeeListByProject");
|
||||||
clearCacheKey( "allEmployeeList" );
|
clearCacheKey("allEmployeeList");
|
||||||
clearCacheKey("employeeProfile")
|
clearCacheKey("employeeProfile");
|
||||||
|
|
||||||
setLoading( false );
|
setLoading(false);
|
||||||
reset()
|
reset();
|
||||||
navigation("/employees");
|
navigation("/employees");
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
@ -257,7 +259,7 @@ const ManageEmployee = () => {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="card-body">
|
<div className="card-body">
|
||||||
{(!currentEmployee && empLoading && employeeId ) && (
|
{!currentEmployee && empLoading && employeeId && (
|
||||||
<p>Loading Employee Data...</p>
|
<p>Loading Employee Data...</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@ -445,7 +447,7 @@ const ManageEmployee = () => {
|
|||||||
placeholder="Current Address"
|
placeholder="Current Address"
|
||||||
aria-label="Current Address"
|
aria-label="Current Address"
|
||||||
aria-describedby="basic-icon-default-message2"
|
aria-describedby="basic-icon-default-message2"
|
||||||
{...register( "CurrentAddress" )}
|
{...register("CurrentAddress")}
|
||||||
maxLength={500}
|
maxLength={500}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setCurrentAddressLength(e.target.value.length);
|
setCurrentAddressLength(e.target.value.length);
|
||||||
@ -454,7 +456,10 @@ const ManageEmployee = () => {
|
|||||||
}}
|
}}
|
||||||
></textarea>
|
></textarea>
|
||||||
<div className="text-end muted">
|
<div className="text-end muted">
|
||||||
<small> {500 - currentAddressLength} characters left</small>
|
<small>
|
||||||
|
{" "}
|
||||||
|
{500 - currentAddressLength} characters left
|
||||||
|
</small>
|
||||||
</div>
|
</div>
|
||||||
{errors.CurrentAddress && (
|
{errors.CurrentAddress && (
|
||||||
<div
|
<div
|
||||||
@ -476,7 +481,7 @@ const ManageEmployee = () => {
|
|||||||
placeholder="Permanent Address"
|
placeholder="Permanent Address"
|
||||||
aria-label="Permanent Address"
|
aria-label="Permanent Address"
|
||||||
aria-describedby="basic-icon-default-message2"
|
aria-describedby="basic-icon-default-message2"
|
||||||
{...register( "PermanentAddress" )}
|
{...register("PermanentAddress")}
|
||||||
maxLength={500}
|
maxLength={500}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setPermanentAddressLength(e.target.value.length);
|
setPermanentAddressLength(e.target.value.length);
|
||||||
@ -484,7 +489,9 @@ const ManageEmployee = () => {
|
|||||||
}}
|
}}
|
||||||
></textarea>
|
></textarea>
|
||||||
<div className="text-end muted">
|
<div className="text-end muted">
|
||||||
<small>{500 - permanentAddressLength} characters left</small>
|
<small>
|
||||||
|
{500 - permanentAddressLength} characters left
|
||||||
|
</small>
|
||||||
</div>
|
</div>
|
||||||
{errors.PermanentAddress && (
|
{errors.PermanentAddress && (
|
||||||
<div
|
<div
|
||||||
|
@ -2,9 +2,7 @@ import React, { useState, useEffect } from "react";
|
|||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { useDispatch } from "react-redux";
|
import {useActivitiesMaster} from "../../../hooks/masterHook/useMaster";
|
||||||
import { changeMaster } from "../../../slices/localVariablesSlice";
|
|
||||||
import useMaster from "../../../hooks/masterHook/useMaster";
|
|
||||||
|
|
||||||
const taskSchema = z.object({
|
const taskSchema = z.object({
|
||||||
buildingID: z.string().min(1, "Building is required"),
|
buildingID: z.string().min(1, "Building is required"),
|
||||||
@ -17,9 +15,9 @@ const taskSchema = z.object({
|
|||||||
|
|
||||||
const defaultModel = {
|
const defaultModel = {
|
||||||
id: null,
|
id: null,
|
||||||
buildingID: null,
|
buildingID:"0",
|
||||||
floorId: null,
|
floorId: "0",
|
||||||
workAreaId: null,
|
workAreaId: "0",
|
||||||
activityID: null,
|
activityID: null,
|
||||||
plannedWork: 0,
|
plannedWork: 0,
|
||||||
completedWork: 0,
|
completedWork: 0,
|
||||||
@ -32,8 +30,7 @@ const TaskModel = ({
|
|||||||
onClearComplete,
|
onClearComplete,
|
||||||
onClose,
|
onClose,
|
||||||
}) => {
|
}) => {
|
||||||
const dispatch = useDispatch();
|
|
||||||
const { data: activities } = useMaster();
|
|
||||||
const [formData, setFormData] = useState(defaultModel);
|
const [formData, setFormData] = useState(defaultModel);
|
||||||
const [selectedBuilding, setSelectedBuilding] = useState(null);
|
const [selectedBuilding, setSelectedBuilding] = useState(null);
|
||||||
const [selectedFloor, setSelectedFloor] = useState(null);
|
const [selectedFloor, setSelectedFloor] = useState(null);
|
||||||
@ -41,6 +38,7 @@ const TaskModel = ({
|
|||||||
const [selectedActivity, setSelectedActivity] = useState(null);
|
const [selectedActivity, setSelectedActivity] = useState(null);
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||||
const [activityData, setActivityData] = useState([]);
|
const [activityData, setActivityData] = useState([]);
|
||||||
|
const {activities, loading, error} = useActivitiesMaster();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
@ -54,7 +52,6 @@ const TaskModel = ({
|
|||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(changeMaster("Activity"));
|
|
||||||
resetForm();
|
resetForm();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@ -117,18 +114,19 @@ const TaskModel = ({
|
|||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
setFormData(defaultModel);
|
setFormData(defaultModel);
|
||||||
setSelectedBuilding(null);
|
setSelectedBuilding("0");
|
||||||
setSelectedFloor(null);
|
setSelectedFloor("0");
|
||||||
setSelectedWorkArea(null);
|
setSelectedWorkArea("0");
|
||||||
setSelectedActivity(null);
|
setSelectedActivity(null);
|
||||||
reset(defaultModel);
|
reset(defaultModel);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (activities && activities.length > 0) {
|
if (!loading && Array.isArray(activities) && activities.length > 0) {
|
||||||
setActivityData( activities );
|
|
||||||
|
setActivityData(activities);
|
||||||
}
|
}
|
||||||
}, [activities]);
|
}, [activities, loading]);
|
||||||
return (
|
return (
|
||||||
<div className="modal-dialog modal-lg modal-simple modal-edit-user">
|
<div className="modal-dialog modal-lg modal-simple modal-edit-user">
|
||||||
<div className="modal-content">
|
<div className="modal-content">
|
||||||
@ -274,7 +272,7 @@ const TaskModel = ({
|
|||||||
</option>
|
</option>
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<option disabled>No activities available</option> // Fallback if activities are empty
|
<option disabled>No activities available</option>
|
||||||
)}
|
)}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
@ -284,7 +282,6 @@ const TaskModel = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Planned Work */}
|
|
||||||
{selectedActivity && (
|
{selectedActivity && (
|
||||||
<div className="col-5 col-md-5">
|
<div className="col-5 col-md-5">
|
||||||
<label className="form-label" htmlFor="plannedWork">
|
<label className="form-label" htmlFor="plannedWork">
|
||||||
@ -302,7 +299,6 @@ const TaskModel = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Completed Work */}
|
|
||||||
{selectedActivity && (
|
{selectedActivity && (
|
||||||
<div className="col-5 col-md-5">
|
<div className="col-5 col-md-5">
|
||||||
<label className="form-label" htmlFor="completedWork">
|
<label className="form-label" htmlFor="completedWork">
|
||||||
|
@ -16,7 +16,7 @@ export const useMasterRole = () =>
|
|||||||
useMasterData("masterRole", MasterRespository.getRoles);
|
useMasterData("masterRole", MasterRespository.getRoles);
|
||||||
|
|
||||||
|
|
||||||
const useMaster = () => {
|
const useMaster = (isMa) => {
|
||||||
|
|
||||||
const selectedMaster = useSelector((store)=>store.localVariables.selectedMaster);
|
const selectedMaster = useSelector((store)=>store.localVariables.selectedMaster);
|
||||||
const [data, setData] = useState([]);
|
const [data, setData] = useState([]);
|
||||||
@ -79,8 +79,37 @@ const useMaster = () => {
|
|||||||
return { data, loading, error }
|
return { data, loading, error }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export default useMaster;
|
export default useMaster;
|
||||||
|
|
||||||
|
export const useActivitiesMaster = () =>
|
||||||
|
{
|
||||||
|
const [ activities, setActivites ] = useState( [] )
|
||||||
|
const [ loading, setloading ] = useState( false );
|
||||||
|
const [ error, setError ] = useState( "" )
|
||||||
|
|
||||||
|
const fetchActivities =async () => {
|
||||||
|
const cacheddata = getCachedData("ActivityMaster");
|
||||||
|
|
||||||
|
if (!cacheddata) {
|
||||||
|
setloading(true);
|
||||||
|
try {
|
||||||
|
const response = await MasterRespository.getActivites();
|
||||||
|
setActivites(response.data);
|
||||||
|
cacheData("ActivityMaster", response.data);
|
||||||
|
} catch (err) {
|
||||||
|
setError(err);
|
||||||
|
console.log(err);
|
||||||
|
} finally {
|
||||||
|
setloading(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setActivites(cacheddata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
useEffect( () =>
|
||||||
|
{
|
||||||
|
fetchActivities()
|
||||||
|
}, [] )
|
||||||
|
|
||||||
|
return {activities,loading,error}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user