@traky-app/ui 1.6.6 → 1.6.8

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.
@@ -82,6 +82,7 @@ import {
82
82
  InputGroupTextarea,
83
83
  } from "./input-group";
84
84
  import { Input } from "./input";
85
+ import { Skeleton } from "./skeleton";
85
86
  import {
86
87
  Message,
87
88
  MessageAvatar,
@@ -219,6 +220,8 @@ export type InternalChatPanelLabels = {
219
220
  supportChat: string;
220
221
  supportChatTooltip: string;
221
222
  supportRoomDescription: string;
223
+ reconnectingMessages: string;
224
+ connectionOffline: string;
222
225
  };
223
226
 
224
227
  const DEFAULT_LABELS: InternalChatPanelLabels = {
@@ -240,6 +243,10 @@ const DEFAULT_LABELS: InternalChatPanelLabels = {
240
243
  noRoomTitle: "Sin sala",
241
244
  noRoomDescription: "Crea una sala con el botón + a la izquierda.",
242
245
  loadingMessages: "Cargando mensajes…",
246
+ reconnectingMessages:
247
+ "Reconectando el chat… Si tarda, cierra y vuelve a abrir el panel.",
248
+ connectionOffline:
249
+ "Sin conexión en tiempo real. Cierra el chat un momento o recarga la página.",
243
250
  loadMessagesErrorTitle: "No se pudieron cargar los mensajes",
244
251
  loadMessagesErrorFallback:
245
252
  "Revisa que la API esté en marcha y que el módulo de chat interno esté migrado.",
@@ -1283,6 +1290,10 @@ export type InternalChatPanelProps = {
1283
1290
  * y no bloquea clics en el resto del admin (sin overlay a pantalla completa).
1284
1291
  */
1285
1292
  embedded?: boolean;
1293
+ /** Tras pestaña suspendida o pérdida del WebSocket. */
1294
+ realtimeStatus?: "connected" | "reconnecting" | "offline";
1295
+ /** Si es false, no monta trigger ni drawer (flag del host). */
1296
+ featureEnabled?: boolean;
1286
1297
  };
1287
1298
 
1288
1299
  function InternalChatPanel({
@@ -1326,9 +1337,27 @@ function InternalChatPanel({
1326
1337
  defaultOpen = false,
1327
1338
  hideTrigger = false,
1328
1339
  embedded = false,
1340
+ realtimeStatus = "connected",
1341
+ featureEnabled = true,
1329
1342
  }: InternalChatPanelProps) {
1343
+ if (!featureEnabled) {
1344
+ return null;
1345
+ }
1346
+
1330
1347
  const labels = { ...DEFAULT_LABELS, ...labelsPartial };
1331
1348
 
1349
+ const displayMessagesStatus: InternalChatMessagesStatus =
1350
+ realtimeStatus === "reconnecting"
1351
+ ? "loading"
1352
+ : realtimeStatus === "offline" && messagesStatus === "ready"
1353
+ ? "error"
1354
+ : messagesStatus;
1355
+
1356
+ const displayMessagesError =
1357
+ realtimeStatus === "offline" && messagesStatus === "ready"
1358
+ ? labels.connectionOffline
1359
+ : messagesError;
1360
+
1332
1361
  const [open, setOpen] = useState(defaultOpen);
1333
1362
  const [draft, setDraft] = useState("");
1334
1363
  const [createOpen, setCreateOpen] = useState(false);
@@ -2063,12 +2092,21 @@ function InternalChatPanel({
2063
2092
  </EmptyDescription>
2064
2093
  </EmptyHeader>
2065
2094
  </Empty>
2066
- ) : messagesStatus === "loading" ? (
2067
- <div className="flex h-full flex-col items-center justify-center gap-2 text-muted-foreground">
2095
+ ) : displayMessagesStatus === "loading" ? (
2096
+ <div className="flex h-full flex-col items-center justify-center gap-4 px-6 text-muted-foreground">
2068
2097
  <IconLoader2 className="size-6 animate-spin" aria-hidden />
2069
- <span className="text-sm">{labels.loadingMessages}</span>
2098
+ <span className="text-center text-sm">
2099
+ {realtimeStatus === "reconnecting"
2100
+ ? labels.reconnectingMessages
2101
+ : labels.loadingMessages}
2102
+ </span>
2103
+ <div className="flex w-full max-w-sm flex-col gap-2">
2104
+ <Skeleton className="h-10 w-3/4 self-end rounded-xl" />
2105
+ <Skeleton className="h-14 w-full rounded-xl" />
2106
+ <Skeleton className="h-10 w-2/3 rounded-xl" />
2107
+ </div>
2070
2108
  </div>
2071
- ) : messagesStatus === "error" ? (
2109
+ ) : displayMessagesStatus === "error" ? (
2072
2110
  <Empty className="h-full border-0">
2073
2111
  <EmptyHeader>
2074
2112
  <EmptyMedia variant="icon">
@@ -2076,11 +2114,11 @@ function InternalChatPanel({
2076
2114
  </EmptyMedia>
2077
2115
  <EmptyTitle>{labels.loadMessagesErrorTitle}</EmptyTitle>
2078
2116
  <EmptyDescription className="text-left">
2079
- {messagesError ?? labels.loadMessagesErrorFallback}
2117
+ {displayMessagesError ?? labels.loadMessagesErrorFallback}
2080
2118
  </EmptyDescription>
2081
2119
  </EmptyHeader>
2082
2120
  </Empty>
2083
- ) : messagesStatus === "empty" ? (
2121
+ ) : displayMessagesStatus === "empty" ? (
2084
2122
  <Empty className="h-full border-0">
2085
2123
  <EmptyHeader>
2086
2124
  <EmptyMedia variant="icon">