From dc55a4da952975a3a7fb08455e01c25b7e8f9c32 Mon Sep 17 00:00:00 2001 From: Romain Mallard Date: Fri, 1 May 2026 13:07:26 +0200 Subject: [PATCH] README + cleanup --- README.md | 19 +++++++++--------- src/App.jsx | 22 +++++++-------------- src/components/MainApp.css | 2 +- src/components/auth_checking.jsx | 6 ++---- src/components/context/HotelContext.jsx | 17 +--------------- src/components/login.jsx | 24 ++--------------------- src/components/widget/RoomWidget.css | 3 --- src/components/widget/inventoryWidget.jsx | 14 ------------- src/components/widget/roomWidget.jsx | 1 - src/config.js | 4 ---- 10 files changed, 23 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index 18bc70e..de40a16 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,17 @@ -# React + Vite +# Hotel Rust API -This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules. +## Description -Currently, two official plugins are available: +Ce projet vas de pair avec mon proof of concept pour un outils interne destiné à des hotels. J'ai utiliser ce projet pour apprend et pratiquer les bases du framework ReactJs, ainsi que pour testé les fonctionnalité et l'implementation de mon API en condition réel. +(API: https://gitea.mallardromain.com/Romain/hotel_api) -- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh -- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh +## Fonctionalités -## React Compiler +- Page de connections +- Connection automatique après première identification +- Dashboard montrant les chambres/inventaire ainsi que le chat, avec des mise a jour en temps réel -The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation). +## Démo -## Expanding the ESLint configuration +Une version de ce projet est déployer à cette addresse: https://mallardromain.com/hotel-demo/ -If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project. diff --git a/src/App.jsx b/src/App.jsx index 93c3388..95ca51c 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -41,9 +41,9 @@ async function checkAuth() { "Content-Type": "application/json", "User-Agent": "react-app", }, - credentials: "include", // send cookies automatically + credentials: "include", body: JSON.stringify({ - device_id : "147ac10b-58cc-4372-a567-0e02b2c3d479", // or persistent device ID + device_id : "147ac10b-58cc-4372-a567-0e02b2c3d479", }), }); @@ -71,9 +71,9 @@ async function logoutUser() { "Content-Type": "application/json", "User-Agent": "react-app", }, - credentials: "include", // send cookies automatically + credentials: "include", body: JSON.stringify({ - device_id : "147ac10b-58cc-4372-a567-0e02b2c3d479", // or persistent device ID + device_id : "147ac10b-58cc-4372-a567-0e02b2c3d479", }), }); @@ -99,9 +99,8 @@ if (!accessTokenSingle) return; "User-Agent": "react-app", Authorization: `Bearer ${accessTokenSingle}` }, - credentials: "include", // send cookies automatically + credentials: "include", body: JSON.stringify({ - //device_id : "147ac10b-58cc-4372-a567-0e02b2c3d479", // or persistent device ID }), }); @@ -193,7 +192,7 @@ async function updatePassword(e) { "Content-Type": "application/json", "User-Agent": "react-app", }, - credentials: "include", // send cookies automatically + credentials: "include", body: JSON.stringify(payload), }); @@ -203,7 +202,7 @@ async function updatePassword(e) { } - if (loading) return

Loading...

; // can show a spinner + if (loading) return

Loading...

