@pubuduth-aplicy/chat-ui 2.1.80 → 2.1.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -13,7 +13,10 @@ import { useEffect, useRef, useState } from "react";
|
|
|
13
13
|
interface MessageProps {
|
|
14
14
|
message: {
|
|
15
15
|
_id?: string;
|
|
16
|
-
|
|
16
|
+
sender: {
|
|
17
|
+
senderId: string;
|
|
18
|
+
role: string;
|
|
19
|
+
};
|
|
17
20
|
message: string;
|
|
18
21
|
status: MessageStatus;
|
|
19
22
|
createdAt: any;
|
|
@@ -48,30 +51,74 @@ interface MessageProps {
|
|
|
48
51
|
|
|
49
52
|
const Message = ({ message }: MessageProps) => {
|
|
50
53
|
const { userId } = useChatContext();
|
|
51
|
-
const { apiUrl,cdnUrl } = getChatConfig();
|
|
54
|
+
const { apiUrl,cdnUrl ,role: role1} = getChatConfig();
|
|
52
55
|
|
|
53
56
|
if (message.type === "system") {
|
|
57
|
+
const booking = message.meta?.bookingDetails;
|
|
58
|
+
const status = booking?.status || "Pending"; // Default to Pending
|
|
59
|
+
const role = role1; // "provider" or "customer"
|
|
60
|
+
|
|
61
|
+
const handleConfirm = () => {
|
|
62
|
+
console.log("Booking confirmed!");
|
|
63
|
+
window.location.href = `/booking/all`;
|
|
64
|
+
// Update booking status to Confirmed
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const handleInProgress = () => {
|
|
68
|
+
console.log("Booking started (In Progress)");
|
|
69
|
+
window.location.href = `/booking/all`;
|
|
70
|
+
// Update booking status to InProgress
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const handleComplete = () => {
|
|
74
|
+
console.log("Booking completed!");
|
|
75
|
+
window.location.href = `/booking/all`;
|
|
76
|
+
// Update booking status to Completed
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const handleReview = () => {
|
|
80
|
+
if (role === "customer") {
|
|
81
|
+
console.log("Navigate to review page for customer → provider");
|
|
82
|
+
window.location.href = `/customer/customer-reviews`;
|
|
83
|
+
} else if (role === "provider") {
|
|
84
|
+
console.log("Navigate to review page for provider → customer");
|
|
85
|
+
window.location.href = `/booking/all`;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
54
89
|
return (
|
|
55
90
|
<div className="system-message booking-details">
|
|
56
|
-
<h4>{
|
|
91
|
+
<h4>{status}</h4>
|
|
57
92
|
<div className="details">
|
|
58
|
-
<p>Service: {
|
|
59
|
-
<p>Date: {
|
|
60
|
-
<p>Time: {
|
|
61
|
-
<p>Price: ${message.meta?.bookingDetails?.price}</p>
|
|
93
|
+
<p>Service: {booking?.serviceId}</p>
|
|
94
|
+
<p>Date: {booking?.date}</p>
|
|
95
|
+
<p>Time: {booking?.time}</p>
|
|
62
96
|
</div>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
97
|
+
|
|
98
|
+
{/* Actions based on role + status */}
|
|
99
|
+
{role === "provider" && status === "Pending" && (
|
|
100
|
+
<button className="confirm-button" onClick={handleConfirm}>
|
|
101
|
+
Confirm Booking ✅
|
|
102
|
+
</button>
|
|
103
|
+
)}
|
|
104
|
+
|
|
105
|
+
{role === "provider" && status === "Confirmed" && (
|
|
106
|
+
<button className="confirm-button" onClick={handleInProgress}>
|
|
107
|
+
Start Service ▶️
|
|
108
|
+
</button>
|
|
109
|
+
)}
|
|
110
|
+
|
|
111
|
+
{role === "provider" && status === "InProgress" && (
|
|
112
|
+
<button className="confirm-button" onClick={handleComplete}>
|
|
113
|
+
Mark as Completed ✔️
|
|
114
|
+
</button>
|
|
115
|
+
)}
|
|
116
|
+
|
|
117
|
+
{status === "Completed" && (
|
|
118
|
+
<button className="confirm-button" onClick={handleReview}>
|
|
119
|
+
Leave a Review ✍️
|
|
120
|
+
</button>
|
|
121
|
+
)}
|
|
75
122
|
</div>
|
|
76
123
|
);
|
|
77
124
|
}
|
|
@@ -92,7 +139,7 @@ const Message = ({ message }: MessageProps) => {
|
|
|
92
139
|
);
|
|
93
140
|
}
|
|
94
141
|
|
|
95
|
-
const fromMe = message.senderId === userId;
|
|
142
|
+
const fromMe = message.sender?.senderId === userId;
|
|
96
143
|
const timestamp = fromMe ? "timestamp_outgoing" : "timestamp_incomeing";
|
|
97
144
|
const alignItems = fromMe ? "outgoing" : "incoming";
|
|
98
145
|
const [localStatus, setLocalStatus] = useState(message.status);
|
|
@@ -258,7 +258,10 @@ const MessageInput = () => {
|
|
|
258
258
|
_id: tempId,
|
|
259
259
|
text: message1,
|
|
260
260
|
message: message1,
|
|
261
|
-
|
|
261
|
+
sender: {
|
|
262
|
+
senderId: userId,
|
|
263
|
+
role: role,
|
|
264
|
+
},
|
|
262
265
|
status: "pending" as MessageStatus,
|
|
263
266
|
createdAt: new Date().toISOString(),
|
|
264
267
|
media: attachmentsRef.current.map((att) => ({
|