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",
"\\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
} }

Binary file not shown.

View File

@ -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 {

View File

@ -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);

View File

@ -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) {
setSelectedRoom(selectedRoomParam)
setIsUpdateFormVisible(true); 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>

View File

@ -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) {

View File

@ -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>

View File

@ -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>