diff --git a/src/components/HotelContext.jsx b/src/components/HotelContext.jsx index c3c2f07..5a1fb65 100644 --- a/src/components/HotelContext.jsx +++ b/src/components/HotelContext.jsx @@ -82,7 +82,7 @@ export function HotelProvider({ accessToken, children }) { body: JSON.stringify(payload), }); - return res; + return res.json(); //return res.json } diff --git a/src/components/widget/chatWidget.css b/src/components/widget/chatWidget.css index d7acf47..5e95db3 100644 --- a/src/components/widget/chatWidget.css +++ b/src/components/widget/chatWidget.css @@ -1,3 +1,8 @@ +.chatWidget{ + display: flex; + flex-direction: column; +} + .convcard { background-color: brown; } @@ -5,7 +10,7 @@ .convlist { display: flex; - flex-direction: column; + flex-direction: row; align-items: right; background-color: darkcyan; } \ No newline at end of file diff --git a/src/components/widget/chatWidget.jsx b/src/components/widget/chatWidget.jsx index 20d1d4a..7688a99 100644 --- a/src/components/widget/chatWidget.jsx +++ b/src/components/widget/chatWidget.jsx @@ -6,35 +6,59 @@ import { useState } from "react"; import "./chatWidget.css" export default function ChatWidget({convlist}) { + const [messages, setMessages] = useState([]); + const { fetchMessages } = useHotel(); + const handleOpenConv = async (conv_id) => { + const msg = await fetchMessages({ conv_id }); + setMessages(msg); + }; return ( -
- {convlist.map(conv => ( - - ))} +
+
+ {convlist.map(conv => ( + + ))} +
+ +
); } -function ConvCard({id, title}) { - - const {fetchMessages} = useHotel(); - +function ConvCard({id, title, onOpenConv}) { return( -
-

ConvId : {id}

-

Name : {title}

-

fetchMessages({conv_id: 4})}> GET MESSAAGE

-
+
+

ConvId : {id}

+

Name : {title}

+

onOpenConv(id)}> GET MESSAAGE

+
) } -function MessagesBox({id}) { - +function MessagesBox({ messages }) { + if (!messages || messages.length === 0) { + return
No messages
+ } + console.log("FETCH RESULT =", messages); + return ( + +
+ {messages.map(msg => ( +
+

Sender: {msg.sender_id}

+

{msg.content}

+ {msg.sent_at} +
+ ))} +
+ + ); } \ No newline at end of file