Merge pull request 'pramod_Task#207 Sync activity updates and deletions in Daily Task Planning view without page refresh' (#96) from pramod_Task#207 into Issue_May_2W
Reviewed-on: #96
This commit is contained in:
commit
49f725b62d
@ -2,27 +2,12 @@ import React, { useEffect, useState } from "react";
|
||||
import { useEmployeeAttendacesLog } from "../../hooks/useAttendance";
|
||||
import { convertShortTime } from "../../utils/dateUtils";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import {THRESH_HOLD} from "../../utils/constants";
|
||||
|
||||
const AttendLogs = ({ Id }) => {
|
||||
const { logs, loading } = useEmployeeAttendacesLog(Id);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const isCheckoutRegularized = (
|
||||
activityTimeStr,
|
||||
checkoutTimeStr,
|
||||
threshHours
|
||||
)=> {
|
||||
if (!activityTimeStr || !checkoutTimeStr) return false;
|
||||
|
||||
const activityTime = new Date(activityTimeStr);
|
||||
const checkoutTime = new Date(checkoutTimeStr);
|
||||
const threshTimeMs = threshHours * 60 * 60 * 1000;
|
||||
|
||||
return checkoutTime - activityTime > threshTimeMs;
|
||||
}
|
||||
|
||||
const whichActivityPerform = (actvity,checkOutTime) => {
|
||||
const whichActivityPerform = (actvity) => {
|
||||
switch (actvity) {
|
||||
case 1:
|
||||
return (
|
||||
@ -39,12 +24,12 @@ const AttendLogs = ({ Id }) => {
|
||||
case 2:
|
||||
return (
|
||||
<i
|
||||
className="bx bx-help-circle text-danger"
|
||||
className="bx bx-help-circle text-secondary"
|
||||
data-bs-toggle="tooltip"
|
||||
data-bs-offset="0,8"
|
||||
data-bs-placement="top"
|
||||
data-bs-custom-class="tooltip"
|
||||
title="Regularize Requested"
|
||||
title="regularize Requested"
|
||||
></i>
|
||||
);
|
||||
break;
|
||||
@ -56,43 +41,27 @@ const AttendLogs = ({ Id }) => {
|
||||
data-bs-offset="0,8"
|
||||
data-bs-placement="top"
|
||||
data-bs-custom-class="tooltip"
|
||||
title="Request Deleted!"
|
||||
title="Regularized"
|
||||
></i>
|
||||
);
|
||||
break;
|
||||
case 4:
|
||||
if (
|
||||
checkOutTime &&
|
||||
isCheckoutRegularized(logs[0]?.activityTime, checkOutTime, THRESH_HOLD)
|
||||
) {
|
||||
return (
|
||||
<i
|
||||
className="bx bx-check-circle text-success"
|
||||
data-bs-toggle="tooltip"
|
||||
data-bs-offset="0,8"
|
||||
data-bs-placement="top"
|
||||
data-bs-custom-class="tooltip"
|
||||
title="Regularized"
|
||||
></i>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<i
|
||||
className="bx bx-left-arrow-circle text-danger"
|
||||
data-bs-toggle="tooltip"
|
||||
data-bs-offset="0,8"
|
||||
data-bs-placement="top"
|
||||
data-bs-custom-class="tooltip"
|
||||
title="Check-Out"
|
||||
></i>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<i
|
||||
className="bx bx-left-arrow-circle text-danger "
|
||||
data-bs-toggle="tooltip"
|
||||
data-bs-offset="0,8"
|
||||
data-bs-placement="top"
|
||||
data-bs-custom-class="tooltip"
|
||||
title="Check-Out"
|
||||
></i>
|
||||
);
|
||||
|
||||
break;
|
||||
case 5:
|
||||
return (
|
||||
<i
|
||||
className="bx bx-x-circle text-danger"
|
||||
className="bx bx-x-circle text-danger"
|
||||
data-bs-toggle="tooltip"
|
||||
data-bs-offset="0,8"
|
||||
data-bs-placement="top"
|
||||
@ -110,7 +79,6 @@ const AttendLogs = ({ Id }) => {
|
||||
const url = `https://www.google.com/maps?q=${lat},${lng}`;
|
||||
window.open(url, "_blank"); // Open in new tab
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const tooltipTriggerList = Array.from(
|
||||
document.querySelectorAll('[data-bs-toggle="tooltip"]')
|
||||
@ -154,11 +122,11 @@ const AttendLogs = ({ Id }) => {
|
||||
<tr key={index}>
|
||||
<td>{log.activityTime.slice(0, 10)}</td>
|
||||
<td>{convertShortTime(log.activityTime)}</td>
|
||||
<td>{whichActivityPerform(log.activity,log.activityTime)}</td>
|
||||
<td>{whichActivityPerform(log.activity)}</td>
|
||||
<td>
|
||||
{log?.latitude != 0 ? (
|
||||
<i
|
||||
className="bx bx-map text-danger cursor-pointer"
|
||||
className="bx bx-location-plus text-danger cursor-pointer"
|
||||
data-bs-toggle="tooltip"
|
||||
data-bs-offset="0,8"
|
||||
data-bs-placement="top"
|
||||
|
@ -13,7 +13,7 @@ import {useHasUserPermission} from "../../hooks/useHasUserPermission";
|
||||
import {MANAGE_PROJECT_INFRA} from "../../utils/constants";
|
||||
import {useDispatch, useSelector} from "react-redux";
|
||||
import {useProfile} from "../../hooks/useProfile";
|
||||
import {setProjectId} from "../../slices/localVariablesSlice";
|
||||
import {refreshData, setProjectId} from "../../slices/localVariablesSlice";
|
||||
import InfraTable from "../Project/Infrastructure/InfraTable";
|
||||
|
||||
|
||||
@ -25,11 +25,23 @@ const InfraPlanning = () =>
|
||||
|
||||
const selectedProject = useSelector((store)=>store.localVariables.projectId)
|
||||
const ManageInfra = useHasUserPermission( MANAGE_PROJECT_INFRA )
|
||||
const {projects_Details, loading: project_deatilsLoader, error: project_error} = useProjectDetails(selectedProject)
|
||||
const {projects_Details, loading: project_deatilsLoader, error: project_error,refetch} = useProjectDetails( selectedProject )
|
||||
const reloadedData = useSelector( ( store ) => store.localVariables.reload )
|
||||
|
||||
useEffect( () =>
|
||||
{
|
||||
dispatch(setProjectId(projects[0]?.id))
|
||||
},[projects])
|
||||
}, [ projects ] )
|
||||
|
||||
useEffect( () =>
|
||||
{
|
||||
if (reloadedData)
|
||||
{
|
||||
refetch()
|
||||
dispatch( refreshData( false ) )
|
||||
}
|
||||
|
||||
},[reloadedData])
|
||||
|
||||
return (
|
||||
<div className="col-md-12 col-lg-12 col-xl-12 order-0 mb-4">
|
||||
|
@ -71,12 +71,14 @@ const EditActivityModal = ({
|
||||
|
||||
const handleActivityChange = (e) => {
|
||||
const selectedId = Number(e.target.value);
|
||||
const selected = activityData.find((a) => a.id === selectedId);
|
||||
const selected = activityData.find( ( a ) => a.id === selectedId );
|
||||
setSelectedActivity(selected || null);
|
||||
setValue("activityID", selectedId);
|
||||
};
|
||||
|
||||
const onSubmitForm = async (data) => {
|
||||
const onSubmitForm = async ( data ) =>
|
||||
{
|
||||
setIsSubmitting(true)
|
||||
const updatedProject = { ...projects_Details };
|
||||
const finalData = {
|
||||
...data,
|
||||
@ -142,13 +144,17 @@ const EditActivityModal = ({
|
||||
});
|
||||
resetForm();
|
||||
dispatch( refreshData( true ) );
|
||||
setIsSubmitting(false)
|
||||
showToast("Activity Updated Successfully","success")
|
||||
|
||||
onClose();
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
showToast(error.message, "error");
|
||||
.catch( ( error ) =>
|
||||
{
|
||||
setIsSubmitting(false)
|
||||
const message = error.response.data.message || error.message || "Error Occured During Api Call"
|
||||
showToast( message, "error" );
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
@ -327,7 +333,7 @@ const EditActivityModal = ({
|
||||
{/* )} */}
|
||||
|
||||
<div className="col-12 text-center">
|
||||
<button type="submit" className="btn btn-sm btn-primary me-3" disabled={activities.length === 0}>
|
||||
<button type="submit" className="btn btn-sm btn-primary me-3" disabled={activities.length === 0 || isSubmitting}>
|
||||
{isSubmitting ? "Please Wait.." : "Edit Task"}
|
||||
</button>
|
||||
<button
|
||||
|
Loading…
x
Reference in New Issue
Block a user