fixed regularization bugs- past employee is not able to regularized beacuse, id not sending to server
This commit is contained in:
parent
9c0f98dbaf
commit
d56ba89a4a
@ -59,10 +59,8 @@ const Attendance = ( {attendance, getRole, handleModalData} ) =>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
{/* <span className="badge bg-label-primary me-1">
|
||||
{getRole(item.roleID)}
|
||||
</span> */}
|
||||
---
|
||||
{item.jobRoleName}
|
||||
|
||||
</td>
|
||||
<td>{item.checkInTime ? convertShortTime(item.checkInTime):"--"}</td>
|
||||
<td>{item.checkOutTime ? convertShortTime(item.checkOutTime):"--"}</td>
|
||||
|
@ -51,6 +51,7 @@ const AttendanceLog = ({ attendance, handleModalData, projectId }) => {
|
||||
<thead>
|
||||
<tr>
|
||||
<th className="border-top-1" colSpan={2}>Name</th>
|
||||
<th className="border-top-1" >Role</th>
|
||||
<th>
|
||||
<i className="bx bxs-down-arrow-alt text-success"></i> Check-In
|
||||
</th>
|
||||
@ -81,6 +82,7 @@ const AttendanceLog = ({ attendance, handleModalData, projectId }) => {
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>{ attendance.jobRoleName}</td>
|
||||
<td>{convertShortTime(attendance.checkInTime)}</td>
|
||||
<td>{attendance.checkOutTime ? convertShortTime(attendance.checkOutTime) : '--'}</td>
|
||||
<td className="text-center">
|
||||
|
@ -35,18 +35,18 @@ const CheckCheckOutmodel = ({modeldata,closeModal,handleSubmitForm,}) => {
|
||||
const onSubmit = ( data ) =>
|
||||
{
|
||||
console.log(data)
|
||||
let record = {...data, date: new Date().toLocaleDateString(),latitude:coords.latitude,longitude:coords.longitude,employeeId:modeldata.employeeId,action:modeldata.action}
|
||||
let record = {...data, date: new Date().toLocaleDateString(),latitude:coords.latitude,longitude:coords.longitude,employeeId:modeldata.employeeId,action:modeldata.action,id:modeldata?.id || null}
|
||||
if(modeldata.forWhichTab === 1){
|
||||
handleSubmitForm(record)
|
||||
} else
|
||||
{
|
||||
console.log("is Date" ,checkIfCurrentDate(modeldata?.currentDate))
|
||||
|
||||
if ( modeldata?.currentDate && checkIfCurrentDate(modeldata?.currentDate) )
|
||||
{
|
||||
handleSubmitForm(record)
|
||||
} else
|
||||
{
|
||||
let formData = {...data, date: new Date().toLocaleDateString(),latitude:coords.latitude,longitude:coords.longitude,employeeId:modeldata.employeeId,projectId:projectId,action:modeldata.action}
|
||||
let formData = {...data, date: new Date().toLocaleDateString(),latitude:coords.latitude,longitude:coords.longitude,employeeId:modeldata.employeeId,projectId:projectId,action:modeldata.action,id:modeldata?.id || null}
|
||||
dispatch(markAttendance(formData))
|
||||
.unwrap()
|
||||
.then(() => {
|
||||
@ -67,8 +67,6 @@ const CheckCheckOutmodel = ({modeldata,closeModal,handleSubmitForm,}) => {
|
||||
<form className="row g-2" onSubmit={handleSubmit(onSubmit)}>
|
||||
|
||||
<div className="col-12 col-md-12">
|
||||
{/* <TimePicker label="Time" onChange={(e) => setValue("time", e)} /> */}
|
||||
|
||||
<TimePicker
|
||||
label="Choose a time"
|
||||
onChange={(e) => setValue("markTime", e)}
|
||||
@ -123,7 +121,7 @@ const schemaReg = z.object({
|
||||
export const Regularization = ({modeldata,closeModal,handleSubmitForm})=>{
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const coords = usePositionTracker();
|
||||
console.log(modeldata)
|
||||
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
@ -138,10 +136,12 @@ export const Regularization = ({modeldata,closeModal,handleSubmitForm})=>{
|
||||
};
|
||||
|
||||
|
||||
const onSubmit = (data) => {
|
||||
let record = {...data, date: new Date().toLocaleDateString(),latitude:coords.latitude,longitude:coords.longitude}
|
||||
const onSubmit = ( data ) =>
|
||||
{
|
||||
|
||||
|
||||
let record = {...data, date: new Date().toLocaleDateString(),latitude:coords.latitude,longitude:coords.longitude, }
|
||||
|
||||
console.log(record)
|
||||
handleSubmitForm(record)
|
||||
closeModal()
|
||||
};
|
||||
|
@ -2,17 +2,23 @@ import React, { useEffect, useState } from 'react';
|
||||
import Avatar from '../common/Avatar';
|
||||
import { convertShortTime } from '../../utils/dateUtils';
|
||||
import RegularizationActions from './RegularizationActions';
|
||||
import {useSelector} from 'react-redux';
|
||||
import {useRegularizationRequests} from '../../hooks/useAttendance';
|
||||
import moment from 'moment';
|
||||
|
||||
|
||||
const Regularization = ({attendance,handleRequest}) => {
|
||||
const[attendances,setAttendances] = useState(attendance)
|
||||
const regularize_Requests = attendances.filter((att)=>att.activity === 2)
|
||||
const Regularization = ( { handleRequest} ) =>
|
||||
{
|
||||
var selectedProject = useSelector((store) => store.localVariables.projectId);
|
||||
const [ regularizesList, setregularizedList ] = useState( [] )
|
||||
const { regularizes, loading,error} = useRegularizationRequests(selectedProject)
|
||||
|
||||
|
||||
|
||||
useEffect(()=>{
|
||||
setAttendances(attendance)
|
||||
},[attendance])
|
||||
|
||||
setregularizedList(regularizes)
|
||||
},[regularizes])
|
||||
|
||||
return (
|
||||
<div className="table-responsive text-nowrap">
|
||||
<table className="table mb-0">
|
||||
@ -25,10 +31,12 @@ const Regularization = ({attendance,handleRequest}) => {
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody>
|
||||
|
||||
{loading &&<td colSpan={5}>Loading...</td>}
|
||||
{
|
||||
regularize_Requests.length > 0 ? (
|
||||
regularize_Requests?.map((att, index) => (
|
||||
regularizes?.length > 0 ? (
|
||||
regularizes?.map((att, index) => (
|
||||
<tr key={index}>
|
||||
<td colSpan={2}>
|
||||
<div className="d-flex justify-content-start align-items-center">
|
||||
@ -48,7 +56,7 @@ const Regularization = ({attendance,handleRequest}) => {
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>{att.date}</td>
|
||||
<td>{moment(att.checkOutTime).format("DD-MMM-YYYY")}</td>
|
||||
<td>{convertShortTime(att.checkInTime)}</td>
|
||||
<td>{att.checkOutTime ? convertShortTime(att.checkOutTime):"--"}</td>
|
||||
<td className='text-center ' >
|
||||
|
@ -1,8 +1,10 @@
|
||||
import React, { act, useEffect, useState } from 'react'
|
||||
import useAttendanceStatus, { ACTIONS } from '../../hooks/useAttendanceStatus';
|
||||
// import AttendanceRepository from '../../repositories/AttendanceRepository';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { usePositionTracker } from '../../hooks/usePositionTracker';
|
||||
import {markCurrentAttendance} from '../../slices/apiSlice/attendanceAllSlice';
|
||||
import {cacheData, getCachedData} from '../../slices/apiDataManager';
|
||||
|
||||
|
||||
const RegularizationActions = ({attendanceData,handleRequest}) => {
|
||||
@ -12,10 +14,10 @@ const [loadingReject,setLoadingForReject] = useState(false)
|
||||
|
||||
const projectId = useSelector((store)=>store.localVariables.projectId)
|
||||
const {latitude,longitude} = usePositionTracker();
|
||||
|
||||
const dispatch = useDispatch()
|
||||
|
||||
const handleRegularization =(request_attendance,IsReqularize)=>{
|
||||
|
||||
debugger
|
||||
if(IsReqularize){
|
||||
setLoadingForApprove(true)
|
||||
}else{
|
||||
@ -34,8 +36,18 @@ const {latitude,longitude} = usePositionTracker();
|
||||
action:IsReqularize ? 4 : 5,
|
||||
image:null
|
||||
}
|
||||
console.log(req_Data)
|
||||
handleRequest(req_Data)
|
||||
|
||||
dispatch( markCurrentAttendance( req_Data ) ).then( ( action ) =>
|
||||
{
|
||||
|
||||
const regularizedList = getCachedData("regularizedList")
|
||||
|
||||
const updatedata = regularizedList?.data?.filter( item => item.id !== action.payload.id );
|
||||
|
||||
cacheData("regularizedList",{data:updatedata,projectId:projectId})
|
||||
setLoadingForApprove( false )
|
||||
setLoadingForReject(false)
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ const RenderAttendanceStatus = ({ attendanceData, handleModalData,Tab,currentDat
|
||||
const handleButtonClick = (key) => {
|
||||
|
||||
if(key === 6){
|
||||
handleModalData({action:6,id :attendanceData?.id})
|
||||
handleModalData({action:6,id:attendanceData?.id})
|
||||
}else{
|
||||
|
||||
handleModalData({
|
||||
@ -22,6 +22,7 @@ const RenderAttendanceStatus = ({ attendanceData, handleModalData,Tab,currentDat
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<div className="d-flex justify-content-center">
|
||||
<button
|
||||
|
@ -37,8 +37,8 @@ const WorkItem = ({ workItem, forBuilding, forFloor, forWorkArea }) => {
|
||||
workArea: forWorkArea,
|
||||
workItem,
|
||||
};
|
||||
console.log(assigndata)
|
||||
const hasWorkItem = NewWorkItem && NewWorkItem
|
||||
|
||||
|
||||
|
||||
const hasWorkItem = NewWorkItem && NewWorkItem;
|
||||
|
||||
|
@ -71,4 +71,41 @@ export const useEmployeeAttendacesLog = (id) => {
|
||||
}, [id]);
|
||||
|
||||
return { logs, loading, error };
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
export const useRegularizationRequests = ( projectId ) =>
|
||||
{
|
||||
const [regularizes, setregularizes] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
|
||||
const fetchData = () => {
|
||||
const regularizedList_cache = getCachedData("regularizedList");
|
||||
if(!regularizedList_cache || regularizedList_cache.projectId !== projectId ){
|
||||
setLoading(true)
|
||||
AttendanceRepository.getRegularizeList(projectId).then((response)=>{
|
||||
setregularizes( response.data )
|
||||
console.log(response.data)
|
||||
cacheData("regularizedList", { data: response.data, projectId })
|
||||
setLoading(false)
|
||||
}).catch((error)=>{
|
||||
setError("Failed to fetch data.");
|
||||
setLoading(false);
|
||||
})
|
||||
}else{
|
||||
|
||||
setregularizes(regularizedList_cache.data);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (projectId) {
|
||||
fetchData();
|
||||
}
|
||||
|
||||
}, [ projectId ] );
|
||||
return {regularizes,loading,error}
|
||||
}
|
@ -23,31 +23,20 @@ const AttendancePage = () => {
|
||||
const loginUser = getCachedProfileData();
|
||||
var selectedProject = useSelector((store) => store.localVariables.projectId);
|
||||
const { projects, loading: projectLoading } = useProjects();
|
||||
const { attendance, loading: attLoading } = useAttendace(selectedProject);
|
||||
const [attendances, setAttendances] = useState();
|
||||
const {attendance, loading: attLoading} = useAttendace( selectedProject );
|
||||
const [ attendances, setAttendances ] = useState();
|
||||
|
||||
const [empRoles, setEmpRoles] = useState(null);
|
||||
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
|
||||
<<<<<<< Updated upstream
|
||||
const [modelConfig, setModelConfig] = useState();
|
||||
const DoRegularized = useHasUserPermission(REGULARIZE_ATTENDANCE);
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
time: "",
|
||||
markTime: "",
|
||||
description: "",
|
||||
date: new Date().toLocaleDateString(),
|
||||
});
|
||||
=======
|
||||
const [ modelConfig, setModelConfig ] = useState();
|
||||
const DoRegularized = useHasUserPermission(REGULARIZE_ATTENDANCE)
|
||||
const dispatch = useDispatch()
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
markTime: "",
|
||||
description: "",
|
||||
date: new Date().toLocaleDateString(),
|
||||
});
|
||||
>>>>>>> Stashed changes
|
||||
|
||||
const getRole = (roleId) => {
|
||||
if (!empRoles) return "Unassigned";
|
||||
@ -60,7 +49,9 @@ const AttendancePage = () => {
|
||||
setIsCreateModalOpen(true);
|
||||
};
|
||||
|
||||
const handleModalData = (employee) => {
|
||||
const handleModalData = ( employee ) =>
|
||||
{
|
||||
|
||||
setModelConfig(employee);
|
||||
};
|
||||
|
||||
@ -69,43 +60,15 @@ const AttendancePage = () => {
|
||||
setIsCreateModalOpen(false);
|
||||
const modalElement = document.getElementById("check-Out-modal");
|
||||
if (modalElement) {
|
||||
<<<<<<< Updated upstream
|
||||
modalElement.classList.remove("show");
|
||||
modalElement.style.display = "none";
|
||||
document.body.classList.remove("modal-open");
|
||||
document.querySelector(".modal-backdrop").remove();
|
||||
}
|
||||
=======
|
||||
modalElement.classList.remove('show');
|
||||
modalElement.style.display = 'none';
|
||||
document.body.classList.remove('modal-open');
|
||||
document.querySelector('.modal-backdrop').remove();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const handleSubmit = ( formData ) =>
|
||||
{
|
||||
debugger
|
||||
dispatch( markCurrentAttendance( formData ) ).then( ( action ) =>
|
||||
{
|
||||
const updatedAttendance = attendances.map(item =>
|
||||
item.employeeId === action.payload.employeeId
|
||||
? { ...item, ...action.payload }
|
||||
: item
|
||||
);
|
||||
cacheData("Attendance", { data: updatedAttendance, projectId: selectedProject })
|
||||
setAttendances(updatedAttendance)
|
||||
showToast("Attedance Marked Successfully","success")
|
||||
})
|
||||
.catch( ( error ) =>
|
||||
{
|
||||
showToast(error.message,"error")
|
||||
});
|
||||
>>>>>>> Stashed changes
|
||||
};
|
||||
|
||||
const handleSubmit = (formData) => {
|
||||
const handleSubmit = ( formData ) =>
|
||||
{
|
||||
dispatch(markCurrentAttendance(formData))
|
||||
.then((action) => {
|
||||
const updatedAttendance = attendances.map((item) =>
|
||||
@ -131,7 +94,7 @@ const AttendancePage = () => {
|
||||
}
|
||||
}, [modelConfig, isCreateModalOpen]);
|
||||
useEffect(() => {
|
||||
setAttendances(attendance);
|
||||
setAttendances( attendance );
|
||||
}, [attendance]);
|
||||
useEffect(() => {
|
||||
dispatch(setProjectId(projects[0]?.id));
|
||||
@ -161,7 +124,6 @@ const AttendancePage = () => {
|
||||
{ label: "Home", link: "/dashboard" },
|
||||
{ label: "Attendance", link: null },
|
||||
]}
|
||||
<<<<<<< Updated upstream
|
||||
></Breadcrumb>
|
||||
<div className="nav-align-top nav-tabs-shadow">
|
||||
<ul className="nav nav-tabs" role="tablist">
|
||||
@ -207,24 +169,6 @@ const AttendancePage = () => {
|
||||
data-bs-target="#navs-top-home"
|
||||
aria-controls="navs-top-home"
|
||||
aria-selected="true"
|
||||
=======
|
||||
></Breadcrumb>
|
||||
<div class="nav-align-top nav-tabs-shadow">
|
||||
<ul class="nav nav-tabs" role="tablist">
|
||||
<div
|
||||
className="dataTables_length text-start py-2 px-2"
|
||||
id="DataTables_Table_0_length"
|
||||
>
|
||||
{
|
||||
((loginUser && loginUser?.projects?.length > 1) ) && (<label>
|
||||
<select
|
||||
name="DataTables_Table_0_length"
|
||||
aria-controls="DataTables_Table_0"
|
||||
className="form-select form-select-sm"
|
||||
value={selectedProject}
|
||||
onChange={(e)=>dispatch(setProjectId(e.target.value))}
|
||||
aria-label=""
|
||||
>>>>>>> Stashed changes
|
||||
>
|
||||
All
|
||||
</button>
|
||||
@ -291,7 +235,7 @@ const AttendancePage = () => {
|
||||
role="tabpanel"
|
||||
>
|
||||
<Regularization
|
||||
attendance={attendances}
|
||||
|
||||
handleRequest={handleSubmit}
|
||||
/>
|
||||
</div>
|
||||
|
@ -5,7 +5,8 @@ const AttendanceRepository = {
|
||||
markAttendance:(data)=>api.post("/api/attendance/record",data),
|
||||
getAttendance:(id)=>api.get(`api/attendance/project/team?projectId=${id}`),
|
||||
getAttendanceFilteredByDate:(id,date)=>api.get(`api/attendance/project/team?projectId=${id+"&date="+date}`),
|
||||
getAttendanceLogs:(id)=>api.get(`api/attendance/log/attendance/${id}`)
|
||||
getAttendanceLogs: ( id ) => api.get( `api/attendance/log/attendance/${ id }` ),
|
||||
getRegularizeList: (id)=> api.get(`api/attendance/regularize?projectId=${id}`)
|
||||
|
||||
}
|
||||
|
||||
|
@ -17,10 +17,13 @@ export const fetchAttendanceData = createAsyncThunk(
|
||||
// This method for marking attendance if a date filter is applied
|
||||
export const markAttendance = createAsyncThunk(
|
||||
'attendanceLogs/markAttendance', // Updated action type prefix
|
||||
async (formData, thunkAPI) => {
|
||||
async ( formData, thunkAPI ) =>
|
||||
{
|
||||
debugger
|
||||
|
||||
try {
|
||||
let newRecordAttendance = {
|
||||
id: formData.id || null,
|
||||
Id: formData.id || null,
|
||||
comment: formData.description,
|
||||
employeeID: formData.employeeId,
|
||||
projectID: formData.projectId,
|
||||
|
@ -12,7 +12,7 @@ export const markCurrentAttendance = createAsyncThunk(
|
||||
console.log(formData)
|
||||
// Create the new attendance record
|
||||
const newRecordAttendance = {
|
||||
id: null,
|
||||
Id: formData.id || null,
|
||||
comment: formData.description,
|
||||
employeeID: formData.employeeId,
|
||||
projectId: projectId,
|
||||
|
Loading…
x
Reference in New Issue
Block a user