@messenger-box/tailwind-ui-inbox 10.0.3-alpha.67 → 10.0.3-alpha.70

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.
Files changed (53) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lib/components/InboxMessage/ConversationItem.d.ts +10 -7
  3. package/lib/components/InboxMessage/ConversationItem.d.ts.map +1 -1
  4. package/lib/components/InboxMessage/ConversationItem.js +58 -77
  5. package/lib/components/InboxMessage/ConversationItem.js.map +1 -1
  6. package/lib/components/InboxMessage/LeftSidebar.d.ts +2 -1
  7. package/lib/components/InboxMessage/LeftSidebar.d.ts.map +1 -1
  8. package/lib/components/InboxMessage/LeftSidebar.js +15 -8
  9. package/lib/components/InboxMessage/LeftSidebar.js.map +1 -1
  10. package/lib/components/InboxMessage/MessageInput.d.ts.map +1 -1
  11. package/lib/components/InboxMessage/MessageInput.js +15 -1
  12. package/lib/components/InboxMessage/MessageInput.js.map +1 -1
  13. package/lib/components/InboxMessage/Messages.d.ts.map +1 -1
  14. package/lib/components/InboxMessage/Messages.js +48 -13
  15. package/lib/components/InboxMessage/Messages.js.map +1 -1
  16. package/lib/components/InboxMessage/SubscriptionHandler.d.ts +19 -0
  17. package/lib/components/InboxMessage/SubscriptionHandler.d.ts.map +1 -0
  18. package/lib/components/InboxMessage/SubscriptionHandler.js +41 -0
  19. package/lib/components/InboxMessage/SubscriptionHandler.js.map +1 -0
  20. package/lib/components/InboxMessage/message-widgets/SlackLikeMessageGroup.d.ts +12 -0
  21. package/lib/components/InboxMessage/message-widgets/SlackLikeMessageGroup.d.ts.map +1 -0
  22. package/lib/components/InboxMessage/message-widgets/SlackLikeMessageGroup.js +134 -0
  23. package/lib/components/InboxMessage/message-widgets/SlackLikeMessageGroup.js.map +1 -0
  24. package/lib/components/InboxMessage/message-widgets/index.d.ts +1 -0
  25. package/lib/components/InboxMessage/message-widgets/index.d.ts.map +1 -1
  26. package/lib/components/slot-fill/chat-message-filler.js +1 -1
  27. package/lib/components/slot-fill/chat-message-filler.js.map +1 -1
  28. package/lib/container/Inbox.d.ts.map +1 -1
  29. package/lib/container/Inbox.js +188 -60
  30. package/lib/container/Inbox.js.map +1 -1
  31. package/lib/container/InboxWithLoader.d.ts +10 -3
  32. package/lib/container/InboxWithLoader.d.ts.map +1 -1
  33. package/lib/container/InboxWithLoader.js +81 -30
  34. package/lib/container/InboxWithLoader.js.map +1 -1
  35. package/lib/container/ServiceInbox.js +1 -1
  36. package/lib/container/ServiceInbox.js.map +1 -1
  37. package/lib/container/ThreadMessages.js +1 -1
  38. package/lib/container/ThreadMessages.js.map +1 -1
  39. package/lib/container/ThreadMessagesInbox.js +1 -1
  40. package/lib/container/ThreadMessagesInbox.js.map +1 -1
  41. package/lib/container/Threads.js +1 -1
  42. package/lib/container/Threads.js.map +1 -1
  43. package/lib/index.js +1 -1
  44. package/package.json +4 -4
  45. package/src/components/InboxMessage/ConversationItem.tsx +188 -186
  46. package/src/components/InboxMessage/LeftSidebar.tsx +20 -11
  47. package/src/components/InboxMessage/MessageInput.tsx +16 -1
  48. package/src/components/InboxMessage/Messages.tsx +48 -11
  49. package/src/components/InboxMessage/SubscriptionHandler.tsx +55 -0
  50. package/src/components/InboxMessage/message-widgets/SlackLikeMessageGroup.tsx +208 -0
  51. package/src/components/InboxMessage/message-widgets/index.ts +1 -0
  52. package/src/container/Inbox.tsx +194 -66
  53. package/src/container/InboxWithLoader.tsx +104 -38
@@ -1,23 +1,38 @@
1
- import React, { useMemo } from 'react';
1
+ import React, { useMemo, useCallback } from 'react';
2
2
  import { useParams, useLocation } from '@remix-run/react';
