diff --git a/frontend/occupi-web/src/components/addRoomModal/AddRoomModal.tsx b/frontend/occupi-web/src/components/addRoomModal/AddRoomModal.tsx index 877befed..dbaef3f5 100644 --- a/frontend/occupi-web/src/components/addRoomModal/AddRoomModal.tsx +++ b/frontend/occupi-web/src/components/addRoomModal/AddRoomModal.tsx @@ -7,7 +7,9 @@ import { Button, Input, ModalContent, + Textarea, } from "@nextui-org/react"; +import DataService from "DataService"; interface Room { roomId: string; @@ -39,6 +41,8 @@ const AddRoomModal: React.FC = ({ isOpen, onClose, onSave }) roomName: "", isDisabled: false, }); + const [isLoading, setIsLoading] = useState(false); + const [err, setErr] = useState(null); const handleInputChange = (e: React.ChangeEvent) => { const { name, value } = e.target; @@ -46,75 +50,110 @@ const AddRoomModal: React.FC = ({ isOpen, onClose, onSave }) }; const handleSave = () => { - onSave(newRoom); - setNewRoom({ - roomId: "", - roomNo: "", - floorNo: "", - minOccupancy: 1, - maxOccupancy: 1, - description: "", - resources: [], - roomName: "", - isDisabled: false, - }); + //validate the form + if (newRoom.roomId === "" || newRoom.roomNo === "" || newRoom.floorNo === "") { + setErr("Please fill all the fields"); + return; + } + + setIsLoading(true); + + DataService.addRoom(newRoom).then((_) => { + onSave(newRoom); + setNewRoom({ + roomId: "", + roomNo: "", + floorNo: "", + minOccupancy: 1, + maxOccupancy: 1, + description: "", + resources: [], + roomName: "", + isDisabled: false, + }); + setIsLoading(false); + onClose(); + }).catch((e) => { + setErr("encountered some error"); + console.log(e); + setIsLoading(false); + }) + }; return ( - + Add New Room - - - - - - + + + +
+ + +
+
+ + +
+