Refactor_Expenses #321

Merged
pramod.mahajan merged 249 commits from Refactor_Expenses into hotfix/MasterActivity 2025-08-01 13:14:59 +00:00
3 changed files with 60 additions and 22 deletions
Showing only changes of commit 820f80562f - Show all commits

View File

@ -10,10 +10,43 @@ import showToast from "../../services/toastService";
import { checkIfCurrentDate } from "../../utils/dateUtils"; import { checkIfCurrentDate } from "../../utils/dateUtils";
const schema = z.object({ // const schema = z.object({
// markTime: z.string().nonempty({ message: "Time is required" }),
// 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" }), 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 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, }) => {
@ -31,6 +64,17 @@ 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,
@ -38,18 +82,17 @@ const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
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) { if (modeldata.forWhichTab === 1) {
handleSubmitForm(record) handleSubmitForm(record)
} else { } else {
// if ( modeldata?.currentDate && checkIfCurrentDate( modeldata?.currentDate ) )
// {
dispatch(markAttendance(record)) dispatch(markAttendance(record))
.unwrap() .unwrap()
.then((data) => { .then((data) => {
@ -61,11 +104,6 @@ const CheckCheckOutmodel = ({ modeldata, closeModal, handleSubmitForm, }) => {
showToast(error, "error"); showToast(error, "error");
}); });
// } else
// {
// 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}
// }
} }
closeModal() closeModal()

View File

@ -469,7 +469,7 @@ const { mutate: updateEmployee, isPending } = useUpdateEmployee();
</div> </div>
<div className="row mb-3"> <div className="row mb-3">
<div className="col-sm-4"> <div className="col-sm-4">
<div className="form-text text-start">Role</div> <div className="form-text text-start">Official Designation</div>
<div className="input-group input-group-merge "> <div className="input-group input-group-merge ">
<select <select
className="form-select form-select-sm" className="form-select form-select-sm"

View File

@ -480,7 +480,7 @@ const EmployeeList = () => {
aria-label="User: activate to sort column ascending" aria-label="User: activate to sort column ascending"
aria-sort="descending" aria-sort="descending"
> >
<div className="text-start ms-5">Role</div> <div className="text-start ms-5">Official Designation</div>
</th> </th>
<th <th