At the time of Regularize status code 400 were shown now solved we add error message in popup "Checkout time must be later than check-in time".
This commit is contained in:
parent
a02c72859f
commit
2d1cddb2e0
@ -8,13 +8,45 @@ import { useDispatch, useSelector } from "react-redux";
|
|||||||
import { markAttendance } from "../../slices/apiSlice/attedanceLogsSlice";
|
import { markAttendance } from "../../slices/apiSlice/attedanceLogsSlice";
|
||||||
import showToast from "../../services/toastService";
|
import showToast from "../../services/toastService";
|
||||||
import { checkIfCurrentDate } from "../../utils/dateUtils";
|
import { checkIfCurrentDate } from "../../utils/dateUtils";
|
||||||
import { useMarkAttendance } from "../../hooks/useAttendance";
|
|
||||||
|
|
||||||
|
|
||||||
const schema = z.object({
|
// const schema = z.object({
|
||||||
markTime: z.string().nonempty({ message: "Time is required" }),
|
// markTime: z.string().nonempty({ message: "Time is required" }),
|
||||||
description: z.string().max(200, "description should less than 200 chracters").optional()
|
// description: z.string().max(200, "description should less than 200 chracters").optional()
|
||||||
});
|
// });
|
||||||
|
|
||||||
|
const createSchema = (modeldata) => {
|
||||||
|
return z
|
||||||
|
.object({
|
||||||
|
markTime: z.string().nonempty({ message: "Time is required" }),
|
||||||
|
description: z
|
||||||
|
.string()
|
||||||
|
.max(200, "Description should be less than 200 characters")
|
||||||
|
.optional(),
|
||||||
|
})
|
||||||
|
.refine((data) => {
|
||||||
|
if (modeldata?.checkInTime && !modeldata?.checkOutTime) {
|
||||||
|
const checkIn = new Date(modeldata.checkInTime);
|
||||||
|
const [time, modifier] = data.markTime.split(" ");
|
||||||
|
const [hourStr, minuteStr] = time.split(":");
|
||||||
|
let hour = parseInt(hourStr, 10);
|
||||||
|
const minute = parseInt(minuteStr, 10);
|
||||||
|
|
||||||
|
if (modifier === "PM" && hour !== 12) hour += 12;
|
||||||
|
if (modifier === "AM" && hour === 12) hour = 0;
|
||||||
|
|
||||||
|
const checkOut = new Date(checkIn);
|
||||||
|
checkOut.setHours(hour, minute, 0, 0);
|
||||||
|
|
||||||
|
return checkOut > checkIn;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}, {
|
||||||
|
message: "Checkout time must be later than check-in time",
|
||||||
|
path: ["markTime"],
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
||||||
|
|
||||||
@ -33,38 +65,38 @@ const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
|||||||
return `${day}-${month}-${year}`;
|
return `${day}-${month}-${year}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// const {
|
||||||
|
// register,
|
||||||
|
// handleSubmit,
|
||||||
|
// formState: { errors },
|
||||||
|
// reset,
|
||||||
|
// setValue,
|
||||||
|
// } = useForm({
|
||||||
|
// resolver: zodResolver(schema),
|
||||||
|
// mode: "onChange"
|
||||||
|
// });
|
||||||
|
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
formState: { errors },
|
formState: { errors },
|
||||||
reset,
|
reset,
|
||||||
setValue,
|
setValue,
|
||||||
} = useForm({
|
} = useForm({
|
||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(createSchema(modeldata)),
|
||||||
mode: "onChange"
|
mode: "onChange",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const onSubmit = (data) => {
|
const onSubmit = (data) => {
|
||||||
let record = { ...data, date: new Date().toLocaleDateString(), latitude: coords.latitude, longitude: coords.longitude, employeeId: modeldata.employeeId, action: modeldata.action, id: modeldata?.id || null }
|
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 || modeldata.forWhichTab === 2) {
|
if (modeldata.forWhichTab === 1) {
|
||||||
// handleSubmitForm(record)
|
handleSubmitForm(record)
|
||||||
const payload = {
|
} else {
|
||||||
Id: modeldata?.id || null,
|
|
||||||
comment: data.description,
|
dispatch(markAttendance(record))
|
||||||
employeeID: modeldata.employeeId,
|
.unwrap()
|
||||||
projectId: projectId,
|
.then((data) => {
|
||||||
date: new Date().toISOString(),
|
|
||||||
markTime: data.markTime,
|
|
||||||
latitude: coords.latitude.toString(),
|
|
||||||
longitude: coords.longitude.toString(),
|
|
||||||
action: modeldata.action,
|
|
||||||
image: null,
|
|
||||||
};
|
|
||||||
MarkAttendance({payload,forWhichTab:modeldata.forWhichTab})
|
|
||||||
// } else {
|
|
||||||
// dispatch(markAttendance(record))
|
|
||||||
// .unwrap()
|
|
||||||
// .then((data) => {
|
|
||||||
|
|
||||||
// showToast("Attendance Marked Successfully", "success");
|
// showToast("Attendance Marked Successfully", "success");
|
||||||
// })
|
// })
|
||||||
@ -72,8 +104,8 @@ const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
|
|||||||
|
|
||||||
// showToast(error, "error");
|
// showToast(error, "error");
|
||||||
|
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
|
|
||||||
closeModal()
|
closeModal()
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user