Merge branch 'Issues_April_4W' of https://git.marcoaiot.com/admin/marco.pms.web into pramod_Feature#51ProjectLisFilter
This commit is contained in:
commit
3e71511d8e
@ -34,18 +34,24 @@ const AssignRoleModel = ({ assignData, onClose }) => {
|
||||
const [selectedRole, setSelectedRole] = useState("all");
|
||||
const [selectedEmployees, setSelectedEmployees] = useState([]);
|
||||
|
||||
|
||||
const { handleSubmit, control, setValue, watch, formState: { errors },reset } = useForm({
|
||||
const {
|
||||
handleSubmit,
|
||||
control,
|
||||
setValue,
|
||||
watch,
|
||||
formState: { errors },
|
||||
reset,
|
||||
} = useForm({
|
||||
defaultValues: {
|
||||
selectedEmployees: [],
|
||||
description:""
|
||||
description: "",
|
||||
},
|
||||
resolver: (data) => {
|
||||
const validation = schema.safeParse(data);
|
||||
if (validation.success) return { values: data, errors: {} };
|
||||
return { values: {}, errors: validation.error.formErrors.fieldErrors };
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const handleRoleChange = (event) => {
|
||||
setSelectedRole(event.plannedTask.value);
|
||||
@ -78,62 +84,51 @@ const { handleSubmit, control, setValue, watch, formState: { errors },reset } =
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const onSubmit = async(data) => {
|
||||
const onSubmit = async (data) => {
|
||||
const formattedData = {
|
||||
taskTeam: data.selectedEmployees,
|
||||
plannedTask: parseInt( plannedTask, 10 ),
|
||||
plannedTask: parseInt(plannedTask, 10),
|
||||
description: data.description,
|
||||
assignmentDate: new Date().toISOString(),
|
||||
workItemId:assignData?.workItem?.workItem.id
|
||||
workItemId: assignData?.workItem?.workItem.id,
|
||||
};
|
||||
try
|
||||
{
|
||||
let response = await TasksRepository.assignTask( formattedData );
|
||||
showToast( "Task Successfully Assigend", "success" )
|
||||
reset()
|
||||
onClose()
|
||||
} catch ( error )
|
||||
{
|
||||
showToast("something wrong","error")
|
||||
try {
|
||||
let response = await TasksRepository.assignTask(formattedData);
|
||||
showToast( "Task Successfully Assigend", "success" );
|
||||
setSelectedEmployees([])
|
||||
reset();
|
||||
closeModal()
|
||||
|
||||
} catch (error) {
|
||||
showToast("something wrong", "error");
|
||||
}
|
||||
|
||||
};
|
||||
useEffect(()=>{
|
||||
dispatch(changeMaster("Job Role"))
|
||||
return ()=> setSelectedRole("all")
|
||||
},[dispatch])
|
||||
|
||||
};
|
||||
useEffect(() => {
|
||||
dispatch(changeMaster("Job Role"));
|
||||
return () => setSelectedRole("all");
|
||||
}, [dispatch]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="container my-1">
|
||||
<div className="mb-2">
|
||||
<div className="bs-stepper wizard-numbered d-flex justify-content-center align-items-center flex-wrap">
|
||||
<div className="mb-">
|
||||
<p className="fs-sm-5 fs-6 text-dark text-start d-flex align-items-center flex-wrap">
|
||||
{[
|
||||
assignData?.building?.name,
|
||||
assignData?.floor?.floorName,
|
||||
assignData?.workArea?.areaName,
|
||||
assignData?.workItem?.workItem?.activityMaster?.activityName,
|
||||
].map((item, index, array) => (
|
||||
<div
|
||||
key={index}
|
||||
className="col d-flex justify-content-center align-items-center"
|
||||
>
|
||||
<div className="bs-stepper-header p-1 text-center">
|
||||
<span className="fs-5">{item}</span>
|
||||
|
||||
{/* Arrow between items */}
|
||||
]
|
||||
.filter(Boolean)
|
||||
.map((item, index, array) => (
|
||||
<span key={index} className="d-flex align-items-center">
|
||||
{item}
|
||||
{index < array.length - 1 && (
|
||||
<div className="line">
|
||||
<i className="icon-base bx bx-chevron-right scaleX-n1-rtl"></i>
|
||||
</div>
|
||||
<i className="bx bx-chevron-right mx-2"></i>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</p>
|
||||
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="row mb-1">
|
||||
@ -166,6 +161,9 @@ useEffect(()=>{
|
||||
<div className="divider text-start">
|
||||
<div className="divider-text">Employee</div>
|
||||
</div>
|
||||
|
||||
<div className="row">
|
||||
<div className="col-12 col-md-8 h-sm-25 overflow-auto">
|
||||
{selectedRole !== "" && (
|
||||
<div className="row mb-2">
|
||||
<div className="col-sm-12">
|
||||
@ -178,7 +176,7 @@ useEffect(()=>{
|
||||
return (
|
||||
<div
|
||||
key={emp.id}
|
||||
className="col-6 col-sm-4 col-md-4 col-lg-3 mb-1"
|
||||
className="col-6 col-sm-6 col-md-4 col-lg-4 mb-1"
|
||||
>
|
||||
<div className="form-check text-start p-0">
|
||||
<div className="li-wrapper d-flex justify-content-start align-items-start">
|
||||
@ -200,10 +198,19 @@ useEffect(()=>{
|
||||
)}
|
||||
/>
|
||||
<div className="list-content">
|
||||
<h6 className="mb-0">
|
||||
<p
|
||||
className=" mb-0"
|
||||
style={{
|
||||
fontSize: "12px",
|
||||
fontWeight: "bolder",
|
||||
}}
|
||||
>
|
||||
{emp.firstName} {emp.lastName}
|
||||
</h6>
|
||||
<small className="text-muted">
|
||||
</p>
|
||||
<small
|
||||
className="lead"
|
||||
style={{ fontSize: "10px" }}
|
||||
>
|
||||
{loading && (
|
||||
<p
|
||||
className="skeleton para"
|
||||
@ -224,6 +231,8 @@ useEffect(()=>{
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="col-12 col-md-4 h-25 overflow-auto" style={{maxHeight:"200px"}}>
|
||||
|
||||
{selectedEmployees.length > 0 && (
|
||||
<div className="mt-1">
|
||||
@ -233,7 +242,7 @@ useEffect(()=>{
|
||||
return (
|
||||
<span
|
||||
key={empId}
|
||||
className="badge bg-label-primary d-inline-flex align-items-center gap-2 me-1 p-2 mb-2"
|
||||
className="badge bg-label-primary d-inline-flex align-items-center gap-2 me-1 p-1 mb-2"
|
||||
>
|
||||
{emp.firstName} {emp.lastName}
|
||||
<p
|
||||
@ -256,6 +265,10 @@ useEffect(()=>{
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div className="col-md text-start mx-0 px-0">
|
||||
<div className="form-check form-check-inline mt-4 px-1">
|
||||
@ -273,7 +286,7 @@ useEffect(()=>{
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
className="form-control form-control-sm "
|
||||
className="form-control form-control-xs"
|
||||
value={plannedTask}
|
||||
onChange={(e) => setPlannedTask(e.target.value)}
|
||||
id="defaultFormControlInput"
|
||||
@ -298,7 +311,7 @@ useEffect(()=>{
|
||||
{...field}
|
||||
className="form-control"
|
||||
id="exampleFormControlTextarea1"
|
||||
rows="3"
|
||||
rows="2"
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
@ -159,8 +159,14 @@ const WorkItem = ({ workItem, forBuilding, forFloor, forWorkArea }) => {
|
||||
</a>
|
||||
<a className="dropdown-item">
|
||||
{" "}
|
||||
<i className="bx bx-trash me-1 text-danger"></i>Delete
|
||||
<i className="bx bx-trash me-1 text-danger" ></i>Delete
|
||||
</a>
|
||||
{!projectId && ( <a className="dropdown-item" data-bs-toggle="modal"
|
||||
data-bs-target="#project-modal"
|
||||
onClick={openModal}>
|
||||
{" "}
|
||||
<i className="bx bx-task me-1 text-info" ></i>Assign
|
||||
</a> )}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
@ -79,18 +79,18 @@ const ProjectBanner = ( {project_data} ) =>
|
||||
{/* Project Banner */}
|
||||
<div className="col-12">
|
||||
<div className="card mb-6 pb-0">
|
||||
<div className="d-flex align-items-center justify-content-between p-4 flex-wrap">
|
||||
<div className="d-flex align-items-center justify-content-between p-2 flex-wrap">
|
||||
{/* Left: Icon + Name */}
|
||||
<div className="d-flex align-items-center gap-3">
|
||||
<img
|
||||
src="../../assets/icons/civil-engineering.svg"
|
||||
alt="user image"
|
||||
className="rounded-3"
|
||||
style={{ width: "60px", height: "60px" }}
|
||||
style={{ width: "40px", height: "40px" }}
|
||||
/>
|
||||
<h4 className="mb-0">
|
||||
<h5 className="mb-0">
|
||||
{CurrentProject.name ? CurrentProject.name : "N/A"}
|
||||
</h4>
|
||||
</h5>
|
||||
</div>
|
||||
{manageProject && (
|
||||
<button
|
||||
|
@ -45,7 +45,7 @@ const GlobalModel = ({
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`modal fade ${modalType}`}
|
||||
className={`modal fade ${ modalType }`}
|
||||
id="customModal"
|
||||
tabIndex="-1"
|
||||
aria-labelledby="exampleModalLabel"
|
||||
@ -53,9 +53,9 @@ const GlobalModel = ({
|
||||
ref={modalRef} // Assign the ref to the modal element
|
||||
{...dataAttributesProps}
|
||||
>
|
||||
<div className={`modal-dialog ${dialogClass} ${modalSizeClass}`} role={role}>
|
||||
<div className={`modal-dialog ${dialogClass} ${modalSizeClass } mx-sm-auto mx-1`} role={role}>
|
||||
<div className="modal-content">
|
||||
<div className="modal-header">
|
||||
<div className="modal-header p-0">
|
||||
{/* Close button inside the modal header */}
|
||||
<button
|
||||
type="button"
|
||||
@ -65,7 +65,7 @@ const GlobalModel = ({
|
||||
onClick={closeModal} // Trigger the React closeModal function
|
||||
></button>
|
||||
</div>
|
||||
<div className="modal-body">
|
||||
<div className="modal-body p-sm-4 p-0">
|
||||
{children} {/* Render children here, which can be the ReportTask component */}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -7,6 +7,7 @@ import { setProjectId } from "../slices/localVariablesSlice";
|
||||
|
||||
export const useProjects = () =>
|
||||
{
|
||||
const {profile} = useProfile()
|
||||
const dispatch = useDispatch();
|
||||
const [projects, setProjects] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
@ -48,9 +49,19 @@ export const useProjects = () =>
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(setProjectId(projects[0]?.id));
|
||||
}, [projects]);
|
||||
useEffect( () =>
|
||||
{
|
||||
if (projects )
|
||||
{
|
||||
if ( profile?.projects && profile?.projects?.length > 0 )
|
||||
{
|
||||
dispatch(setProjectId(profile?.projects[0]))
|
||||
} else
|
||||
{
|
||||
dispatch(setProjectId(1))
|
||||
}
|
||||
}
|
||||
}, [profile]);
|
||||
|
||||
return { projects, loading, error, refetch: fetchData };
|
||||
};
|
||||
|
@ -19,15 +19,37 @@ const DailyTask = () => {
|
||||
const { profile: LoggedUser } = useProfile();
|
||||
const [searchParams] = useSearchParams();
|
||||
const projectId = searchParams.get("project");
|
||||
|
||||
const selectedProject = useSelector(
|
||||
(store) => store.localVariables.projectId
|
||||
);
|
||||
const {
|
||||
projects,
|
||||
loading: project_lodaing,
|
||||
error: projects_Error,
|
||||
} = useProjects();
|
||||
const selectedProject = useSelector(
|
||||
(store) => store.localVariables.projectId
|
||||
|
||||
|
||||
|
||||
const [initialized, setInitialized] = useState(false);
|
||||
|
||||
// Sync projectId (either from URL or pick first accessible one)
|
||||
useEffect(() => {
|
||||
if (!project_lodaing && projects.length > 0) {
|
||||
const userProjects = projects.filter((p) =>
|
||||
LoggedUser?.projects?.map(Number).includes(p.id)
|
||||
);
|
||||
|
||||
if (projectId) {
|
||||
dispatch(setProjectId(projectId));
|
||||
} else if (!selectedProject && userProjects.length > 0) {
|
||||
dispatch(setProjectId(userProjects[0].id));
|
||||
}
|
||||
|
||||
setInitialized(true);
|
||||
}
|
||||
}, [project_lodaing, projects, projectId, selectedProject]);
|
||||
|
||||
|
||||
const dispatch = useDispatch(selectedProject);
|
||||
const [dateRange, setDateRange] = useState({ startDate: "", endDate: "" });
|
||||
|
||||
@ -60,9 +82,6 @@ const DailyTask = () => {
|
||||
openModal();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (projectId) dispatch(setProjectId(projectId));
|
||||
}, [projectId]);
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
@ -161,6 +180,11 @@ const DailyTask = () => {
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{(!initialized || !selectedProject) && ( <tr>
|
||||
<td colSpan={7} className="text-center">
|
||||
<p>Loading..</p>
|
||||
</td>
|
||||
</tr>)}
|
||||
|
||||
{TaskLists.map((task, index) => {
|
||||
const accordionId = `accordion-${index}`;
|
||||
|
@ -35,13 +35,17 @@ const ForgotPasswordPage = () => {
|
||||
setLoading(true)
|
||||
const response = await AuthRepository.forgotPassword(data)
|
||||
if ( response.data && response.success )
|
||||
showToast( response.message, "success" )
|
||||
showToast( "verification email has been sent to your registered email address", "success" )
|
||||
reset()
|
||||
setLoading( false )
|
||||
} catch ( err )
|
||||
{
|
||||
if(err.response.status === 404){
|
||||
showToast( "verification email has been sent to your registered email address", "success" )
|
||||
}else{
|
||||
showToast("Something wrong","error")
|
||||
}
|
||||
|
||||
showToast( err.message, "error" )
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
@ -44,6 +44,7 @@ const LoginPage = () => {
|
||||
setLoading(false);
|
||||
navigate("/dashboard");
|
||||
} catch (err) {
|
||||
showToast("Invalid username or password.","error")
|
||||
console.log("Unable to proceed. Please try again.");
|
||||
setLoading(false);
|
||||
}
|
||||
|
@ -178,7 +178,9 @@ const EmployeeList = () => {
|
||||
<>
|
||||
<option value="">All Employees</option>
|
||||
{Array.isArray(projects) &&
|
||||
projects.map((item) => (
|
||||
projects
|
||||
.filter((item) => loginUser?.projects?.includes(String(item.id)))
|
||||
.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.name}
|
||||
</option>
|
||||
@ -186,7 +188,7 @@ const EmployeeList = () => {
|
||||
</>
|
||||
)}
|
||||
</select>
|
||||
</label>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -210,6 +210,17 @@ const ProjectList = () => {
|
||||
currentItems.map((item) => (
|
||||
<ProjectCard projectData={item} key={item.id}></ProjectCard>
|
||||
))}
|
||||
=======
|
||||
|
||||
|
||||
{Array.isArray(currentItems) && loginUser?.projects && (
|
||||
currentItems
|
||||
.filter((item) => loginUser.projects.includes(String(item.id)))
|
||||
.map((item) => (
|
||||
<ProjectCard projectData={item} key={item.id} />
|
||||
))
|
||||
)}
|
||||
>>>>>>> 148058d1d22430d0c2a314cdade3509b38c5d090
|
||||
</div>
|
||||
{/* Pagination */}
|
||||
{!loading && (
|
||||
|
@ -11,7 +11,6 @@ export const axiosClient = axios.create({
|
||||
"Content-Type": "application/json", // Specify the content type
|
||||
},
|
||||
});
|
||||
|
||||
axiosRetry(axiosClient, { retries: 3 });
|
||||
|
||||
// Request interceptor to add Bearer token
|
||||
@ -21,6 +20,10 @@ axiosClient.interceptors.request.use(
|
||||
const token = localStorage.getItem("jwtToken");
|
||||
if (token) {
|
||||
config.headers["Authorization"] = `Bearer ${token}`;
|
||||
config._retry = true;
|
||||
}
|
||||
else{
|
||||
config._retry = false;
|
||||
}
|
||||
}
|
||||
return config;
|
||||
@ -32,7 +35,9 @@ axiosClient.interceptors.request.use(
|
||||
// Add an interceptor to handle expired tokens
|
||||
axiosClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
|
||||
async (error) => {
|
||||
|
||||
const originalRequest = error.config;
|
||||
|
||||
if (!originalRequest) {
|
||||
@ -80,13 +85,12 @@ axiosClient.interceptors.response.use(
|
||||
if (error.config.url.indexOf("refresh-token") != -1) {
|
||||
//showToast("Server is unreachable. Try again later!", "error");
|
||||
console.log("4 - error fetching refresh token :", error);
|
||||
} else {
|
||||
showToast(error.response.data.message, "error");
|
||||
}
|
||||
|
||||
// else {
|
||||
// // showToast(error.response.data.message, "error"); // repeted toast
|
||||
// }
|
||||
if (error.response.status === 401 && !originalRequest._retry) {
|
||||
originalRequest._retry = true;
|
||||
|
||||
try {
|
||||
// Get the refresh token from secure storage
|
||||
const refreshToken = localStorage.getItem("refreshToken");
|
||||
@ -129,11 +133,11 @@ axiosClient.interceptors.response.use(
|
||||
//showToast("Server is unreachable. Try again later!", "error");
|
||||
console.log("6 - error fetching refresh token :", error);
|
||||
}
|
||||
showToast(
|
||||
error.response.data?.message ||
|
||||
"An error occurred. Please try again.",
|
||||
"error"
|
||||
);
|
||||
// showToast(
|
||||
// error.response.data?.message ||
|
||||
// "An error occurred. Please try again.",
|
||||
// "error"
|
||||
// );
|
||||
}
|
||||
} else {
|
||||
console.error("An unknown error occurred:", error.message);
|
||||
|
Loading…
x
Reference in New Issue
Block a user