analytica-frontend-lib 1.2.55 → 1.2.56

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 (39) hide show
  1. package/dist/ActivitiesHistory/index.css +12 -0
  2. package/dist/ActivitiesHistory/index.css.map +1 -1
  3. package/dist/ActivityCardQuestionBanks/index.css +12 -0
  4. package/dist/ActivityCardQuestionBanks/index.css.map +1 -1
  5. package/dist/ActivityCardQuestionPreview/index.css +12 -0
  6. package/dist/ActivityCardQuestionPreview/index.css.map +1 -1
  7. package/dist/ActivityDetails/index.css +12 -0
  8. package/dist/ActivityDetails/index.css.map +1 -1
  9. package/dist/ActivityFilters/index.css +12 -0
  10. package/dist/ActivityFilters/index.css.map +1 -1
  11. package/dist/ActivityPreview/index.css +12 -0
  12. package/dist/ActivityPreview/index.css.map +1 -1
  13. package/dist/AlertManager/index.css +12 -0
  14. package/dist/AlertManager/index.css.map +1 -1
  15. package/dist/RecommendedLessonsHistory/index.css +12 -0
  16. package/dist/RecommendedLessonsHistory/index.css.map +1 -1
  17. package/dist/SendActivityModal/SendActivityModal.css +12 -0
  18. package/dist/SendActivityModal/SendActivityModal.css.map +1 -1
  19. package/dist/SendActivityModal/index.css +12 -0
  20. package/dist/SendActivityModal/index.css.map +1 -1
  21. package/dist/TableProvider/index.css +12 -0
  22. package/dist/TableProvider/index.css.map +1 -1
  23. package/dist/hooks/useAppContent.d.ts +0 -1
  24. package/dist/hooks/useAppContent.d.ts.map +1 -1
  25. package/dist/hooks/useChat.d.ts.map +1 -1
  26. package/dist/hooks/useChatRooms.d.ts.map +1 -1
  27. package/dist/index.css +12 -0
  28. package/dist/index.css.map +1 -1
  29. package/dist/index.d.ts +3 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +137 -28
  32. package/dist/index.js.map +1 -1
  33. package/dist/index.mjs +134 -29
  34. package/dist/index.mjs.map +1 -1
  35. package/dist/styles.css +12 -0
  36. package/dist/styles.css.map +1 -1
  37. package/dist/utils/chatUtils.d.ts +74 -0
  38. package/dist/utils/chatUtils.d.ts.map +1 -0
  39. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -19258,7 +19258,7 @@ import { useCallback as useCallback14, useEffect as useEffect38, useMemo as useM
19258
19258
  import { useNavigate as useNavigate2 } from "react-router-dom";
19259
19259
  function useAppContent(config) {
19260
19260
  const navigate = useNavigate2();
19261
- const { setTokens, setSessionInfo, setSelectedProfile, setUser } = useAuthStore();
19261
+ const { setTokens, setSessionInfo, setSelectedProfile } = useAuthStore();
19262
19262
  const {
19263
19263
  api,
19264
19264
  getInstitutionId,
@@ -19309,7 +19309,6 @@ function useAppContent(config) {
19309
19309
  setTokens,
19310
19310
  setSessionInfo,
19311
19311
  setSelectedProfile: handleSetSelectedProfile,
19312
- setUser,
19313
19312
  api: apiConfig,
19314
19313
  endpoint,
19315
19314
  clearParamsFromURL: handleClearParamsFromURL,
@@ -19321,7 +19320,6 @@ function useAppContent(config) {
19321
19320
  setTokens,
19322
19321
  setSessionInfo,
19323
19322
  handleSetSelectedProfile,
19324
- setUser,
19325
19323
  apiConfig,
19326
19324
  endpoint,
19327
19325
  handleClearParamsFromURL,
@@ -25153,6 +25151,9 @@ function useChat({
25153
25151
  null
25154
25152
  );
25155
25153
  const isManualDisconnectRef = useRef28(false);
25154
+ const isConnectingRef = useRef28(false);
25155
+ const connectRef = useRef28(() => {
25156
+ });
25156
25157
  const sendWsMessage = useCallback27((message) => {
25157
25158
  if (wsRef.current?.readyState === WS_STATES.OPEN) {
25158
25159
  wsRef.current.send(JSON.stringify(message));
@@ -25243,15 +25244,20 @@ function useChat({
25243
25244
  [onError]
25244
25245
  );
25245
25246
  const connect = useCallback27(() => {
25247
+ if (isConnectingRef.current) {
25248
+ return;
25249
+ }
25246
25250
  const url = new URL(wsUrl);
25247
25251
  url.searchParams.set("roomId", roomId);
25248
25252
  url.searchParams.set("token", token);
25249
25253
  if (wsRef.current) {
25250
25254
  wsRef.current.close();
25251
25255
  }
25256
+ isConnectingRef.current = true;
25252
25257
  const ws = new WebSocket(url.toString());
25253
25258
  wsRef.current = ws;
25254
25259
  ws.onopen = () => {
25260
+ isConnectingRef.current = false;
25255
25261
  setIsConnected(true);
25256
25262
  setError(null);
25257
25263
  reconnectAttemptsRef.current = 0;
@@ -25259,11 +25265,13 @@ function useChat({
25259
25265
  };
25260
25266
  ws.onmessage = handleMessage;
25261
25267
  ws.onerror = () => {
25268
+ isConnectingRef.current = false;
25262
25269
  const error2 = new Error("Erro na conex\xE3o WebSocket");
25263
25270
  setError(error2);
25264
25271
  onError?.(error2);
25265
25272
  };
25266
25273
  ws.onclose = (event) => {
25274
+ isConnectingRef.current = false;
25267
25275
  setIsConnected(false);
25268
25276
  onDisconnect?.();
25269
25277
  if (autoReconnect && !isManualDisconnectRef.current && reconnectAttemptsRef.current < maxReconnectAttempts && event.code !== 4001 && // Unauthorized
@@ -25287,22 +25295,40 @@ function useChat({
25287
25295
  reconnectInterval,
25288
25296
  maxReconnectAttempts
25289
25297
  ]);
25298
+ connectRef.current = connect;
25290
25299
  const reconnect = useCallback27(() => {
25291
25300
  isManualDisconnectRef.current = false;
25292
25301
  reconnectAttemptsRef.current = 0;
25293
- connect();
25294
- }, [connect]);
25302
+ connectRef.current();
25303
+ }, []);
25295
25304
  useEffect46(() => {
25305
+ if (!roomId) {
25306
+ return;
25307
+ }
25308
+ if (reconnectTimeoutRef.current) {
25309
+ clearTimeout(reconnectTimeoutRef.current);
25310
+ reconnectTimeoutRef.current = null;
25311
+ }
25296
25312
  isManualDisconnectRef.current = false;
25297
- connect();
25313
+ isConnectingRef.current = false;
25314
+ reconnectAttemptsRef.current = 0;
25315
+ if (wsRef.current) {
25316
+ wsRef.current.close(1e3, "Room changed");
25317
+ wsRef.current = null;
25318
+ }
25319
+ const timeoutId = setTimeout(() => {
25320
+ connectRef.current();
25321
+ }, 100);
25298
25322
  return () => {
25323
+ clearTimeout(timeoutId);
25299
25324
  isManualDisconnectRef.current = true;
25325
+ isConnectingRef.current = false;
25300
25326
  if (reconnectTimeoutRef.current) {
25301
25327
  clearTimeout(reconnectTimeoutRef.current);
25302
25328
  }
25303
25329
  wsRef.current?.close(1e3, "Component unmounted");
25304
25330
  };
25305
- }, [connect]);
25331
+ }, [roomId]);
25306
25332
  return {
25307
25333
  isConnected,
25308
25334
  messages,
@@ -25331,8 +25357,10 @@ function useChatRooms({
25331
25357
  setLoading(true);
25332
25358
  setError(null);
25333
25359
  try {
25334
- const response = await apiClient.get("/chat/rooms");
25335
- setRooms(response.data.rooms);
25360
+ const response = await apiClient.get(
25361
+ "/chat/rooms"
25362
+ );
25363
+ setRooms(response.data.data.rooms);
25336
25364
  } catch (err) {
25337
25365
  const error2 = err instanceof Error ? err : new Error("Erro ao carregar salas");
25338
25366
  setError(error2);
@@ -25348,7 +25376,7 @@ function useChatRooms({
25348
25376
  const response = await apiClient.get(
25349
25377
  "/chat/available-users"
25350
25378
  );
25351
- setAvailableUsers(response.data.users);
25379
+ setAvailableUsers(response.data.data.users);
25352
25380
  } catch (err) {
25353
25381
  const error2 = err instanceof Error ? err : new Error("Erro ao carregar usu\xE1rios");
25354
25382
  setError(error2);
@@ -25369,7 +25397,7 @@ function useChatRooms({
25369
25397
  }
25370
25398
  );
25371
25399
  await fetchRooms();
25372
- return response.data.room;
25400
+ return response.data.data.room;
25373
25401
  } catch (err) {
25374
25402
  const error2 = err instanceof Error ? err : new Error("Erro ao criar sala");
25375
25403
  setError(error2);
@@ -25415,7 +25443,7 @@ var CHAT_MESSAGE_TYPES = {
25415
25443
  };
25416
25444
 
25417
25445
  // src/components/Chat/Chat.tsx
25418
- import { useState as useState52, useEffect as useEffect47, useCallback as useCallback29 } from "react";
25446
+ import { useState as useState52, useEffect as useEffect47, useCallback as useCallback29, useRef as useRef29 } from "react";
25419
25447
  import {
25420
25448
  PaperPlaneTiltIcon as PaperPlaneTiltIcon2,
25421
25449
  XIcon,
@@ -25548,7 +25576,14 @@ var UserSelector = ({
25548
25576
  },
25549
25577
  user.userInstitutionId
25550
25578
  )) });
25551
- function Chat({
25579
+ function Chat(props) {
25580
+ const { userId, token } = props;
25581
+ if (!userId || !token) {
25582
+ return /* @__PURE__ */ jsx104("div", { className: "flex items-center justify-center h-96", children: /* @__PURE__ */ jsx104(Text_default, { size: "sm", className: "text-text-500", children: "Carregando..." }) });
25583
+ }
25584
+ return /* @__PURE__ */ jsx104(ChatContent, { ...props });
25585
+ }
25586
+ function ChatContent({
25552
25587
  apiClient,
25553
25588
  wsUrl,
25554
25589
  token,
@@ -25556,7 +25591,10 @@ function Chat({
25556
25591
  userName,
25557
25592
  userPhoto,
25558
25593
  userRole,
25559
- className
25594
+ className,
25595
+ initialRoomId,
25596
+ onRoomChange,
25597
+ onBackToList
25560
25598
  }) {
25561
25599
  const [view, setView] = useState52("list");
25562
25600
  const [selectedRoom, setSelectedRoom] = useState52(
@@ -25567,6 +25605,7 @@ function Chat({
25567
25605
  );
25568
25606
  const [messageInput, setMessageInput] = useState52("");
25569
25607
  const [showCreateModal, setShowCreateModal] = useState52(false);
25608
+ const hasHandledInitialRoomRef = useRef29(false);
25570
25609
  const {
25571
25610
  rooms,
25572
25611
  availableUsers,
@@ -25597,10 +25636,36 @@ function Chat({
25597
25636
  useEffect47(() => {
25598
25637
  fetchRooms();
25599
25638
  }, [fetchRooms]);
25600
- const handleSelectRoom = useCallback29((room) => {
25601
- setSelectedRoom(room);
25602
- setView("room");
25603
- }, []);
25639
+ useEffect47(() => {
25640
+ if (hasHandledInitialRoomRef.current) {
25641
+ return;
25642
+ }
25643
+ if (!initialRoomId || roomsLoading) {
25644
+ return;
25645
+ }
25646
+ if (rooms?.length > 0) {
25647
+ const room = rooms.find((r) => r.id === initialRoomId);
25648
+ if (room) {
25649
+ hasHandledInitialRoomRef.current = true;
25650
+ setSelectedRoom(room);
25651
+ setView("room");
25652
+ } else {
25653
+ hasHandledInitialRoomRef.current = true;
25654
+ onBackToList?.();
25655
+ }
25656
+ } else if (rooms !== void 0 && !roomsLoading) {
25657
+ hasHandledInitialRoomRef.current = true;
25658
+ onBackToList?.();
25659
+ }
25660
+ }, [initialRoomId, rooms, roomsLoading, onBackToList]);
25661
+ const handleSelectRoom = useCallback29(
25662
+ (room) => {
25663
+ setSelectedRoom(room);
25664
+ setView("room");
25665
+ onRoomChange?.(room.id);
25666
+ },
25667
+ [onRoomChange]
25668
+ );
25604
25669
  const handleOpenCreateModal = useCallback29(async () => {
25605
25670
  await fetchAvailableUsers();
25606
25671
  setSelectedUserIds(/* @__PURE__ */ new Set());
@@ -25623,9 +25688,9 @@ function Chat({
25623
25688
  if (room) {
25624
25689
  setShowCreateModal(false);
25625
25690
  setSelectedUserIds(/* @__PURE__ */ new Set());
25626
- await fetchRooms();
25691
+ onRoomChange?.(room.id);
25627
25692
  }
25628
- }, [selectedUserIds, createRoom, fetchRooms]);
25693
+ }, [selectedUserIds, createRoom, onRoomChange]);
25629
25694
  const handleSendMessage = useCallback29(() => {
25630
25695
  if (!messageInput.trim()) return;
25631
25696
  sendMessage(messageInput);
@@ -25634,7 +25699,8 @@ function Chat({
25634
25699
  const handleBackToList = useCallback29(() => {
25635
25700
  setSelectedRoom(null);
25636
25701
  setView("list");
25637
- }, []);
25702
+ onBackToList?.();
25703
+ }, [onBackToList]);
25638
25704
  const renderMessagesContent = () => {
25639
25705
  if (chatError) {
25640
25706
  return /* @__PURE__ */ jsx104("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsxs83("div", { className: "text-center", children: [
@@ -25642,10 +25708,13 @@ function Chat({
25642
25708
  /* @__PURE__ */ jsx104(Text_default, { size: "xs", className: "text-text-500", children: "Tentando reconectar..." })
25643
25709
  ] }) });
25644
25710
  }
25645
- if (messages.length === 0) {
25711
+ const userMessages = messages?.filter(
25712
+ (message) => message.messageType !== CHAT_MESSAGE_TYPES.SYSTEM
25713
+ );
25714
+ if (!userMessages?.length) {
25646
25715
  return /* @__PURE__ */ jsx104("div", { className: "flex items-center justify-center h-full", children: /* @__PURE__ */ jsx104(Text_default, { size: "sm", className: "text-text-500", children: "Nenhuma mensagem ainda. Comece a conversa!" }) });
25647
25716
  }
25648
- return messages.map((message) => /* @__PURE__ */ jsx104(
25717
+ return userMessages.map((message) => /* @__PURE__ */ jsx104(
25649
25718
  MessageBubble,
25650
25719
  {
25651
25720
  message,
@@ -25697,14 +25766,14 @@ function Chat({
25697
25766
  /* @__PURE__ */ jsx104(SkeletonText, { className: "w-1/2 h-3" })
25698
25767
  ] })
25699
25768
  ] }, i)) }),
25700
- !roomsError && !roomsLoading && rooms.length === 0 && /* @__PURE__ */ jsx104(
25769
+ !roomsError && !roomsLoading && !rooms?.length && /* @__PURE__ */ jsx104(
25701
25770
  EmptyState_default,
25702
25771
  {
25703
25772
  title: "Nenhuma conversa",
25704
25773
  description: "Comece uma nova conversa clicando no botao acima"
25705
25774
  }
25706
25775
  ),
25707
- !roomsError && !roomsLoading && rooms.length > 0 && /* @__PURE__ */ jsx104("div", { className: "space-y-1", children: rooms.map((room) => /* @__PURE__ */ jsx104(
25776
+ !roomsError && !roomsLoading && !!rooms?.length && /* @__PURE__ */ jsx104("div", { className: "space-y-1", children: rooms.map((room) => /* @__PURE__ */ jsx104(
25708
25777
  RoomItem,
25709
25778
  {
25710
25779
  room,
@@ -25757,10 +25826,10 @@ function Chat({
25757
25826
  /* @__PURE__ */ jsxs83("div", { className: "w-64 border-l border-background-200 p-4 hidden lg:block", children: [
25758
25827
  /* @__PURE__ */ jsxs83(Text_default, { size: "sm", weight: "semibold", className: "text-text-900 mb-3", children: [
25759
25828
  "Participantes (",
25760
- participants.length,
25829
+ participants?.length ?? 0,
25761
25830
  ")"
25762
25831
  ] }),
25763
- /* @__PURE__ */ jsx104("div", { className: "space-y-1", children: participants.map((participant) => /* @__PURE__ */ jsx104(
25832
+ /* @__PURE__ */ jsx104("div", { className: "space-y-1", children: participants?.map((participant) => /* @__PURE__ */ jsx104(
25764
25833
  ParticipantItem,
25765
25834
  {
25766
25835
  participant
@@ -25792,8 +25861,8 @@ function Chat({
25792
25861
  /* @__PURE__ */ jsx104(SkeletonRounded, { className: "w-10 h-10" }),
25793
25862
  /* @__PURE__ */ jsx104(SkeletonText, { className: "flex-1 h-4" })
25794
25863
  ] }, i)) }),
25795
- !roomsLoading && availableUsers.length === 0 && /* @__PURE__ */ jsx104(Text_default, { size: "sm", className: "text-text-500 text-center py-4", children: "Nenhum usuario disponivel para chat" }),
25796
- !roomsLoading && availableUsers.length > 0 && /* @__PURE__ */ jsx104(
25864
+ !roomsLoading && !availableUsers?.length && /* @__PURE__ */ jsx104(Text_default, { size: "sm", className: "text-text-500 text-center py-4", children: "Nenhum usuario disponivel para chat" }),
25865
+ !roomsLoading && !!availableUsers?.length && /* @__PURE__ */ jsx104(
25797
25866
  UserSelector,
25798
25867
  {
25799
25868
  users: availableUsers,
@@ -25820,6 +25889,38 @@ function Chat({
25820
25889
  }
25821
25890
  );
25822
25891
  }
25892
+
25893
+ // src/components/Chat/ChatLoading.tsx
25894
+ import { jsx as jsx105 } from "react/jsx-runtime";
25895
+ function ChatLoading() {
25896
+ return /* @__PURE__ */ jsx105("div", { className: "flex items-center justify-center h-96", children: /* @__PURE__ */ jsx105(Text_default, { size: "sm", className: "text-text-500", children: "Carregando..." }) });
25897
+ }
25898
+
25899
+ // src/utils/chatUtils.ts
25900
+ var isChatUserInfoValid = (userInfo) => {
25901
+ return Boolean(userInfo.userId && userInfo.token);
25902
+ };
25903
+ var getChatWsUrl = (apiUrl) => {
25904
+ const baseUrl = apiUrl;
25905
+ return baseUrl.replace(/^http/, "ws") + "/chat/ws";
25906
+ };
25907
+ var getChatUserInfo = (user, tokens, sessionInfo, defaultUserName = "Usuario") => {
25908
+ const userId = String(user?.userInstitutionId ?? sessionInfo?.userId ?? "");
25909
+ const userName = String(
25910
+ user?.name ?? sessionInfo?.userName ?? defaultUserName
25911
+ );
25912
+ const photoUrl = String(
25913
+ user?.urlProfilePicture ?? sessionInfo?.urlProfilePicture ?? ""
25914
+ );
25915
+ const userPhoto = photoUrl || null;
25916
+ const token = tokens?.token || "";
25917
+ return {
25918
+ userId,
25919
+ userName,
25920
+ userPhoto,
25921
+ token
25922
+ };
25923
+ };
25823
25924
  export {
25824
25925
  ACTIVITY_AVAILABILITY,
25825
25926
  ACTIVITY_FILTER_STATUS_OPTIONS,
@@ -25863,6 +25964,7 @@ export {
25863
25964
  CardTest,
25864
25965
  CardTopic,
25865
25966
  Chat,
25967
+ ChatLoading,
25866
25968
  CheckBox_default as CheckBox,
25867
25969
  CheckboxGroup,
25868
25970
  CheckboxList_default as CheckboxList,
@@ -26031,6 +26133,8 @@ export {
26031
26133
  getActivityStatusBadgeAction,
26032
26134
  getCategoryIcon,
26033
26135
  getCategoryText,
26136
+ getChatUserInfo,
26137
+ getChatWsUrl,
26034
26138
  getDeviceType,
26035
26139
  getGoalStatusBadgeAction,
26036
26140
  getQuestionStatusBadgeConfig,
@@ -26054,6 +26158,7 @@ export {
26054
26158
  handleLessonDetailsFetchError,
26055
26159
  handleModelFetchError,
26056
26160
  historyApiResponseSchema,
26161
+ isChatUserInfoValid,
26057
26162
  isDeadlinePassed,
26058
26163
  isFormValid,
26059
26164
  isStepValid,