diff --git a/src/components/Activities/AttendLogs.jsx b/src/components/Activities/AttendLogs.jsx index 2000f7eb..f8d39f7a 100644 --- a/src/components/Activities/AttendLogs.jsx +++ b/src/components/Activities/AttendLogs.jsx @@ -29,7 +29,7 @@ const AttendLogs = ({ Id }) => { {logs .slice() - .sort((a, b) => new Date(b.activityTime) - new Date(a.activityTime)) + .sort((a, b) => b.id - a.id) .map((log, index) => ( {convertShortTime(log.activityTime)} diff --git a/src/components/Activities/Regularization.jsx b/src/components/Activities/Regularization.jsx index 55504593..0a310c82 100644 --- a/src/components/Activities/Regularization.jsx +++ b/src/components/Activities/Regularization.jsx @@ -67,7 +67,7 @@ const Regularization = ( { handleRequest} ) => )) ):( - No Result Found + No Record Found ) } diff --git a/src/components/Dashboard/Dashboard.tsx b/src/components/Dashboard/Dashboard.tsx index fb4876af..ceb15793 100644 --- a/src/components/Dashboard/Dashboard.tsx +++ b/src/components/Dashboard/Dashboard.tsx @@ -1,4 +1,4 @@ -import { useProfile } from "../../hooks/useProfile"; + const Dashboard = () => { diff --git a/src/components/Project/Infrastructure/BuildingModel.jsx b/src/components/Project/Infrastructure/BuildingModel.jsx index 89216ea7..1ef3e1e2 100644 --- a/src/components/Project/Infrastructure/BuildingModel.jsx +++ b/src/components/Project/Infrastructure/BuildingModel.jsx @@ -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 (
@@ -81,23 +99,34 @@ const BuildingModel = ({ data-bs-dismiss="modal" aria-label="Close" onClick={onClose} - > -
Manage Buildings - {project.name}
+
+ Manage Buildings - {project.name} +
- {errors.Id && {errors.Id.message}} + {errors.Id && ( + {errors.Id.message} + )}
@@ -109,7 +138,9 @@ const BuildingModel = ({ type="text" className="form-control form-control-sm" /> - {errors.name && {errors.name.message}} + {errors.name && ( + {errors.name.message} + )}
@@ -120,14 +151,26 @@ const BuildingModel = ({ rows="5" className="form-control form-control-sm" /> - {errors.description && {errors.description.message}} + {errors.description && ( + + {errors.description.message} + + )}
-
diff --git a/src/components/Project/Infrastructure/FloorModel.jsx b/src/components/Project/Infrastructure/FloorModel.jsx index d66cae15..75b50294 100644 --- a/src/components/Project/Infrastructure/FloorModel.jsx +++ b/src/components/Project/Infrastructure/FloorModel.jsx @@ -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 (
@@ -125,7 +140,9 @@ const FloorModel = ({ onChange={handleBuildigChange} > - {project.buildings.map((building) => ( + {buildings && + buildings?.length > 0 && + buildings.map((building) => ( @@ -149,11 +166,19 @@ const FloorModel = ({ onChange={handleFloorChange} > - {selectedBuilding?.floors?.map((floor) => ( + {/* {selectedBuilding?.floors?.map((floor) => ( - ))} + ) )} */} + + {buildings && + buildings[getValues("buildingId")]?.length > 0 && + buildings[getValues("buildingId")]?.map((floor) => ( + + ))} {errors.id && (

{errors.id.message}

@@ -186,11 +211,11 @@ const FloorModel = ({ : "Add Floor"} diff --git a/src/hooks/useAttendance.js b/src/hooks/useAttendance.js index 65f1f0f4..7c52244e 100644 --- a/src/hooks/useAttendance.js +++ b/src/hooks/useAttendance.js @@ -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); diff --git a/src/pages/Activities/AttendancePage.jsx b/src/pages/Activities/AttendancePage.jsx index 71f05bc4..9e260433 100644 --- a/src/pages/Activities/AttendancePage.jsx +++ b/src/pages/Activities/AttendancePage.jsx @@ -100,6 +100,8 @@ const AttendancePage = () => { dispatch(setProjectId(projects[0]?.id)); }, [projects]); + + return ( <> {isCreateModalOpen && modelConfig && ( diff --git a/src/pages/project/ProjectDetails.jsx b/src/pages/project/ProjectDetails.jsx index 937c6de7..7d3850b5 100644 --- a/src/pages/project/ProjectDetails.jsx +++ b/src/pages/project/ProjectDetails.jsx @@ -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 ( diff --git a/src/slices/apiSlice/attedanceLogsSlice.js b/src/slices/apiSlice/attedanceLogsSlice.js index ff5999ca..6e26c5b6 100644 --- a/src/slices/apiSlice/attedanceLogsSlice.js +++ b/src/slices/apiSlice/attedanceLogsSlice.js @@ -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); diff --git a/src/slices/apiSlice/attendanceAllSlice.js b/src/slices/apiSlice/attendanceAllSlice.js index 6126ce77..d5dfc157 100644 --- a/src/slices/apiSlice/attendanceAllSlice.js +++ b/src/slices/apiSlice/attendanceAllSlice.js @@ -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) { diff --git a/src/utils/axiosClient.jsx b/src/utils/axiosClient.jsx index dd08fdf3..c20be7f5 100644 --- a/src/utils/axiosClient.jsx +++ b/src/utils/axiosClient.jsx @@ -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