3
3
 
4
4
  // import AddGovernmentId from './AddGovernmentId';
5
5
  import Inbox from './Inbox';
6
- import { useGetChannelsByUserQuery, useMessagesQuery, useViewChannelDetailQuery } from 'common/graphql';
6
+ import {
7
+ useGetChannelsByUserQuery,
8
+ useGetChannelsByUserWithLastMessageQuery,
9
+ useMessagesQuery,
10
+ useViewChannelDetailQuery,
11
+ } from 'common/graphql';
7
12
  import { RoomType } from 'common';
8
13
  import { config } from '../config';
9
14
 
10
15
  const { MESSAGES_PER_PAGE } = config;
11
16
 
12
- // Static utility function moved outside component - exported for external use
13
- export const queryParamsGenerator = (params) => ({
17
+ // Enhanced query parameters generator with better typing and flexibility
18
+ export const queryParamsGenerator = (params: {
19
+ role?: string;
20
+ criteria?: Record<string, any>;
21
+ supportServices?: boolean;
22
+ orgName?: string;
23
+ }) => ({
14
24
  variable1: {
15
25
  role: params.role,
16
- criteria: params.criteria,
17
- supportServices: params.supportServices ? true : false,
18
- supportServiceCriteria: {
19
- type: RoomType.Service,
26
+ criteria: {
27
+ ...params.criteria,
28
+ ...(params.orgName && { orgName: params.orgName }),
20
29
  },
30
+ supportServices: params.supportServices ? true : false,
31
+ supportServiceCriteria: params.supportServices
32
+ ? {
33
+ type: RoomType.Service,
34
+ }
35
+ : undefined,
21
36
  orderBy: {
22
37
  lastPostAt: 'desc',
23
38
  },
@@ -172,28 +187,35 @@ const InboxWithLoader = (props: InboxWithLoaderProps) => {
172
187
  const { channelFilters: channelFilterProp, channelRole: channelRoleProp, supportServices, pathPrefix } = props;
173
188
  const { orgName, channelRole: channelRoleParam } = useParams();
174
189
  const channelRole = channelRoleParam || channelRoleProp;
175
- // Get full location info
190
+
176
191
  // Create new props object with orgName instead of mutating original props
177
- const inboxProps = {
178
- ...props,
179
- orgName: orgName || '',
180
- pathPrefix: pathPrefix || '',
181
- };
192
+ const inboxProps = useMemo(
193
+ () => ({
194
+ ...props,
195
+ orgName: orgName || '',
196
+ pathPrefix: pathPrefix || '',
197
+ }),
198
+ [props, orgName, pathPrefix],
199
+ );
182
200
 
183
201
  const { id: pathChannelId } = useParams();
184
202
 
185
- // Optimized query variables with stable references
186
- const channelsQueryVariables = useMemo(
187
- () =>
188
- queryParamsGenerator({
189
- role: channelRole,
190
- criteria: orgName
191
- ? { ...channelFilterProp, orgName: channelFilterProp?.orgName || orgName || '' }
192
- : channelFilterProp,
193
- supportServices,
194
- }).variable1,
195
- [channelRole, channelFilterProp, supportServices, orgName],
196
- );
203
+ // Enhanced query variables with better filtering and stable references
204
+ const channelsQueryVariables = useMemo(() => {
205
+ const channelFilters = { ...channelFilterProp };
206
+ const channelType = channelFilters?.type ?? RoomType.Direct;
207
+ const baseFilters = {
208
+ ...channelFilters,
209
+ type: supportServices ? [channelType, RoomType.Service] : channelType,
210
+ };
211
+
212
+ return queryParamsGenerator({
213
+ role: channelRole,
214
+ criteria: baseFilters,
215
+ supportServices,
216
+ orgName: orgName || '',
217
+ }).variable1;
218
+ }, [channelRole, channelFilterProp, supportServices, orgName]);
197
219
 
198
220
  const messagesQueryVariables = useMemo(
199
221
  () => ({
@@ -211,43 +233,67 @@ const InboxWithLoader = (props: InboxWithLoaderProps) => {
211
233
  [pathChannelId],
212
234
  );
213
235
 
214
- // Apollo queries with optimized cache policies
236
+ // Enhanced Apollo queries with better cache policies and error handling
215
237
  const channelsQuery = useGetChannelsByUserQuery({
216
238
  variables: channelsQueryVariables,
217
- fetchPolicy: 'cache-first',
239
+ fetchPolicy: 'cache-and-network', // Better for real-time updates
218
240
  errorPolicy: 'all',
219
- notifyOnNetworkStatusChange: true,
220
- // Enable optimistic updates and real-time subscriptions
241
+ notifyOnNetworkStatusChange: false,
221
242
  returnPartialData: true,
243
+ // Add context for better cache management
244
+ context: {
245
+ cacheKey: 'channels-list',
246
+ },
222
247
  });
223
248
 
224
249
  const messagesQuery = useMessagesQuery({
225
250
  variables: messagesQueryVariables,
226
251
  skip: !pathChannelId,
227
- fetchPolicy: 'cache-and-network', // Changed to cache-and-network for better UX
252
+ fetchPolicy: 'cache-and-network', // Better for real-time messaging
228
253
  errorPolicy: 'all',
229
254
  notifyOnNetworkStatusChange: true,
230
255
  returnPartialData: true,
231
- // Enable polling for real-time updates as fallback
232
- pollInterval: process.env.NODE_ENV === 'development' ? 0 : 30000,
256
+ // Disable polling to allow subscriptions to work properly
257
+ pollInterval: 0,
258
+ // Add context for better cache management
259
+ context: {
260
+ cacheKey: 'messages-list',
261
+ },
233
262
  });
234
263
 
235
264
  const channelDetailQuery = useViewChannelDetailQuery({
236
265
  variables: channelDetailQueryVariables,
237
266
  skip: !pathChannelId,
238
- fetchPolicy: 'cache-first',
267
+ fetchPolicy: 'cache-first', // Channel details don't change often
239
268
  errorPolicy: 'all',
240
- notifyOnNetworkStatusChange: true,
269
+ notifyOnNetworkStatusChange: false, // No need for real-time updates
241
270
  returnPartialData: true,
271
+ // Add context for better cache management
272
+ context: {
273
+ cacheKey: 'channel-detail',
274
+ },
242
275
  });
243
276
 
244
- // Create loader data array for Inbox component
277
+ // Enhanced error handling with retry logic
278
+ const handleRetry = useCallback(() => {
279
+ if (channelsQuery.error) {
280
+ channelsQuery.refetch();
281
+ }
282
+ if (messagesQuery.error) {
283
+ messagesQuery.refetch();
284
+ }
285
+ if (channelDetailQuery.error) {
286
+ channelDetailQuery.refetch();
287
+ }
288
+ }, [channelsQuery, messagesQuery, channelDetailQuery]);
289
+
290
+ // Create loader data array for Inbox component with better error handling
245
291
  const loaderData = useMemo(
246
292
  () => [channelsQuery, messagesQuery, channelDetailQuery],
247
293
  [channelsQuery, messagesQuery, channelDetailQuery],
248
294
  );
249
295
 
250
- // Enhanced loading states with skeleton
296
+ // Enhanced loading states with better UX
251
297
  if (channelsQuery.loading && !pathChannelId && !channelsQuery.data) {
252
298
  return <InboxSkeleton showRightSidebar={false} />;
253
299
  }
@@ -262,8 +308,28 @@ const InboxWithLoader = (props: InboxWithLoaderProps) => {
262
308
  return <InboxSkeleton showRightSidebar={true} />;
263
309
  }
264
310
 
311
+ // Enhanced error handling with retry option
265
312
  if (channelsQuery.error && !channelsQuery.data) {
266
- return <TailwindAlert>Error loading channels: {channelsQuery.error.message}</TailwindAlert>;
313
+ return (
314
+ <div className="flex flex-col items-center justify-center min-h-screen space-y-4">
315
+ <TailwindAlert>Error loading channels: {channelsQuery.error.message}</TailwindAlert>
316
+ <button
317
+ onClick={handleRetry}
318
+ className="px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors"
319
+ >
320
+ Retry
321
+ </button>
322
+ </div>
323
+ );
324
+ }
325
+
326
+ // Handle individual query errors gracefully
327
+ if (messagesQuery.error && !messagesQuery.data && pathChannelId) {
328
+ console.warn('Messages query error:', messagesQuery.error);
329
+ }
330
+
331
+ if (channelDetailQuery.error && !channelDetailQuery.data && pathChannelId) {
332
+ console.warn('Channel detail query error:', channelDetailQuery.error);
267
333
  }
268
334
 
269
335
  return <Inbox data={loaderData} {...inboxProps} />;