@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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pubuduth-aplicy/chat-ui",
3
- "version": "2.1.80",
3
+ "version": "2.1.81",
4
4
  "description": "This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.",
5
5
  "license": "ISC",
6
6
  "author": "",
@@ -13,7 +13,10 @@ import { useEffect, useRef, useState } from "react";
13
13
  interface MessageProps {
14
14
  message: {
15
15
  _id?: string;
16
- senderId: string;
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>{message.meta?.bookingDetails?.status || 'Unknown'}</h4>
91
+ <h4>{status}</h4>
57
92
  <div className="details">
58
- <p>Service: {message.meta?.bookingDetails?.serviceId}</p>
59
- <p>Date: {message.meta?.bookingDetails?.date}</p>
60
- <p>Time: {message.meta?.bookingDetails?.time}</p>
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
- <button
64
- className="confirm-button"
65
- onClick={() => {
66
- // Add your confirmation logic here
67
- console.log('Booking confirmed!');
68
- }}
69
- >
70
- Confirm Booking
71
- <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
72
- <path d="M12.736 3.97a.733.733 0 0 1 1.047 0c.286.289.29.756.01 1.05L7.88 12.01a.733.733 0 0 1-1.065.02L3.217 8.384a.757.757 0 0 1 0-1.06.733.733 0 0 1 1.047 0l3.052 3.093 5.4-6.425a.247.247 0 0 1 .02-.022Z" />
73
- </svg>
74
- </button>
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
- senderId: userId,
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) => ({
@@ -61,7 +61,7 @@ const Messages = () => {
61
61
  (msg) =>
62
62
  msg._id === newMessage._id ||
63
63
  (msg.isOptimistic &&
64
- msg.senderId === userId &&
64
+ msg.sender.senderId === userId &&
65
65
  msg.message === newMessage.message)
66
66
  );
67
67
 
@@ -26,7 +26,10 @@ interface ChatUIState {
26
26
  messages: {
27
27
  _id: string;
28
28
  text: string;
29
- senderId: string;
29
+ sender: {
30
+ senderId: string;
31
+ role: string;
32
+ };
30
33
  status: string;
31
34
  isOptimistic: boolean;
32
35
  message: string;