fixed attendance logs, attendanance rolename and removed import-userProfile.

This commit is contained in:
Pramod Mahajan 2025-04-09 11:23:34 +05:30
parent e8aa2ae718
commit faf68cac25
11 changed files with 130 additions and 50 deletions

View File

@ -29,7 +29,7 @@ const AttendLogs = ({ Id }) => {
<tbody>
{logs
.slice()
.sort((a, b) => new Date(b.activityTime) - new Date(a.activityTime))
.sort((a, b) => b.id - a.id)
.map((log, index) => (
<tr key={index}>
<td>{convertShortTime(log.activityTime)}</td>

View File

@ -67,7 +67,7 @@ const Regularization = ( { handleRequest} ) =>
</tr>
))
):(
<td colSpan={5}>No Result Found</td>
<td colSpan={5}>No Record Found</td>
)
}
</tbody>

View File

@ -1,4 +1,4 @@
import { useProfile } from "../../hooks/useProfile";
const Dashboard = () => {

View File

@ -3,6 +3,9 @@ import { useForm } from "react-hook-form";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import ProjectRepository from "../../../repositories/ProjectRepository";
import { useSelector } from "react-redux";
import { useProjectDetails } from "../../../hooks/useProjects";
import {getCachedData} from "../../../slices/apiDataManager";
// Zod validation schema
const buildingSchema = z.object({
@ -22,6 +25,11 @@ const BuildingModel = ({
onClearComplete,
editingBuilding = null,
}) => {
const selectedProject = useSelector(
(store) => store.localVariables.projectId
);
const [buildings ,setBuildings] = useState([])
const projects_Details = getCachedData("projectInfo")
const [formData, setFormData] = useState({
id: "",
name: "",
@ -29,7 +37,6 @@ const BuildingModel = ({
projectId: project.id,
});
// Reset form data if clearTrigger is true, or if editing a building
useEffect(() => {
if (clearTrigger) {
setFormData({ id: "", name: "", description: "", projectId: project.id });
@ -38,39 +45,50 @@ const BuildingModel = ({
setFormData({ ...editingBuilding, projectId: project.id });
}
return () =>
{
setValue("name",null)
}
return () => {
setValue("name", null);
};
}, [clearTrigger, onClearComplete, editingBuilding, project.id]);
const { register, handleSubmit, formState: { errors }, setValue,reset,getValues} = useForm({
const {
register,
handleSubmit,
formState: { errors },
setValue,
reset,
getValues,
} = useForm({
resolver: zodResolver(buildingSchema),
defaultValues: formData, // Set default values from formData state
});
const handleBuildingChange = (e) => {
const selectedBuilding = project.buildings.find(b => b.id === +e.target.value);
const selectedBuilding = project.buildings.find(
(b) => b.id === +e.target.value
);
if (selectedBuilding) {
setFormData({ ...selectedBuilding, projectId: project.id });
setValue("name", selectedBuilding.name); // Update name field
setValue("description", selectedBuilding.description); // Update description field
} else {
setFormData({ id: "", name: "", description: "", projectId: project.id });
setValue("name", "");
setValue("description", "");
setValue("name", "");
setValue("description", "");
}
};
const onSubmitHandler = async( data ) =>
{
onSubmit( {...data, projectId: project.id} );
reset( {
const onSubmitHandler = async (data) => {
onSubmit({ ...data, projectId: project.id });
reset({
name: null,
description:null
})
description: null,
});
};
useEffect( () =>
{
setBuildings(projects_Details.data?.buildings)
},[projects_Details])
return (
<div className="modal-dialog modal-lg modal-simple modal-edit-user">
<div className="modal-content">
@ -81,23 +99,34 @@ const BuildingModel = ({
data-bs-dismiss="modal"
aria-label="Close"
onClick={onClose}
></button>
<h5 className="text-center mb-2">Manage Buildings - {project.name}</h5>
<h5 className="text-center mb-2">
Manage Buildings - {project.name}
</h5>
<form onSubmit={handleSubmit(onSubmitHandler)} className="row g-2">
<div className="col-12">
<label className="form-label">Select Building</label>
<select
{...register("Id")}
className="select2 form-select form-select-sm"
onChange={(e) => { handleBuildingChange(e); }}
onChange={(e) => {
handleBuildingChange(e);
}}
>
<option value="0">Add New Building</option>
{project.buildings.map((building) => (
<option key={building.id} value={building.id}>{building.name}</option>
))}
<option value="0">Add New Building</option>
{buildings &&
buildings?.length > 0 &&
buildings.map((building) => (
<option key={building.id} value={building.id}>
{building.name}
</option>
))}
</select>
{errors.Id && <span className="danger-text">{errors.Id.message}</span>}
{errors.Id && (
<span className="danger-text">{errors.Id.message}</span>
)}
</div>
<div className="col-12">
@ -109,7 +138,9 @@ const BuildingModel = ({
type="text"
className="form-control form-control-sm"
/>
{errors.name && <span className="danger-text">{errors.name.message}</span>}
{errors.name && (
<span className="danger-text">{errors.name.message}</span>
)}
</div>
<div className="col-12">
@ -120,14 +151,26 @@ const BuildingModel = ({
rows="5"
className="form-control form-control-sm"
/>
{errors.description && <span className="danger-text">{errors.description.message}</span>}
{errors.description && (
<span className="danger-text">
{errors.description.message}
</span>
)}
</div>
<div className="col-12 text-center">
<button type="submit" className="btn btn-sm btn-primary me-3">
{ ( formData.id && getValues("name")) ? "Edit Building" : "Add Building"}
{formData.id && getValues("name")
? "Edit Building"
: "Add Building"}
</button>
<button type="reset" className="btn btn-sm btn-label-secondary" data-bs-dismiss="modal" aria-label="Close" onClick={onClose}>
<button
type="reset"
className="btn btn-sm btn-label-secondary"
data-bs-dismiss="modal"
aria-label="Close"
onClick={onClose}
>
Cancel
</button>
</div>

View File

@ -2,6 +2,7 @@ import React, { useState, useEffect } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import {getCachedData} from "../../../slices/apiDataManager";
// Zod validation schema
const floorSchema = z.object({
@ -23,7 +24,10 @@ const FloorModel = ({
onSubmit,
clearTrigger,
onClearComplete,
}) => {
} ) =>
{
const [ buildings, setBuildings ] = useState( [] )
const projects_Details = getCachedData( "projectInfo" )
const [formData, setFormData] = useState(defaultModel);
const [selectedBuilding, setSelectedBuilding] = useState({});
@ -32,6 +36,7 @@ const FloorModel = ({
register,
handleSubmit,
setValue,
getValues,
reset,
formState: { errors },
} = useForm({
@ -39,17 +44,19 @@ const FloorModel = ({
defaultValues: defaultModel,
});
useEffect(() => {
useEffect( () =>
{
if (clearTrigger) {
reset(defaultModel);
onClearComplete();
}
}, [clearTrigger, onClearComplete, reset]);
}, [clearTrigger, onClearComplete, reset,]);
// Handle building selection change
const handleBuildigChange = (e) => {
const buildingId = e.target.value;
const building = project.buildings.find((b) => b.id === Number(buildingId));
const building = buildings.find((b) => b.id === Number(buildingId));
if (building) {
setSelectedBuilding(building);
setFormData({
@ -71,11 +78,13 @@ const FloorModel = ({
setValue("buildingId", "0");
}
};
// Handle floor selection change
const handleFloorChange = (e) => {
const id = e.target.value;
const floor = selectedBuilding.floors.find((b) => b.id === Number(id));
const floor = buildings[getValues("buildingId")].floors.find((b) => b.id === Number(id));
if (floor) {
setFormData({
id: floor.id,
@ -99,7 +108,13 @@ const FloorModel = ({
const onFormSubmit = (data) => {
onSubmit(data);
};
useEffect( () =>
{
setBuildings(projects_Details.data?.buildings)
}, [ projects_Details ] )
console.log(getValues("buildingId"))
console.log(buildings)
return (
<div className="modal-dialog modal-lg modal-simple modal-edit-user">
<div className="modal-content">
@ -125,7 +140,9 @@ const FloorModel = ({
onChange={handleBuildigChange}
>
<option value="0">Select Building</option>
{project.buildings.map((building) => (
{buildings &&
buildings?.length > 0 &&
buildings.map((building) => (
<option key={building.id} value={building.id}>
{building.name}
</option>
@ -149,11 +166,19 @@ const FloorModel = ({
onChange={handleFloorChange}
>
<option value="0">Add New Floor</option>
{selectedBuilding?.floors?.map((floor) => (
{/* {selectedBuilding?.floors?.map((floor) => (
<option key={floor.id} value={floor.id}>
{floor.floorName}
</option>
))}
) )} */}
{buildings &&
buildings[getValues("buildingId")]?.length > 0 &&
buildings[getValues("buildingId")]?.map((floor) => (
<option key={floor.id} value={floor.id}>
{floor.floorName}
</option>
))}
</select>
{errors.id && (
<p className="text-danger">{errors.id.message}</p>
@ -186,11 +211,11 @@ const FloorModel = ({
: "Add Floor"}
</button>
<button
type="reset"
type="button"
className="btn btn-sm btn-label-secondary"
data-bs-dismiss="modal"
aria-label="Close"
onClick={onclose}
onClick={onClose}
>
Cancel
</button>

View File

@ -30,7 +30,10 @@ export const useAttendace =(projectId)=>{
useEffect(()=>{
fetchData(projectId);
if ( projectId )
{
fetchData(projectId);
}
},[projectId])
return {attendance,loading,error}
@ -40,7 +43,7 @@ export const useAttendace =(projectId)=>{
export const useEmployeeAttendacesLog = (id) => {
const [logs, setLogs] = useState();
const [logs, setLogs] = useState([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState(null);

View File

@ -100,6 +100,8 @@ const AttendancePage = () => {
dispatch(setProjectId(projects[0]?.id));
}, [projects]);
return (
<>
{isCreateModalOpen && modelConfig && (

View File

@ -14,15 +14,16 @@ import Breadcrumb from "../../components/common/Breadcrumb";
import { cacheData, getCachedData } from "../../slices/apiDataManager";
import ProjectRepository from "../../repositories/ProjectRepository";
import { ActivityeRepository } from "../../repositories/MastersRepository";
import "./ProjectDetails.css";
import {useEmployeesByProjectAllocated, useProjectDetails} from "../../hooks/useProjects";
import {useDispatch} from "react-redux";
import {setProjectId} from "../../slices/localVariablesSlice";
const ProjectDetails = () => {
let {projectId} = useParams();
const {projects_Details,loading:projectLoading,error:ProjectError} = useProjectDetails(projectId)
const dispatch = useDispatch()
const [project, setProject] = useState(null);
const [ projectDetails, setProjectDetails ] = useState( null );
const [activities, setActivities] = useState(null);
@ -169,10 +170,11 @@ const ProjectDetails = () => {
useEffect(() => {
// fetchData();
dispatch(setProjectId(projectId))
setProject( projects_Details )
setProjectDetails(projects_Details)
fetchActivities();
}, [projects_Details]);
}, [projects_Details,projectId]);
return (

View File

@ -1,5 +1,6 @@
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import AttendanceRepository from '../../repositories/AttendanceRepository';
import {clearCacheKey} from '../apiDataManager';
// Fetch attendance data
export const fetchAttendanceData = createAsyncThunk(
@ -19,7 +20,7 @@ export const markAttendance = createAsyncThunk(
'attendanceLogs/markAttendance', // Updated action type prefix
async ( formData, thunkAPI ) =>
{
debugger
try {
let newRecordAttendance = {
@ -35,7 +36,8 @@ export const markAttendance = createAsyncThunk(
image: null,
};
const response = await AttendanceRepository.markAttendance(newRecordAttendance);
const response = await AttendanceRepository.markAttendance( newRecordAttendance );
clearCacheKey("AttendanceLogs")
return response.data; // Return the newly created or updated record
} catch (error) {
return thunkAPI.rejectWithValue(error.message);

View File

@ -1,15 +1,16 @@
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
import AttendanceRepository from '../../repositories/AttendanceRepository';
import {clearCacheKey} from '../apiDataManager';
export const markCurrentAttendance = createAsyncThunk(
'attendanceCurrentDate/markAttendance',
async ( formData, {getState, dispatch, rejectWithValue} ) =>
{
debugger
const { projectId } = getState().localVariables
try
{
console.log(formData)
// Create the new attendance record
const newRecordAttendance = {
Id: formData.id || null,
@ -26,6 +27,7 @@ export const markCurrentAttendance = createAsyncThunk(
const response = await AttendanceRepository.markAttendance(newRecordAttendance);
const markedAttendance = response.data
clearCacheKey("AttendanceLogs")
return markedAttendance;
} catch (error) {

View File

@ -3,6 +3,7 @@ import { useNavigate } from "react-router-dom";
import axiosRetry from "axios-retry";
import showToast from "../services/toastService";
const base_Url = process.env.VITE_BASE_URL;
// const base_Url = https://api.marcoaiot.com;
export const axiosClient = axios.create({
baseURL: base_Url, // Your Web API URL
withCredentials: false, // Required if the API uses cookies