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..1e748f77 100644 --- a/src/components/Project/Infrastructure/FloorModel.jsx +++ b/src/components/Project/Infrastructure/FloorModel.jsx @@ -3,6 +3,7 @@ import { useForm } from "react-hook-form"; import { z } from "zod"; import { zodResolver } from "@hookform/resolvers/zod"; import {getCachedData} from "../../../slices/apiDataManager"; +import showToast from "../../../services/toastService"; // Zod validation schema const floorSchema = z.object({ @@ -92,7 +93,7 @@ const FloorModel = ({ buildingId: selectedBuilding.id, }); - setValue("floorName", floor.floorName); // Set floor name for form + setValue("floorName", floor.floorName); } else { setFormData({ id: "0", @@ -106,7 +107,19 @@ const FloorModel = ({ // Handle form submission const onFormSubmit = (data) => { - onSubmit(data); + onSubmit( data ); + reset( + { + floorName: "" + } ) + if ( data.id !== "0" ) + { + showToast( "Floor updated successfully.", "success" ); + } else + { + showToast( "Floor created successfully.", "success" ); + } + }; diff --git a/src/components/Project/Infrastructure/WorkAreaModel.jsx b/src/components/Project/Infrastructure/WorkAreaModel.jsx index 951575b8..743fc462 100644 --- a/src/components/Project/Infrastructure/WorkAreaModel.jsx +++ b/src/components/Project/Infrastructure/WorkAreaModel.jsx @@ -2,6 +2,7 @@ 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( { @@ -97,11 +98,25 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo floorId: data.floorId, buildingId:data.buildingId } - onSubmit(WorkArea); // Send the final data to the parent + onSubmit( WorkArea ); + + reset( { + id:"0", + areaName:"" + } ); + if ( data.id !== "0" ) + { + showToast( "WorkArea updated successfully.", "success" ); + } else + { + showToast( "WorkArea created successfully.", "success" ); + + } + }; const handleCancel = () => { - reset(defaultModel); // Reset the form to initial state + reset(defaultModel); setSelectedFloor(null); setSelectedBuilding( null ); onClose() @@ -170,6 +185,7 @@ const WorkAreaModel = ({ project, onSubmit, clearTrigger, onClearComplete, onClo className="select2 form-select form-select-sm" {...register("id")} onChange={handleWorkAreaChange} + > {selectedFloor?.workAreas?.map((workArea) => (