diff --git a/src/components/Project/Infrastructure/FloorModel.jsx b/src/components/Project/Infrastructure/FloorModel.jsx index 1e748f77..2d64c275 100644 --- a/src/components/Project/Infrastructure/FloorModel.jsx +++ b/src/components/Project/Infrastructure/FloorModel.jsx @@ -2,7 +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"; +import { getCachedData } from "../../../slices/apiDataManager"; import showToast from "../../../services/toastService"; // Zod validation schema @@ -25,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, @@ -45,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) => { @@ -64,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 @@ -74,13 +69,10 @@ const FloorModel = ({ id: "", floorName: "", buildingId: "0", - }); setValue("buildingId", "0"); } }; - - // Handle floor selection change const handleFloorChange = (e) => { @@ -91,15 +83,13 @@ const FloorModel = ({ id: floor.id, floorName: floor.floorName, buildingId: selectedBuilding.id, - }); - setValue("floorName", floor.floorName); + setValue("floorName", floor.floorName); } else { setFormData({ id: "0", floorName: "", buildingId: selectedBuilding.id, - }); setValue("floorName", ""); } @@ -107,36 +97,32 @@ 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" ); - } - + onSubmit(data); + reset({ + floorName: "", + }); + if (data.id !== "0") { + showToast("Floor updated successfully.", "success"); + } else { + showToast("Floor created successfully.", "success"); + } }; - - return (