diff --git a/src/components/Project/Infrastructure/BuildingModel.jsx b/src/components/Project/Infrastructure/BuildingModel.jsx index 7db3c2dc..374c7719 100644 --- a/src/components/Project/Infrastructure/BuildingModel.jsx +++ b/src/components/Project/Infrastructure/BuildingModel.jsx @@ -6,6 +6,7 @@ import ProjectRepository from "../../../repositories/ProjectRepository"; import { useSelector } from "react-redux"; import { useProjectDetails } from "../../../hooks/useProjects"; import {getCachedData} from "../../../slices/apiDataManager"; +import showToast from "../../../services/toastService"; // Zod validation schema const buildingSchema = z.object({ @@ -79,10 +80,18 @@ const BuildingModel = ({ const onSubmitHandler = async (data) => { onSubmit({ ...data, projectId: project.id }); - reset({ - name: null, - description: null, - }); + reset( { + Id:"0", + name: "", + description: "", + } ); + if ( data.Id !== "0" ) + { + showToast( "Building updated successfully.", "success" ); + } else + { + showToast( "Building created successfully.", "success" ); + } }; useEffect( () => diff --git a/src/components/Project/Infrastructure/FloorModel.jsx b/src/components/Project/Infrastructure/FloorModel.jsx index 42e10123..2d64c275 100644 --- a/src/components/Project/Infrastructure/FloorModel.jsx +++ b/src/components/Project/Infrastructure/FloorModel.jsx @@ -2,7 +2,8 @@ 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"; +import { getCachedData } from "../../../slices/apiDataManager"; +import showToast from "../../../services/toastService"; // Zod validation schema const floorSchema = z.object({ @@ -24,13 +25,11 @@ const FloorModel = ({ onSubmit, clearTrigger, onClearComplete, -} ) => -{ - +}) => { const [formData, setFormData] = useState(defaultModel); - const [ selectedBuilding, setSelectedBuilding ] = useState( {} ); + const [selectedBuilding, setSelectedBuilding] = useState({}); const [buildings, setBuildings] = useState(project?.buildings || []); - + // Initialize the form with React Hook Form const { register, @@ -44,14 +43,12 @@ const FloorModel = ({ defaultValues: defaultModel, }); - useEffect( () => - { - + useEffect(() => { if (clearTrigger) { reset(defaultModel); onClearComplete(); } - }, [clearTrigger, onClearComplete, reset,]); + }, [clearTrigger, onClearComplete, reset]); // Handle building selection change const handleBuildigChange = (e) => { @@ -63,7 +60,6 @@ const FloorModel = ({ id: "", floorName: "", buildingId: building.id, - }); setValue("buildingId", building.id); // Set value for validation setValue("id", "0"); // Reset floorId when changing building @@ -73,13 +69,10 @@ const FloorModel = ({ id: "", floorName: "", buildingId: "0", - }); setValue("buildingId", "0"); } }; - - // Handle floor selection change const handleFloorChange = (e) => { @@ -90,15 +83,13 @@ const FloorModel = ({ id: floor.id, floorName: floor.floorName, buildingId: selectedBuilding.id, - }); - setValue("floorName", floor.floorName); // Set floor name for form + setValue("floorName", floor.floorName); } else { setFormData({ id: "0", floorName: "", buildingId: selectedBuilding.id, - }); setValue("floorName", ""); } @@ -107,23 +98,31 @@ const FloorModel = ({ // Handle form submission const onFormSubmit = (data) => { onSubmit(data); + reset({ + floorName: "", + }); + if (data.id !== "0") { + showToast("Floor updated successfully.", "success"); + } else { + showToast("Floor created successfully.", "success"); + } }; - - return (
-
)} @@ -214,20 +241,25 @@ const TaskModel = ({ - {errors.activityID &&

{errors.activityID.message}

} + {errors.activityID && ( +

{errors.activityID.message}

+ )}
)} @@ -240,12 +272,12 @@ const TaskModel = ({ - {errors.plannedWork &&

{errors.plannedWork.message}

} + {errors.plannedWork && ( +

{errors.plannedWork.message}

+ )}
)} @@ -258,12 +290,14 @@ const TaskModel = ({ - {errors.completedWork &&

{errors.completedWork.message}

} + {errors.completedWork && ( +

+ {errors.completedWork.message} +

+ )}
)} @@ -276,8 +310,6 @@ const TaskModel = ({ @@ -286,7 +318,11 @@ const TaskModel = ({
-
diff --git a/src/components/Project/Infrastructure/WorkAreaModel.jsx b/src/components/Project/Infrastructure/WorkAreaModel.jsx index 951575b8..f6beaddd 100644 --- a/src/components/Project/Infrastructure/WorkAreaModel.jsx +++ b/src/components/Project/Infrastructure/WorkAreaModel.jsx @@ -2,14 +2,18 @@ import React, { useState, useEffect } from "react"; import { set, useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; +import showToast from "../../../services/toastService"; // Zod schema for form validation -const workAreaSchema = z.object( { - id:z.string().nonempty("Floor is required"), - +const workAreaSchema = z.object({ + id: z.string().nonempty("Floor is required"), + buildingId: z.string().nonempty("Building is required"), floorId: z.string().nonempty("Floor is required"), - areaName: z.string().nonempty( "Work Area Name is required" ).min( 3, "Name must be at least 3 characters long" ), + areaName: z + .string() + .nonempty("Work Area Name is required") + .min(3, "Name must be at least 3 characters long"), }); // Default form data @@ -19,17 +23,30 @@ const defaultModel = { floorId: "0", }; -const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClose }) => { +const WorkAreaModel = ({ + project, + onSubmit, + clearTrigger, + onClearComplete, + onClose, +}) => { const [selectedBuilding, setSelectedBuilding] = useState(null); - const [ selectedFloor, setSelectedFloor ] = useState( null ); - const [selectdWorkArea,setWorkArea] = useState() + const [selectedFloor, setSelectedFloor] = useState(null); + const [selectdWorkArea, setWorkArea] = useState(); - const { register, handleSubmit, formState: { errors }, setValue, reset, watch } = useForm({ + const { + register, + handleSubmit, + formState: { errors }, + setValue, + reset, + watch, + } = useForm({ resolver: zodResolver(workAreaSchema), // Use Zod resolver for validation defaultValues: defaultModel, }); - const floorId = watch( "floorId" ); // Watch the floorId for conditional rendering + const floorId = watch("floorId"); // Watch the floorId for conditional rendering useEffect(() => { if (clearTrigger) { @@ -40,25 +57,22 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo } }, [clearTrigger, onClearComplete, reset]); - const handleWorkAreaChange = ( e ) => - { - - + const handleWorkAreaChange = (e) => { const { value } = e.target; if (value === "0") { - setValue("id", "0"); // Create New Work Area - setValue( "areaName", "" ); - - setWorkArea(String(0)) - } else { - const workArea = selectedFloor?.workAreas.find((b) => b.id === Number(value)); - if ( workArea ) - { - setValue("id", String(workArea.id)); // Set id as a string - setValue("areaName", workArea.areaName); - setWorkArea(String(workArea.id)) + setValue("id", "0"); // Create New Work Area + setValue("areaName", ""); + setWorkArea(String(0)); + } else { + const workArea = selectedFloor?.workAreas.find( + (b) => b.id === Number(value) + ); + if (workArea) { + setValue("id", String(workArea.id)); // Set id as a string + setValue("areaName", workArea.areaName); + setWorkArea(String(workArea.id)); } } }; @@ -69,8 +83,8 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo if (floor) { setSelectedFloor(floor); - setValue("floorId", floor.id); // Update floorId - setValue("id", "0"); // Reset Work Area ID for new area creation + setValue("floorId", floor.id); // Update floorId + setValue("id", "0"); // Reset Work Area ID for new area creation setValue("areaName", ""); // Reset Work Area Name when changing floor } else { setSelectedFloor(null); @@ -88,23 +102,31 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo reset(defaultModel); // Reset the form when a new building is selected }; - const onSubmitForm = ( data ) => - { - + const onSubmitForm = (data) => { let WorkArea = { id: data.id, areaName: data.areaName, floorId: data.floorId, - buildingId:data.buildingId + buildingId: data.buildingId, + }; + onSubmit(WorkArea); + + reset({ + id: "0", + areaName: "", + }); + if (data.id !== "0") { + showToast("WorkArea updated successfully.", "success"); + } else { + showToast("WorkArea created successfully.", "success"); } - onSubmit(WorkArea); // Send the final data to the parent }; const handleCancel = () => { - reset(defaultModel); // Reset the form to initial state + reset(defaultModel); setSelectedFloor(null); - setSelectedBuilding( null ); - onClose() + setSelectedBuilding(null); + onClose(); }; return ( @@ -112,14 +134,21 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo
- -
diff --git a/src/components/Project/Infrastructure/WorkItem.jsx b/src/components/Project/Infrastructure/WorkItem.jsx index ab85c28d..d568c14c 100644 --- a/src/components/Project/Infrastructure/WorkItem.jsx +++ b/src/components/Project/Infrastructure/WorkItem.jsx @@ -8,6 +8,7 @@ const WorkItem = ({ workItem, forBuilding, forFloor, forWorkArea }) => { const [itemName, setItemName] = useState(""); const [NewWorkItem, setNewWorkItem] = useState(); const [isModalOpen, setIsModalOpen] = useState(false); + const [showModal, setShowModal] = useState(false); const openModal = () => setIsModalOpen(true); const closeModal = () => setIsModalOpen(false); @@ -38,6 +39,8 @@ const WorkItem = ({ workItem, forBuilding, forFloor, forWorkArea }) => { tooltipTriggerList.forEach((el) => new bootstrap.Tooltip(el)); }, []); + const showModal1 = () => setShowModal(true); + const closeModal1 = () => setShowModal(false); return ( <>
{
+
+
+
+
+ +
+ +
Comming Soon
+
+
+
+
+ @@ -119,6 +149,7 @@ const WorkItem = ({ workItem, forBuilding, forFloor, forWorkArea }) => { aria-label="Modify" type="button" className="btn p-0 dropdown-toggle hide-arrow" + onClick={showModal1} > { aria-label="Delete" type="button" className="btn p-0 dropdown-toggle hide-arrow" + onClick={showModal1} > {
{" "} - + {" "} Edit - + {" "} Delete diff --git a/src/components/Project/ProjectInfra.jsx b/src/components/Project/ProjectInfra.jsx index 0c8eadac..eaee8972 100644 --- a/src/components/Project/ProjectInfra.jsx +++ b/src/components/Project/ProjectInfra.jsx @@ -160,7 +160,7 @@ const ProjectInfra = ({ }); setProject( updatedProject ); - closeTaskModel() + // closeTaskModel() } }) .catch((error) => { @@ -172,7 +172,6 @@ const ProjectInfra = ({ const submitData = async (infraObject) => { try { - debugger let response = await ProjectRepository.manageProjectInfra(infraObject); const entity = response.data; @@ -206,7 +205,8 @@ const ProjectInfra = ({ ...prevProject, buildings: updatedBuildings, } ) ); - closeBuildingModel() + // closeBuildingModel() + } // Handle the floor data else if (entity.floor) { @@ -243,7 +243,7 @@ const ProjectInfra = ({ data: updatedProject, }); setProject( updatedProject ); - closeFloorModel() + // closeFloorModel() } // Handle the work area data else if ( entity.workArea ) @@ -287,7 +287,7 @@ const ProjectInfra = ({ data: updatedProject, }); setProject( updatedProject ); - closeWorkAreaModel() + // closeWorkAreaModel() } // Handle the task (workItem) data else { @@ -296,7 +296,6 @@ const ProjectInfra = ({ } catch (Err) { showToast("Somthing wrong", "error"); } - handleClose(); };