; return ( <> @@ -256,10 +255,3 @@ return ( ); } - - - - - - -//export default App diff --git a/src/components/MainApp.css b/src/components/MainApp.css index b04e116..45bccde 100644 --- a/src/components/MainApp.css +++ b/src/components/MainApp.css @@ -5,7 +5,7 @@ } .main > * { - min-width: 0; /* prevents overflow bugs */ + min-width: 0; } .toolbar { diff --git a/src/components/auth_checking.jsx b/src/components/auth_checking.jsx index cdba32a..6a2885e 100644 --- a/src/components/auth_checking.jsx +++ b/src/components/auth_checking.jsx @@ -19,10 +19,9 @@ export default function App() { "Content-Type": "application/json", "User-Agent": "react-app", }, - credentials: "include", // send cookies automatically + credentials: "include", body: JSON.stringify({ - device_id: crypto.randomUUID() // or a persistent device ID if you have one - }), + device_id: crypto.randomUUID() }), }); if (!res.ok) { @@ -31,7 +30,6 @@ export default function App() { } const data = await res.json(); - // store short-lived token somewhere accessible localStorage.setItem("access_token", JSON.stringify(data.tokens)); setLoggedIn(true); } catch (err) { diff --git a/src/components/context/HotelContext.jsx b/src/components/context/HotelContext.jsx index 0a72009..77f1437 100644 --- a/src/components/context/HotelContext.jsx +++ b/src/components/context/HotelContext.jsx @@ -50,10 +50,6 @@ export function HotelProvider({ accessToken, children, resClientId}) { }, body: JSON.stringify({ status }), }); - - // refresh cached rooms - //const updated = await fetchRooms(); - //setRooms(updated); } // CHAT @@ -127,10 +123,7 @@ export function HotelProvider({ accessToken, children, resClientId}) { })); return messages; - - - //return res.json - } +} async function fetchConvUsers({ conv_id }) { @@ -151,8 +144,6 @@ export function HotelProvider({ accessToken, children, resClientId}) { }); return res.json(); - - //return res.json } async function sendMessage({ conv_id, message }) { @@ -166,8 +157,6 @@ export function HotelProvider({ accessToken, children, resClientId}) { message }; - //console.log(JSON.stringify(payload)); - const res = await fetch(`${API_BASE}/chat/send_message`, { method: "POST" , headers: { @@ -258,7 +247,6 @@ export function HotelProvider({ accessToken, children, resClientId}) { } setUsersById(map); -// setUsers(users) return users; } @@ -379,7 +367,6 @@ async function addHotelUser(user_id,hotel_ids) { setConversations(convData); setUsers(usersData); SetItems(itemsData); - //getHotelList(); } @@ -396,10 +383,8 @@ async function addHotelUser(user_id,hotel_ids) { }, [conversations]); useEffect(() => { - //if (!accessTokenSingle || !clientId) return; const ws = new WebSocket( - //`ws://localhost:7080/auth/ws/${accessTokenSingle}` `wss://mallardromain.com/hotel-demo/api/auth/ws/${accessTokenSingle}` ); diff --git a/src/components/login.jsx b/src/components/login.jsx index 4c4d53f..79152f5 100644 --- a/src/components/login.jsx +++ b/src/components/login.jsx @@ -30,12 +30,7 @@ export default function Login({ onLogin }) { setError("Invalid credentials or server error."); return; } - - //const data = await res.json(); // server returns short-lived token - //localStorage.setItem("access_token", data.access_token); - - if (onLogin) await onLogin(); // notify App to show MainApp - + if (onLogin) await onLogin(); } catch (err) { console.error(err); setError("Network error."); @@ -43,11 +38,7 @@ export default function Login({ onLogin }) { } //TODO: add login button for test1 and test2 - async function LoginTest1() { - //e.preventDefault(); - //setError(""); - const device_id = "147ac10b-58cc-4372-a567-0e02b2c3d479"; let username = "test1" @@ -68,11 +59,7 @@ export default function Login({ onLogin }) { setError("Invalid credentials or server error."); return; } - - //const data = await res.json(); // server returns short-lived token - //localStorage.setItem("access_token", data.access_token); - - if (onLogin) await onLogin(); // notify App to show MainApp + if (onLogin) await onLogin(); } catch (err) { console.error(err); @@ -81,9 +68,6 @@ export default function Login({ onLogin }) { } async function LoginTest2() { - //e.preventDefault(); - //setError(""); - const device_id = "147ac10b-58cc-4372-a567-0e02b2c3d479"; let username = "test2" @@ -104,10 +88,6 @@ export default function Login({ onLogin }) { setError("Invalid credentials or server error."); return; } - - //const data = await res.json(); // server returns short-lived token - //localStorage.setItem("access_token", data.access_token); - if (onLogin) await onLogin(); // notify App to show MainApp } catch (err) { diff --git a/src/components/widget/RoomWidget.css b/src/components/widget/RoomWidget.css index 60351c1..b735b3f 100644 --- a/src/components/widget/RoomWidget.css +++ b/src/components/widget/RoomWidget.css @@ -1,6 +1,4 @@ - -/* Room grid */ .roomGrid { margin: 5px; height: 90vh; @@ -13,7 +11,6 @@ gap: 1rem; } -/* Room card */ .card { padding: 1rem; border-radius: 10px; diff --git a/src/components/widget/inventoryWidget.jsx b/src/components/widget/inventoryWidget.jsx index c209fb6..630c1b2 100644 --- a/src/components/widget/inventoryWidget.jsx +++ b/src/components/widget/inventoryWidget.jsx @@ -3,20 +3,6 @@ import {HotelProvider, useHotel} from "../context/HotelContext"; import "./inventoryWidget.css"; export default function InventoryWidget({}) { - //const { fetchHotelInventory } = useHotel(); - //const [items, setItems] = useState([]); - - /* - useEffect(() => { - async function loadInventory() { - const data = await fetchHotelInventory() - setItems(data); - } - loadInventory() - console.log ("loaded inventory") - }, []) -*/ - const { items } = useHotel(); return ( diff --git a/src/components/widget/roomWidget.jsx b/src/components/widget/roomWidget.jsx index 5db7acb..b1bfab0 100644 --- a/src/components/widget/roomWidget.jsx +++ b/src/components/widget/roomWidget.jsx @@ -75,4 +75,3 @@ function RoomCard({ number, status ,id}) { ); } -//export default roomWidget \ No newline at end of file diff --git a/src/config.js b/src/config.js index a5d1ba6..2069e1f 100644 --- a/src/config.js +++ b/src/config.js @@ -1,5 +1 @@ -//export const API_BASE = "http://localhost:7080"; - export const API_BASE = "https://mallardromain.com/hotel-demo/api"; - -//export const API_BASE = "https://79.137.75.155:5090"; \ No newline at end of file