Changes in Activities DateRangePicket.
This commit is contained in:
parent
9b3ffdb33d
commit
020020056e
@ -1,6 +1,6 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
import DateRangePicker from "../common/DateRangePicker";
|
import DateRangePicker, { DateRangePicker1 } from "../common/DateRangePicker";
|
||||||
import { useDispatch, useSelector } from "react-redux";
|
import { useDispatch, useSelector } from "react-redux";
|
||||||
import { fetchEmployeeAttendanceData } from "../../slices/apiSlice/employeeAttendanceSlice";
|
import { fetchEmployeeAttendanceData } from "../../slices/apiSlice/employeeAttendanceSlice";
|
||||||
import usePagination from "../../hooks/usePagination";
|
import usePagination from "../../hooks/usePagination";
|
||||||
@ -11,6 +11,12 @@ import AttendLogs from "../Activities/AttendLogs";
|
|||||||
import { useAttendanceByEmployee } from "../../hooks/useAttendance";
|
import { useAttendanceByEmployee } from "../../hooks/useAttendance";
|
||||||
import GlobalModel from "../common/GlobalModel";
|
import GlobalModel from "../common/GlobalModel";
|
||||||
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
import { ITEMS_PER_PAGE } from "../../utils/constants";
|
||||||
|
import { FormProvider, useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { localToUtc } from "../../utils/appUtils";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const EmpAttendance = ({ employee }) => {
|
const EmpAttendance = ({ employee }) => {
|
||||||
const [attendances, setAttendnaces] = useState([]);
|
const [attendances, setAttendnaces] = useState([]);
|
||||||
@ -18,6 +24,21 @@ const EmpAttendance = ({ employee }) => {
|
|||||||
const [dateRange, setDateRange] = useState({ startDate: "", endDate: "" });
|
const [dateRange, setDateRange] = useState({ startDate: "", endDate: "" });
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
const [attendanceId, setAttendanecId] = useState();
|
const [attendanceId, setAttendanecId] = useState();
|
||||||
|
|
||||||
|
|
||||||
|
const methods = useForm({
|
||||||
|
resolver: zodResolver(z.object({
|
||||||
|
startDate: z.string(),
|
||||||
|
endDate: z.string()
|
||||||
|
})),
|
||||||
|
defaultValues: {
|
||||||
|
startDate: "",
|
||||||
|
endDate: ""
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const { control, register, handleSubmit, reset, watch } = methods;
|
||||||
|
const startDate = watch('startDate')
|
||||||
|
const endDate = watch('endDate')
|
||||||
const {
|
const {
|
||||||
data = [],
|
data = [],
|
||||||
isLoading: loading,
|
isLoading: loading,
|
||||||
@ -25,7 +46,7 @@ const EmpAttendance = ({ employee }) => {
|
|||||||
isError,
|
isError,
|
||||||
error,
|
error,
|
||||||
refetch,
|
refetch,
|
||||||
} = useAttendanceByEmployee(employee, dateRange.startDate, dateRange.endDate);
|
} = useAttendanceByEmployee(employee, localToUtc(startDate), localToUtc(endDate));
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
// const { data, loading, error } = useSelector(
|
// const { data, loading, error } = useSelector(
|
||||||
@ -90,7 +111,7 @@ const EmpAttendance = ({ employee }) => {
|
|||||||
if (
|
if (
|
||||||
!existing ||
|
!existing ||
|
||||||
new Date(rec.checkInTime || rec.checkOutTime) >
|
new Date(rec.checkInTime || rec.checkOutTime) >
|
||||||
new Date(existing.checkInTime || existing.checkOutTime)
|
new Date(existing.checkInTime || existing.checkOutTime)
|
||||||
) {
|
) {
|
||||||
uniqueMap.set(key, rec);
|
uniqueMap.set(key, rec);
|
||||||
}
|
}
|
||||||
@ -114,6 +135,11 @@ const EmpAttendance = ({ employee }) => {
|
|||||||
};
|
};
|
||||||
const closeModal = () => setIsModalOpen(false);
|
const closeModal = () => setIsModalOpen(false);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const onSubmit = (formData) => {
|
||||||
|
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isModalOpen && (
|
{isModalOpen && (
|
||||||
@ -127,17 +153,26 @@ const EmpAttendance = ({ employee }) => {
|
|||||||
id="DataTables_Table_0_length"
|
id="DataTables_Table_0_length"
|
||||||
>
|
>
|
||||||
<div className="col-md-4 my-0 ">
|
<div className="col-md-4 my-0 ">
|
||||||
<DateRangePicker
|
<>
|
||||||
DateDifference="7"
|
<FormProvider {...methods}>
|
||||||
onRangeChange={setDateRange}
|
<form onSubmit={handleSubmit(onSubmit)} className="p-2 text-start">
|
||||||
endDateMode="today"
|
<DateRangePicker1
|
||||||
/>
|
|
||||||
|
placeholder="DD-MM-YYYY To DD-MM-YYYY"
|
||||||
|
startField="startDate"
|
||||||
|
endField="endDate"
|
||||||
|
|
||||||
|
defaultRange={true}
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
|
</FormProvider>
|
||||||
|
</>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div className="col-md-2 m-0 text-end">
|
<div className="col-md-2 m-0 text-end">
|
||||||
<i
|
<i
|
||||||
className={`bx bx-refresh cursor-pointer fs-4 ${
|
className={`bx bx-refresh cursor-pointer fs-4 ${isFetching ? "spin" : ""
|
||||||
isFetching ? "spin" : ""
|
}`}
|
||||||
}`}
|
|
||||||
data-toggle="tooltip"
|
data-toggle="tooltip"
|
||||||
title="Refresh"
|
title="Refresh"
|
||||||
onClick={() => refetch()}
|
onClick={() => refetch()}
|
||||||
@ -230,9 +265,8 @@ const EmpAttendance = ({ employee }) => {
|
|||||||
{[...Array(totalPages)].map((_, index) => (
|
{[...Array(totalPages)].map((_, index) => (
|
||||||
<li
|
<li
|
||||||
key={index}
|
key={index}
|
||||||
className={`page-item ${
|
className={`page-item ${currentPage === index + 1 ? "active" : ""
|
||||||
currentPage === index + 1 ? "active" : ""
|
}`}
|
||||||
}`}
|
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="page-link "
|
className="page-link "
|
||||||
@ -243,9 +277,8 @@ const EmpAttendance = ({ employee }) => {
|
|||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
<li
|
<li
|
||||||
className={`page-item ${
|
className={`page-item ${currentPage === totalPages ? "disabled" : ""
|
||||||
currentPage === totalPages ? "disabled" : ""
|
}`}
|
||||||
}`}
|
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
className="page-link "
|
className="page-link "
|
||||||
|
|||||||
@ -108,7 +108,7 @@ export const useAttendanceByEmployee = (employeeId, fromDate, toDate) => {
|
|||||||
const res = await AttendanceRepository.getAttendanceByEmployee(employeeId, fromDate, toDate);
|
const res = await AttendanceRepository.getAttendanceByEmployee(employeeId, fromDate, toDate);
|
||||||
return res.data;
|
return res.data;
|
||||||
},
|
},
|
||||||
enabled,
|
enabled: !!fromDate && !! toDate,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -72,6 +72,8 @@ export const normalizeAllowedContentTypes = (allowedContentType) => {
|
|||||||
|
|
||||||
|
|
||||||
export function localToUtc(localDateString) {
|
export function localToUtc(localDateString) {
|
||||||
|
if (!localDateString || localDateString.trim() === "") return null; // return null instead of undefined
|
||||||
const date = new Date(localDateString);
|
const date = new Date(localDateString);
|
||||||
|
if (isNaN(date.getTime())) return null; // invalid date check
|
||||||
return date.toISOString();
|
return date.toISOString();
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user