@pubuduth-aplicy/chat-ui 2.2.4 → 2.2.6

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.2.4",
3
+ "version": "2.2.6",
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": "",
@@ -17,7 +17,7 @@ export const Chat = () => {
17
17
  const parsed = JSON.parse(event.data);
18
18
 
19
19
  if (parsed.event === "newMessage") {
20
- const message = parsed.data;
20
+ const message = parsed.data.data;
21
21
  // Send delivery confirmation
22
22
  // Update UI immediately
23
23
  setMessages((prev) => [...prev, message]);
@@ -35,8 +35,7 @@ const CollapsibleSection = ({
35
35
  />
36
36
  </div>
37
37
  {isOpen && (
38
- <div className="p-2 text-gray-900 dark:text-gray-200"
39
- style={{height:"400px"}}>{children}</div>
38
+ <div className="p-2 text-gray-900 dark:text-gray-200">{children}</div>
40
39
  )}
41
40
  </div>
42
41
  );
@@ -23,7 +23,7 @@ const VirtualizedChatList = ({ conversations }: Props) => {
23
23
  <div
24
24
  ref={parentRef}
25
25
  style={{
26
- height: `400px`,
26
+ // height: `400px`,
27
27
  width: "100%",
28
28
  // position: "relative",
29
29
  overflow: "auto",
@@ -37,6 +37,7 @@ interface MessageProps {
37
37
  type?: "user" | "system" | "system-completion";
38
38
  meta?: {
39
39
  bookingDetails?: {
40
+ bookingId: string;
40
41
  status: string; // e.g., "confirmed", "pending", "cancelled"
41
42
  serviceId: string;
42
43
  date: string;
@@ -60,19 +61,19 @@ const Message = ({ message }: MessageProps) => {
60
61
 
61
62
  const handleConfirm = () => {
62
63
  console.log("Booking confirmed!");
63
- window.location.href = `/booking/all`;
64
+ window.location.href = `/booking/all#${message.meta?.bookingDetails?.bookingId}`;
64
65
  // Update booking status to Confirmed
65
66
  };
66
67
 
67
68
  const handleInProgress = () => {
68
69
  console.log("Booking started (In Progress)");
69
- window.location.href = `/booking/all`;
70
+ window.location.href = `/booking/all#${message.meta?.bookingDetails?.bookingId}`;
70
71
  // Update booking status to InProgress
71
72
  };
72
73
 
73
74
  const handleComplete = () => {
74
75
  console.log("Booking completed!");
75
- window.location.href = `/booking/all`;
76
+ window.location.href = `/booking/all#${message.meta?.bookingDetails?.bookingId}`;
76
77
  // Update booking status to Completed
77
78
  };
78
79
 
@@ -82,7 +83,7 @@ const Message = ({ message }: MessageProps) => {
82
83
  window.location.href = `/customer/customer-reviews`;
83
84
  } else if (role === "provider") {
84
85
  console.log("Navigate to review page for provider → customer");
85
- window.location.href = `/booking/all`;
86
+ window.location.href = `/booking/all#${message.meta?.bookingDetails?.bookingId}`;
86
87
  }
87
88
  };
88
89
 
@@ -544,6 +545,40 @@ const Message = ({ message }: MessageProps) => {
544
545
  return now.getTime() - messageDate.getTime() > oneDayInMs;
545
546
  };
546
547
 
548
+ const formatLastMessageTime = (dateString: string) => {
549
+ const date = new Date(dateString);
550
+ const now = new Date();
551
+
552
+ const isToday = date.toDateString() === now.toDateString();
553
+
554
+ const yesterday = new Date();
555
+ yesterday.setDate(now.getDate() - 1);
556
+
557
+ const isYesterday = date.toDateString() === yesterday.toDateString();
558
+
559
+ if (isToday) {
560
+ return date.toLocaleTimeString([], {
561
+ hour: "2-digit",
562
+ minute: "2-digit",
563
+ });
564
+ }
565
+
566
+ if (isYesterday) {
567
+ return "Yesterday";
568
+ }
569
+
570
+ // MM/DD format
571
+ return date.toLocaleDateString("en-US", {
572
+ month: "2-digit",
573
+ day: "2-digit",
574
+ });
575
+ };
576
+
577
+ const messageTime =
578
+ message.status === "deleted" || message.status === "edited"
579
+ ? message.updatedAt
580
+ : message.createdAt;
581
+
547
582
  const hasMedia = message.media && message.media.length > 0;
548
583
 
549
584
  return (
@@ -641,23 +676,7 @@ const Message = ({ message }: MessageProps) => {
641
676
  )
642
677
  )}
643
678
  <div className={`${timestamp}`}>
644
- {message.status === "deleted"
645
- ? // Show deleted timestamp if message is deleted
646
- new Date(message.updatedAt).toLocaleTimeString([], {
647
- hour: "2-digit",
648
- minute: "2-digit",
649
- })
650
- : message.status === "edited"
651
- ? // Show updated timestamp if message was edited
652
- new Date(message.updatedAt).toLocaleTimeString([], {
653
- hour: "2-digit",
654
- minute: "2-digit",
655
- })
656
- : // Default to created timestamp
657
- new Date(message.createdAt).toLocaleTimeString([], {
658
- hour: "2-digit",
659
- minute: "2-digit",
660
- })}
679
+ {formatLastMessageTime(messageTime)}
661
680
  <span className="status-icon">{getStatusIcon()}</span>
662
681
  </div>
663
682
  </div>
@@ -8,19 +8,16 @@ import { getChatConfig } from "../../Chat.config";
8
8
  import defaultProfilePicture from "../../assets/pngegg.png";
9
9
 
10
10
  const Conversation = ({ conversation }: ConversationProps) => {
11
- const {
12
- setSelectedConversation,
13
- setOnlineUsers,
14
- } = useChatUIStore();
15
- const { socket, isUserOnline, } = useChatContext();
11
+ const { setSelectedConversation, setOnlineUsers } = useChatUIStore();
12
+ const { socket, isUserOnline } = useChatContext();
16
13
  const selectedConversation = useChatUIStore(
17
14
  (state) => state.selectedConversation
18
15
  );
19
16
  const { userId } = useChatContext();
20
- const { role } = getChatConfig();
17
+ const { role } = getChatConfig();
21
18
 
22
19
  const participant = conversation.participantDetails?.find(
23
- (p:any) => p._id !== userId
20
+ (p: any) => p._id !== userId
24
21
  );
25
22
 
26
23
  const handleSelectConversation = () => {
@@ -81,12 +78,40 @@ const Conversation = ({ conversation }: ConversationProps) => {
81
78
  ? `Booking #${conversation.bookingId}`
82
79
  : participant?.name || "Conversation";
83
80
 
84
- const lastMessageTimestamp = new Date(
85
- conversation.lastMessage?.updatedAt || conversation.lastMessage?.createdAt || conversation.createdAt
86
- ).toLocaleTimeString([], {
87
- hour: "2-digit",
88
- minute: "2-digit",
89
- });
81
+ const formatLastMessageTime = (dateString: string) => {
82
+ const date = new Date(dateString);
83
+ const now = new Date();
84
+
85
+ const isToday = date.toDateString() === now.toDateString();
86
+
87
+ const yesterday = new Date();
88
+ yesterday.setDate(now.getDate() - 1);
89
+
90
+ const isYesterday = date.toDateString() === yesterday.toDateString();
91
+
92
+ if (isToday) {
93
+ return date.toLocaleTimeString([], {
94
+ hour: "2-digit",
95
+ minute: "2-digit",
96
+ });
97
+ }
98
+
99
+ if (isYesterday) {
100
+ return "Yesterday";
101
+ }
102
+
103
+ // MM/DD format
104
+ return date.toLocaleDateString("en-US", {
105
+ month: "2-digit",
106
+ day: "2-digit",
107
+ });
108
+ };
109
+
110
+ const lastMessageTimestamp = formatLastMessageTime(
111
+ conversation.lastMessage?.updatedAt ||
112
+ conversation.lastMessage?.createdAt ||
113
+ conversation.createdAt
114
+ );
90
115
 
91
116
  return (
92
117
  <div
@@ -104,7 +129,11 @@ const Conversation = ({ conversation }: ConversationProps) => {
104
129
  <>
105
130
  <img
106
131
  className="w-10 h-10 rounded-full"
107
- src={participant?.profilePicture ? participant?.profilePicture: defaultProfilePicture}
132
+ src={
133
+ participant?.profilePicture
134
+ ? participant?.profilePicture
135
+ : defaultProfilePicture
136
+ }
108
137
  alt="User Avatar"
109
138
  />
110
139
  <span
@@ -121,7 +150,7 @@ const Conversation = ({ conversation }: ConversationProps) => {
121
150
  </p>
122
151
  <div className="flex items-center gap-2">
123
152
  {unreadCount > 0 && (
124
- <span className="background text-white text-xs rounded-full h-5 w-5 flex items-center justify-center">
153
+ <span className="background text-white text-xs rounded-full h-5 w-5 flex items-center justify-center">
125
154
  {unreadCount}
126
155
  </span>
127
156
  )}