import "./RoomWidget.css"; import { useHotel } from "../context/HotelContext"; import { useState } from "react"; export default function RoomWidget({}) { const { rooms } = useHotel(); return (
{rooms.map(room => ( ))}
); } function RoomCard({ number, status ,id}) { //FIXME: this shouldn't use hotel context, instead : set the state once on load const { updateRoomStatus } = useHotel(); const [editing, setEdtiting] = useState(false); const [value, SetValue] = useState(status); function submit() { updateRoomStatus(id,value); setEdtiting(false); } function closeInput(){ setEdtiting(false); } return (

Room {number}

{!editing ?(

setEdtiting(true)} style={{ cursor: "pointer" }}> Status: {status}

): (
SetValue(e.target.value)} onKeyDown={e => e.key === "Enter" && submit()} onBlur={closeInput} />
)}
); } //export default roomWidget