basic conv display + fetch messages fnc
This commit is contained in:
@@ -23,20 +23,31 @@ export function HotelProvider({ accessToken, children }) {
|
|||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateRoomStatus(roomId, status) {
|
async function updateRoomStatus(roomId, status) {
|
||||||
await fetch(`${API_BASE}/rooms/clean_db_update/${roomId}`, {
|
await fetch(`${API_BASE}/rooms/clean_db_update/${roomId}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessTokenSingle}`,
|
Authorization: `Bearer ${accessTokenSingle}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ status }),
|
body: JSON.stringify({ status }),
|
||||||
});
|
});
|
||||||
|
|
||||||
// refresh cached rooms
|
// refresh cached rooms
|
||||||
const updated = await fetchRooms();
|
const updated = await fetchRooms();
|
||||||
setRooms(updated);
|
setRooms(updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchHotelUsers() {
|
||||||
|
const res = await fetch(`${API_BASE}/chat/hotel_users`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${accessTokenSingle}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return res.json();
|
||||||
|
}
|
||||||
|
|
||||||
async function fetchConversations() {
|
async function fetchConversations() {
|
||||||
const res = await fetch(`${API_BASE}/chat/get_conv`, {
|
const res = await fetch(`${API_BASE}/chat/get_conv`, {
|
||||||
@@ -53,13 +64,30 @@ async function updateRoomStatus(roomId, status) {
|
|||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchHotelUsers() {
|
async function fetchMessages({ conv_id }) {
|
||||||
const res = await fetch(`${API_BASE}/chat/hotel_users`, {
|
|
||||||
headers: { Authorization: `Bearer ${accessTokenSingle}` },
|
const payload = {
|
||||||
|
conv_id,
|
||||||
|
timestamp: "2025-09-25 11:05:33",
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(JSON.stringify(payload));
|
||||||
|
|
||||||
|
const res = await fetch(`${API_BASE}/chat/get_message`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${accessTokenSingle}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(payload),
|
||||||
});
|
});
|
||||||
return res.json();
|
|
||||||
|
return res;
|
||||||
|
|
||||||
|
//return res.json
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --- INITIAL DATA LOADING ---
|
// --- INITIAL DATA LOADING ---
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!accessToken) return;
|
if (!accessToken) return;
|
||||||
@@ -68,12 +96,12 @@ async function updateRoomStatus(roomId, status) {
|
|||||||
const [roomsData, convData, usersData] = await Promise.all([
|
const [roomsData, convData, usersData] = await Promise.all([
|
||||||
fetchRooms(),
|
fetchRooms(),
|
||||||
fetchConversations(),
|
fetchConversations(),
|
||||||
//fetchHotelUsers(),
|
fetchHotelUsers(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
setRooms(roomsData);
|
setRooms(roomsData);
|
||||||
setConversations(convData);
|
setConversations(convData);
|
||||||
//setUsers(usersData);
|
setUsers(usersData);
|
||||||
}
|
}
|
||||||
|
|
||||||
load();
|
load();
|
||||||
@@ -86,6 +114,7 @@ async function updateRoomStatus(roomId, status) {
|
|||||||
conversations,
|
conversations,
|
||||||
users,
|
users,
|
||||||
updateRoomStatus,
|
updateRoomStatus,
|
||||||
|
fetchMessages,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { HotelProvider, useHotel } from "./HotelContext";
|
import { HotelProvider, useHotel } from "./HotelContext";
|
||||||
import RoomWidget from "./widget/roomWidget"
|
import RoomWidget from "./widget/roomWidget"
|
||||||
|
import ChatWidget from "./widget/chatWidget"
|
||||||
|
|
||||||
|
import "./MainApp.css"
|
||||||
|
|
||||||
export default function MainAppWrapper() {
|
export default function MainAppWrapper() {
|
||||||
const accessToken = localStorage.getItem("access_tokens");
|
const accessToken = localStorage.getItem("access_tokens");
|
||||||
@@ -22,15 +24,15 @@ function MainApp() {
|
|||||||
|
|
||||||
<h2>Access token</h2>
|
<h2>Access token</h2>
|
||||||
<pre>{accessToken}</pre>
|
<pre>{accessToken}</pre>
|
||||||
|
<h3>Rooms: {rooms.length}</h3>
|
||||||
|
<h3>Conversations: {conversations.length}</h3>
|
||||||
|
<h3>Users: {users.length}</h3>
|
||||||
|
<h2>Dashboard</h2>
|
||||||
|
<section className="main">
|
||||||
|
|
||||||
|
<RoomWidget roomlist={rooms}/>
|
||||||
|
<ChatWidget convlist={conversations}/>
|
||||||
|
|
||||||
<section>
|
|
||||||
<h2>Dashboard</h2>
|
|
||||||
<ul>
|
|
||||||
<li>Rooms: {rooms.length}</li>
|
|
||||||
<RoomWidget roomlist={rooms}/>
|
|
||||||
<li>Conversations: {conversations.length}</li>
|
|
||||||
<li>Users: {users.length}</li>
|
|
||||||
</ul>
|
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
6
src/components/Mainapp.css
Normal file
6
src/components/Mainapp.css
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
.main {
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-around;
|
||||||
|
background-color: rgb(160, 149, 199);
|
||||||
|
}
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
.grid {
|
.grid {
|
||||||
display: grid;
|
display: flex;
|
||||||
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
justify-items: space-around;
|
||||||
gap: 1px;
|
gap: 1px;
|
||||||
background-color: #777777;
|
background-color: #777777;
|
||||||
}
|
}
|
||||||
|
|
||||||
.card {
|
.card {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-around;
|
||||||
gap: 1px;
|
gap: 1px;
|
||||||
background-color: #a3a3a3;
|
background-color: #a3a3a3;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
|
|||||||
11
src/components/widget/chatWidget.css
Normal file
11
src/components/widget/chatWidget.css
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
.convcard {
|
||||||
|
background-color: brown;
|
||||||
|
}
|
||||||
|
|
||||||
|
.convlist {
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: right;
|
||||||
|
background-color: darkcyan;
|
||||||
|
}
|
||||||
40
src/components/widget/chatWidget.jsx
Normal file
40
src/components/widget/chatWidget.jsx
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import { useHotel } from "../HotelContext";
|
||||||
|
import { useState } from "react";
|
||||||
|
|
||||||
|
//import {fetchMessage} from .
|
||||||
|
|
||||||
|
import "./chatWidget.css"
|
||||||
|
|
||||||
|
export default function ChatWidget({convlist}) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="convlist">
|
||||||
|
{convlist.map(conv => (
|
||||||
|
<ConvCard
|
||||||
|
key={conv.id}
|
||||||
|
id={conv.id}
|
||||||
|
title={conv.title}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ConvCard({id, title}) {
|
||||||
|
|
||||||
|
const {fetchMessages} = useHotel();
|
||||||
|
|
||||||
|
return(
|
||||||
|
<div className="convcard">
|
||||||
|
<h3>ConvId : {id} </h3>
|
||||||
|
<h3>Name : {title}</h3>
|
||||||
|
<p onClick={() => fetchMessages({conv_id: 4})}> GET MESSAAGE</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function MessagesBox({id}) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -19,50 +19,50 @@ export default function RoomWidget({ roomlist }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function RoomCard({ number, status ,id}) {
|
function RoomCard({ number, status ,id}) {
|
||||||
const { updateRoomStatus } = useHotel();
|
|
||||||
const [editing, setEditing] = useState(false);
|
|
||||||
const [value, SetValue] = useState(status);
|
|
||||||
|
|
||||||
|
const { updateRoomStatus } = useHotel();
|
||||||
|
const [editing, setEditing] = useState(false);
|
||||||
|
const [value, SetValue] = useState(status);
|
||||||
|
|
||||||
function submit() {
|
function submit() {
|
||||||
updateRoomStatus(id,value);
|
updateRoomStatus(id,value);
|
||||||
setEditing(false);
|
setEditing(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="card">
|
<div className="card">
|
||||||
<h3>Room {number}</h3>
|
<h3>Room {number}</h3>
|
||||||
<h4>Id {id}</h4>
|
<h4>Id {id}</h4>
|
||||||
|
|
||||||
{!editing ?(
|
{!editing ?(
|
||||||
<p onClick={() => setEditing(true)} style={{ cursor: "pointer" }}>
|
<p onClick={() => setEditing(true)} style={{ cursor: "pointer" }}>
|
||||||
Status: {status}
|
Status: {status}
|
||||||
</p>
|
</p>
|
||||||
): (
|
): (
|
||||||
<div>
|
<div>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
value={value}
|
value={value}
|
||||||
autoFocus
|
autoFocus
|
||||||
onChange={e => SetValue(e.target.value)}
|
onChange={e => SetValue(e.target.value)}
|
||||||
onKeyDown={e => e.key === "Enter" && submit()}
|
onKeyDown={e => e.key === "Enter" && submit()}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
<div className="actions">
|
<div className="actions">
|
||||||
<button onClick={() => updateRoomStatus(id, "clean")}>
|
<button onClick={() => updateRoomStatus(id, "clean")}>
|
||||||
Mark Clean
|
Mark Clean
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button onClick={() => updateRoomStatus(id, "dirty")}>
|
<button onClick={() => updateRoomStatus(id, "dirty")}>
|
||||||
Mark Dirty
|
Mark Dirty
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//export default roomWidget
|
//export default roomWidget
|
||||||
Reference in New Issue
Block a user