README + cleanup
All checks were successful
Deploy React / build-and-deploy (push) Successful in 18s

This commit is contained in:
2026-05-01 13:07:26 +02:00
parent 5bcf3e673e
commit dc55a4da95
10 changed files with 23 additions and 89 deletions

View File

@@ -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 ## Fonctionalités
- [@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
## 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.

View File

@@ -41,9 +41,9 @@ async function checkAuth() {
"Content-Type": "application/json", "Content-Type": "application/json",
"User-Agent": "react-app", "User-Agent": "react-app",
}, },
credentials: "include", // send cookies automatically credentials: "include",
body: JSON.stringify({ 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", "Content-Type": "application/json",
"User-Agent": "react-app", "User-Agent": "react-app",
}, },
credentials: "include", // send cookies automatically credentials: "include",
body: JSON.stringify({ 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", "User-Agent": "react-app",
Authorization: `Bearer ${accessTokenSingle}` Authorization: `Bearer ${accessTokenSingle}`
}, },
credentials: "include", // send cookies automatically credentials: "include",
body: JSON.stringify({ 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", "Content-Type": "application/json",
"User-Agent": "react-app", "User-Agent": "react-app",
}, },
credentials: "include", // send cookies automatically credentials: "include",
body: JSON.stringify(payload), body: JSON.stringify(payload),
}); });
@@ -203,7 +202,7 @@ async function updatePassword(e) {
} }
if (loading) return <p>Loading...</p>; // can show a spinner if (loading) return <p>Loading...</p>;
return ( return (
<> <>
@@ -256,10 +255,3 @@ return (
</> </>
); );
} }
//export default App

View File

@@ -5,7 +5,7 @@
} }
.main > * { .main > * {
min-width: 0; /* prevents overflow bugs */ min-width: 0;
} }
.toolbar { .toolbar {

View File

@@ -19,10 +19,9 @@ export default function App() {
"Content-Type": "application/json", "Content-Type": "application/json",
"User-Agent": "react-app", "User-Agent": "react-app",
}, },
credentials: "include", // send cookies automatically credentials: "include",
body: JSON.stringify({ body: JSON.stringify({
device_id: crypto.randomUUID() // or a persistent device ID if you have one device_id: crypto.randomUUID() }),
}),
}); });
if (!res.ok) { if (!res.ok) {
@@ -31,7 +30,6 @@ export default function App() {
} }
const data = await res.json(); const data = await res.json();
// store short-lived token somewhere accessible
localStorage.setItem("access_token", JSON.stringify(data.tokens)); localStorage.setItem("access_token", JSON.stringify(data.tokens));
setLoggedIn(true); setLoggedIn(true);
} catch (err) { } catch (err) {

View File

@@ -50,10 +50,6 @@ export function HotelProvider({ accessToken, children, resClientId}) {
}, },
body: JSON.stringify({ status }), body: JSON.stringify({ status }),
}); });
// refresh cached rooms
//const updated = await fetchRooms();
//setRooms(updated);
} }
// CHAT // CHAT
@@ -127,9 +123,6 @@ export function HotelProvider({ accessToken, children, resClientId}) {
})); }));
return messages; return messages;
//return res.json
} }
async function fetchConvUsers({ conv_id }) { async function fetchConvUsers({ conv_id }) {
@@ -151,8 +144,6 @@ export function HotelProvider({ accessToken, children, resClientId}) {
}); });
return res.json(); return res.json();
//return res.json
} }
async function sendMessage({ conv_id, message }) { async function sendMessage({ conv_id, message }) {
@@ -166,8 +157,6 @@ export function HotelProvider({ accessToken, children, resClientId}) {
message message
}; };
//console.log(JSON.stringify(payload));
const res = await fetch(`${API_BASE}/chat/send_message`, { const res = await fetch(`${API_BASE}/chat/send_message`, {
method: "POST" , method: "POST" ,
headers: { headers: {
@@ -258,7 +247,6 @@ export function HotelProvider({ accessToken, children, resClientId}) {
} }
setUsersById(map); setUsersById(map);
// setUsers(users)
return users; return users;
} }
@@ -379,7 +367,6 @@ async function addHotelUser(user_id,hotel_ids) {
setConversations(convData); setConversations(convData);
setUsers(usersData); setUsers(usersData);
SetItems(itemsData); SetItems(itemsData);
//getHotelList();
} }
@@ -396,10 +383,8 @@ async function addHotelUser(user_id,hotel_ids) {
}, [conversations]); }, [conversations]);
useEffect(() => { useEffect(() => {
//if (!accessTokenSingle || !clientId) return;
const ws = new WebSocket( const ws = new WebSocket(
//`ws://localhost:7080/auth/ws/${accessTokenSingle}`
`wss://mallardromain.com/hotel-demo/api/auth/ws/${accessTokenSingle}` `wss://mallardromain.com/hotel-demo/api/auth/ws/${accessTokenSingle}`
); );

View File

@@ -30,12 +30,7 @@ export default function Login({ onLogin }) {
setError("Invalid credentials or server error."); setError("Invalid credentials or server error.");
return; return;
} }
if (onLogin) await onLogin();
//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) { } catch (err) {
console.error(err); console.error(err);
setError("Network error."); setError("Network error.");
@@ -43,11 +38,7 @@ export default function Login({ onLogin }) {
} }
//TODO: add login button for test1 and test2 //TODO: add login button for test1 and test2
async function LoginTest1() { async function LoginTest1() {
//e.preventDefault();
//setError("");
const device_id = "147ac10b-58cc-4372-a567-0e02b2c3d479"; const device_id = "147ac10b-58cc-4372-a567-0e02b2c3d479";
let username = "test1" let username = "test1"
@@ -68,11 +59,7 @@ export default function Login({ onLogin }) {
setError("Invalid credentials or server error."); setError("Invalid credentials or server error.");
return; return;
} }
if (onLogin) await onLogin();
//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) { } catch (err) {
console.error(err); console.error(err);
@@ -81,9 +68,6 @@ export default function Login({ onLogin }) {
} }
async function LoginTest2() { async function LoginTest2() {
//e.preventDefault();
//setError("");
const device_id = "147ac10b-58cc-4372-a567-0e02b2c3d479"; const device_id = "147ac10b-58cc-4372-a567-0e02b2c3d479";
let username = "test2" let username = "test2"
@@ -104,10 +88,6 @@ export default function Login({ onLogin }) {
setError("Invalid credentials or server error."); setError("Invalid credentials or server error.");
return; 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(); // notify App to show MainApp
} catch (err) { } catch (err) {

View File

@@ -1,6 +1,4 @@
/* Room grid */
.roomGrid { .roomGrid {
margin: 5px; margin: 5px;
height: 90vh; height: 90vh;
@@ -13,7 +11,6 @@
gap: 1rem; gap: 1rem;
} }
/* Room card */
.card { .card {
padding: 1rem; padding: 1rem;
border-radius: 10px; border-radius: 10px;

View File

@@ -3,20 +3,6 @@ import {HotelProvider, useHotel} from "../context/HotelContext";
import "./inventoryWidget.css"; import "./inventoryWidget.css";
export default function InventoryWidget({}) { 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(); const { items } = useHotel();
return ( return (

View File

@@ -75,4 +75,3 @@ function RoomCard({ number, status ,id}) {
); );
} }
//export default roomWidget

View File

@@ -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://mallardromain.com/hotel-demo/api";
//export const API_BASE = "https://79.137.75.155:5090";