update rooms

This commit is contained in:
Simon CATANESE 2024-05-13 18:12:59 +02:00
parent 1e3dcf340d
commit baf31f7959
10 changed files with 579 additions and 218 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -3,14 +3,14 @@
"",
"\\src",
"\\src\\api",
"\\src\\hooks",
"\\src\\pages",
"\\tests-examples",
"\\__tests__",
"\\__tests__\\api",
"\\__tests__\\pages",
"\\__tests__\\pages\\authenticated"
"\\src\\assets",
"\\src\\components",
"\\src\\components\\form",
"\\src\\components\\item",
"\\src\\components\\nav",
"\\src\\components\\parts",
"\\src\\components\\rooms"
],
"SelectedNode": "\\src\\pages\\rooms-stats.jsx",
"SelectedNode": "\\README.md",
"PreviewInSolutionExplorer": false
}

Binary file not shown.

View File

@ -5,7 +5,8 @@ import axios from "axios";
export const getRoom = async (_id) => {
try {
const response = await axios.get("/room/"+{_id});
let id = _id.toString()
const response = await axios.get(`/room/${id}`);
console.log(response.data)
return response.data;
} catch (error) {
@ -57,7 +58,7 @@ function formatRoomStatsGlobal(global){
const most_expensive_room = {
name: global.most_expensive_room.name,
price: global.most_expensive_room.price
count: global.most_expensive_room.count
};
return {

View File

@ -7,28 +7,29 @@ export const FormUpdateRoom = ({_id}) => {
const [form] = Form.useForm();
const [room, setRoom] = useState();
//useEffect(() => {
// const fetchData = async () => {
// const roomsResponse = await getRoom(_id);
// setRoom(roomsResponse);
// console.log(roomsResponse);
// };
useEffect(() => {
const fetchData = async () => {
console.log(_id)
const roomsResponse = await getRoom(_id);
setRoom(roomsResponse);
console.log(roomsResponse);
};
// fetchData();
//}, [_id]);
fetchData();
}, [_id]);
//useEffect(() => {
// if (room) {
// form.setFieldsValue({
// ...room
// });
// }
//}, [room, form]);
useEffect(() => {
if (room) {
form.setFieldsValue({
...room
});
}
}, [room, form]);
const onFinish = async (values) => {
try {
const response = await axios.post(
`${import.meta.env.VITE_API_URL}/room`,
const response = await axios.put(
`${import.meta.env.VITE_API_URL}/room/${_id}`,
values,
);
console.log(response.data);
@ -38,7 +39,7 @@ export const FormUpdateRoom = ({_id}) => {
};
return (
<Form form={form} onFinish={onFinish}>
<Form form={form} onFinish={onFinish}>
<Form.Item
label="Room Name"
name="name"

View File

@ -3,21 +3,21 @@ import { FormCreateRoom } from "../../components/form/formCreateRoom";
import { FormUpdateRoom } from "../../components/form/formUpdateRoom";
export const RoomDetail = ({
selectedRoom,
onCreateFormSubmit,
onBack,
selectedRoomParam,
onCreateFormSubmit
}) => {
const [isUpdateFormVisible, setIsUpdateFormVisible] = useState(false);
const [selectedRoom, setSelectedRoom] = useState(false);
useEffect(() => {
if (selectedRoom) {
setIsUpdateFormVisible(true);
if (selectedRoomParam) {
setSelectedRoom(selectedRoomParam)
setIsUpdateFormVisible(true);
}
}, [selectedRoom]);
}, [selectedRoomParam]);
const handleBackClick = () => {
setIsUpdateFormVisible(false);
onBack(null);
setIsUpdateFormVisible(false);
};
return (
@ -25,8 +25,8 @@ export const RoomDetail = ({
{isUpdateFormVisible ? (
<div>
<h2>Modifier une chambre (non fonctionnel)</h2>
<FormUpdateRoom />
<button onClick={handleBackClick}>Annuler </button>
<FormUpdateRoom _id={selectedRoom} />
</div>
) : (
<div>

View File

@ -7,7 +7,6 @@ import { formatRoomStats } from "../../api/room";
export const RoomList = ({ statsParam, onRoomClick }) => {
const [rooms, setRooms] = useState([]);
const [selectedRoom, setSelectedRoom] = useState("all");
useEffect(() => {
if (statsParam.rooms) {

View File

@ -55,7 +55,7 @@ const RoomStats = ({statsParam}) => {
<p>La chambre la plus chère :</p>
<ul>
<li><span>{stats?.global?.most_expensive_room?.name}</span></li>
<li>Prix total : <span>{stats?.global?.most_expensive_room?.price}</span></li>
<li>Prix total : <span>{stats?.global?.most_expensive_room?.count}</span></li>
</ul>
</div>
</div>

View File

@ -30,7 +30,7 @@ export const Rooms = () => {
const handleRoomClick = (roomId) => {
console.log("Clicked room ID:", roomId);
setSelectedRoom(roomId);
};
};
return (
<div className="manContainer">
@ -44,8 +44,7 @@ export const Rooms = () => {
</div>
<div className="detailContainer">
<RoomDetail
selectedRoom={selectedRoom}
onBack={handleRoomClick}
selectedRoomParam={selectedRoom}
></RoomDetail>
</div>
</div>