update rooms
This commit is contained in:
parent
1e3dcf340d
commit
baf31f7959
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -3,14 +3,14 @@
|
|||||||
"",
|
"",
|
||||||
"\\src",
|
"\\src",
|
||||||
"\\src\\api",
|
"\\src\\api",
|
||||||
"\\src\\hooks",
|
"\\src\\assets",
|
||||||
"\\src\\pages",
|
"\\src\\components",
|
||||||
"\\tests-examples",
|
"\\src\\components\\form",
|
||||||
"\\__tests__",
|
"\\src\\components\\item",
|
||||||
"\\__tests__\\api",
|
"\\src\\components\\nav",
|
||||||
"\\__tests__\\pages",
|
"\\src\\components\\parts",
|
||||||
"\\__tests__\\pages\\authenticated"
|
"\\src\\components\\rooms"
|
||||||
],
|
],
|
||||||
"SelectedNode": "\\src\\pages\\rooms-stats.jsx",
|
"SelectedNode": "\\README.md",
|
||||||
"PreviewInSolutionExplorer": false
|
"PreviewInSolutionExplorer": false
|
||||||
}
|
}
|
BIN
.vs/slnx.sqlite
BIN
.vs/slnx.sqlite
Binary file not shown.
@ -5,7 +5,8 @@ import axios from "axios";
|
|||||||
|
|
||||||
export const getRoom = async (_id) => {
|
export const getRoom = async (_id) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get("/room/"+{_id});
|
let id = _id.toString()
|
||||||
|
const response = await axios.get(`/room/${id}`);
|
||||||
console.log(response.data)
|
console.log(response.data)
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -57,7 +58,7 @@ function formatRoomStatsGlobal(global){
|
|||||||
|
|
||||||
const most_expensive_room = {
|
const most_expensive_room = {
|
||||||
name: global.most_expensive_room.name,
|
name: global.most_expensive_room.name,
|
||||||
price: global.most_expensive_room.price
|
count: global.most_expensive_room.count
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -7,28 +7,29 @@ export const FormUpdateRoom = ({_id}) => {
|
|||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [room, setRoom] = useState();
|
const [room, setRoom] = useState();
|
||||||
|
|
||||||
//useEffect(() => {
|
useEffect(() => {
|
||||||
// const fetchData = async () => {
|
const fetchData = async () => {
|
||||||
// const roomsResponse = await getRoom(_id);
|
console.log(_id)
|
||||||
// setRoom(roomsResponse);
|
const roomsResponse = await getRoom(_id);
|
||||||
// console.log(roomsResponse);
|
setRoom(roomsResponse);
|
||||||
// };
|
console.log(roomsResponse);
|
||||||
|
};
|
||||||
|
|
||||||
// fetchData();
|
fetchData();
|
||||||
//}, [_id]);
|
}, [_id]);
|
||||||
|
|
||||||
//useEffect(() => {
|
useEffect(() => {
|
||||||
// if (room) {
|
if (room) {
|
||||||
// form.setFieldsValue({
|
form.setFieldsValue({
|
||||||
// ...room
|
...room
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
//}, [room, form]);
|
}, [room, form]);
|
||||||
|
|
||||||
const onFinish = async (values) => {
|
const onFinish = async (values) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(
|
const response = await axios.put(
|
||||||
`${import.meta.env.VITE_API_URL}/room`,
|
`${import.meta.env.VITE_API_URL}/room/${_id}`,
|
||||||
values,
|
values,
|
||||||
);
|
);
|
||||||
console.log(response.data);
|
console.log(response.data);
|
||||||
@ -38,7 +39,7 @@ export const FormUpdateRoom = ({_id}) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form form={form} onFinish={onFinish}>
|
<Form form={form} onFinish={onFinish}>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label="Room Name"
|
label="Room Name"
|
||||||
name="name"
|
name="name"
|
||||||
|
@ -3,21 +3,21 @@ import { FormCreateRoom } from "../../components/form/formCreateRoom";
|
|||||||
import { FormUpdateRoom } from "../../components/form/formUpdateRoom";
|
import { FormUpdateRoom } from "../../components/form/formUpdateRoom";
|
||||||
|
|
||||||
export const RoomDetail = ({
|
export const RoomDetail = ({
|
||||||
selectedRoom,
|
selectedRoomParam,
|
||||||
onCreateFormSubmit,
|
onCreateFormSubmit
|
||||||
onBack,
|
|
||||||
}) => {
|
}) => {
|
||||||
const [isUpdateFormVisible, setIsUpdateFormVisible] = useState(false);
|
const [isUpdateFormVisible, setIsUpdateFormVisible] = useState(false);
|
||||||
|
const [selectedRoom, setSelectedRoom] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedRoom) {
|
if (selectedRoomParam) {
|
||||||
setIsUpdateFormVisible(true);
|
setSelectedRoom(selectedRoomParam)
|
||||||
|
setIsUpdateFormVisible(true);
|
||||||
}
|
}
|
||||||
}, [selectedRoom]);
|
}, [selectedRoomParam]);
|
||||||
|
|
||||||
const handleBackClick = () => {
|
const handleBackClick = () => {
|
||||||
setIsUpdateFormVisible(false);
|
setIsUpdateFormVisible(false);
|
||||||
onBack(null);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -25,8 +25,8 @@ export const RoomDetail = ({
|
|||||||
{isUpdateFormVisible ? (
|
{isUpdateFormVisible ? (
|
||||||
<div>
|
<div>
|
||||||
<h2>Modifier une chambre (non fonctionnel)</h2>
|
<h2>Modifier une chambre (non fonctionnel)</h2>
|
||||||
|
<button onClick={handleBackClick}>Annuler </button>
|
||||||
<FormUpdateRoom />
|
<FormUpdateRoom _id={selectedRoom} />
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div>
|
<div>
|
||||||
|
@ -7,7 +7,6 @@ import { formatRoomStats } from "../../api/room";
|
|||||||
|
|
||||||
export const RoomList = ({ statsParam, onRoomClick }) => {
|
export const RoomList = ({ statsParam, onRoomClick }) => {
|
||||||
const [rooms, setRooms] = useState([]);
|
const [rooms, setRooms] = useState([]);
|
||||||
const [selectedRoom, setSelectedRoom] = useState("all");
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (statsParam.rooms) {
|
if (statsParam.rooms) {
|
||||||
|
@ -55,7 +55,7 @@ const RoomStats = ({statsParam}) => {
|
|||||||
<p>La chambre la plus chère :</p>
|
<p>La chambre la plus chère :</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><span>{stats?.global?.most_expensive_room?.name}</span></li>
|
<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>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -30,7 +30,7 @@ export const Rooms = () => {
|
|||||||
const handleRoomClick = (roomId) => {
|
const handleRoomClick = (roomId) => {
|
||||||
console.log("Clicked room ID:", roomId);
|
console.log("Clicked room ID:", roomId);
|
||||||
setSelectedRoom(roomId);
|
setSelectedRoom(roomId);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="manContainer">
|
<div className="manContainer">
|
||||||
@ -44,8 +44,7 @@ export const Rooms = () => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="detailContainer">
|
<div className="detailContainer">
|
||||||
<RoomDetail
|
<RoomDetail
|
||||||
selectedRoom={selectedRoom}
|
selectedRoomParam={selectedRoom}
|
||||||
onBack={handleRoomClick}
|
|
||||||
></RoomDetail>
|
></RoomDetail>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user