analytica-frontend-lib 1.1.45 → 1.1.46

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.
@@ -1,3 +1,3 @@
1
1
  import 'react/jsx-runtime';
2
2
  import 'react';
3
- export { j as LegacyNotificationCard, L as LegacyNotificationCardProps, i as NotificationCardProps, b as NotificationGroup, d as NotificationItem, c as default } from '../NotificationCard-IYDURfYp.mjs';
3
+ export { j as LegacyNotificationCard, L as LegacyNotificationCardProps, i as NotificationCardProps, b as NotificationGroup, f as NotificationItem, e as default } from '../NotificationCard-kGUKNOqT.mjs';
@@ -1,3 +1,3 @@
1
1
  import 'react/jsx-runtime';
2
2
  import 'react';
3
- export { j as LegacyNotificationCard, L as LegacyNotificationCardProps, i as NotificationCardProps, b as NotificationGroup, d as NotificationItem, c as default } from '../NotificationCard-IYDURfYp.js';
3
+ export { j as LegacyNotificationCard, L as LegacyNotificationCardProps, i as NotificationCardProps, b as NotificationGroup, f as NotificationItem, e as default } from '../NotificationCard-kGUKNOqT.js';
@@ -399,4 +399,4 @@ declare const NotificationCard: (props: NotificationCardProps) => react_jsx_runt
399
399
  */
400
400
  declare const LegacyNotificationCard: (props: LegacyNotificationCardProps) => react_jsx_runtime.JSX.Element;
401
401
 
402
- export { type BackendNotification as B, type FetchNotificationsParams as F, type LegacyNotificationCardProps as L, type NotificationApiClient as N, type Notification as a, type NotificationGroup as b, NotificationCard as c, type NotificationItem as d, NotificationEntityType as e, type NotificationType as f, type BackendNotificationsResponse as g, type NotificationsResponse as h, type NotificationCardProps as i, LegacyNotificationCard as j };
402
+ export { type BackendNotification as B, type FetchNotificationsParams as F, type LegacyNotificationCardProps as L, type NotificationApiClient as N, type Notification as a, type NotificationGroup as b, NotificationEntityType as c, type NotificationType as d, NotificationCard as e, type NotificationItem as f, type BackendNotificationsResponse as g, type NotificationsResponse as h, type NotificationCardProps as i, LegacyNotificationCard as j };
@@ -399,4 +399,4 @@ declare const NotificationCard: (props: NotificationCardProps) => react_jsx_runt
399
399
  */
400
400
  declare const LegacyNotificationCard: (props: LegacyNotificationCardProps) => react_jsx_runtime.JSX.Element;
401
401
 
402
- export { type BackendNotification as B, type FetchNotificationsParams as F, type LegacyNotificationCardProps as L, type NotificationApiClient as N, type Notification as a, type NotificationGroup as b, NotificationCard as c, type NotificationItem as d, NotificationEntityType as e, type NotificationType as f, type BackendNotificationsResponse as g, type NotificationsResponse as h, type NotificationCardProps as i, LegacyNotificationCard as j };
402
+ export { type BackendNotification as B, type FetchNotificationsParams as F, type LegacyNotificationCardProps as L, type NotificationApiClient as N, type Notification as a, type NotificationGroup as b, NotificationEntityType as c, type NotificationType as d, NotificationCard as e, type NotificationItem as f, type BackendNotificationsResponse as g, type NotificationsResponse as h, type NotificationCardProps as i, LegacyNotificationCard as j };
package/dist/index.d.mts CHANGED
@@ -47,8 +47,8 @@ export { useApiConfig } from './Auth/useApiConfig/index.mjs';
47
47
  export { Quiz, QuizAlternative, QuizConnectDots, QuizContent, QuizDissertative, QuizFooter, QuizHeader, QuizHeaderResult, QuizImageQuestion, QuizListResult, QuizListResultByMateria, QuizMultipleChoice, QuizQuestionList, QuizResultHeaderTitle, QuizResultPerformance, QuizResultTitle, QuizTitle, QuizTrueOrFalse, getStatusBadge } from './Quiz/index.mjs';
48
48
  export { ANSWER_STATUS, Activity, Lesson, QUESTION_DIFFICULTY, QUESTION_STATUS, QUESTION_TYPE, Question, QuestionResult, QuizState, SUBTYPE_ENUM, Simulated, UserAnswerItem, useQuizStore } from './Quiz/useQuizStore/index.mjs';
49
49
  export { default as LoadingModal } from './LoadingModal/index.mjs';
50
- import { N as NotificationApiClient, a as Notification, F as FetchNotificationsParams, b as NotificationGroup } from './NotificationCard-IYDURfYp.mjs';
51
- export { B as BackendNotification, g as BackendNotificationsResponse, c as NotificationCard, e as NotificationEntityType, d as NotificationItem, f as NotificationType, h as NotificationsResponse } from './NotificationCard-IYDURfYp.mjs';
50
+ import { N as NotificationApiClient, a as Notification, F as FetchNotificationsParams, b as NotificationGroup, c as NotificationEntityType, d as NotificationType } from './NotificationCard-kGUKNOqT.mjs';
51
+ export { B as BackendNotification, g as BackendNotificationsResponse, e as NotificationCard, f as NotificationItem, h as NotificationsResponse } from './NotificationCard-kGUKNOqT.mjs';
52
52
  import 'react/jsx-runtime';
53
53
 
54
54
  /**
@@ -259,4 +259,129 @@ declare const createUseNotificationStore: (apiClient: NotificationApiClient) =>
259
259
  };
260
260
  }>;
261
261
 
262
- export { CheckboxList, CheckboxListItem, FetchNotificationsParams, Notification, type NotificationActions, NotificationApiClient, NotificationGroup, type NotificationState, type NotificationStore, createNotificationStore, createUseNotificationStore, formatTimeAgo };
262
+ /**
263
+ * Create a comprehensive notifications hook with formatting and navigation
264
+ * This hook provides all notification functionality in a single interface
265
+ *
266
+ * @param apiClient - API client instance for notifications
267
+ * @returns Hook with notification state, actions, and utilities
268
+ */
269
+ declare const createUseNotifications: (apiClient: NotificationApiClient) => () => {
270
+ notifications: Notification[];
271
+ unreadCount: number;
272
+ loading: boolean;
273
+ error: string | null;
274
+ hasMore: boolean;
275
+ currentPage: number;
276
+ fetchNotifications: (params?: FetchNotificationsParams) => Promise<void>;
277
+ markAsRead: (id: string) => Promise<void>;
278
+ markAllAsRead: () => Promise<void>;
279
+ deleteNotification: (id: string) => Promise<void>;
280
+ clearNotifications: () => void;
281
+ resetError: () => void;
282
+ markAsReadAndNavigate: (id: string, entityType?: string, entityId?: string) => Promise<void>;
283
+ refreshNotifications: () => Promise<void>;
284
+ handleNavigate: (entityType?: string, entityId?: string) => void;
285
+ getActionLabel: (entityType?: string) => string | undefined;
286
+ getGroupedNotifications: () => NotificationGroup[];
287
+ getFormattedGroupedNotifications: () => {
288
+ notifications: {
289
+ time: string;
290
+ entityType: NotificationEntityType | undefined;
291
+ entityId: string | undefined;
292
+ id: string;
293
+ title: string;
294
+ message: string;
295
+ type: NotificationType;
296
+ isRead: boolean;
297
+ createdAt: Date;
298
+ sender?: {
299
+ id: string;
300
+ user: {
301
+ id: string;
302
+ name: string;
303
+ email: string;
304
+ };
305
+ } | null;
306
+ activity?: {
307
+ id: string;
308
+ title: string;
309
+ type: string;
310
+ } | null;
311
+ goal?: {
312
+ id: string;
313
+ title: string;
314
+ } | null;
315
+ }[];
316
+ label: string;
317
+ }[];
318
+ };
319
+ /**
320
+ * Create a pre-configured notifications hook
321
+ * This is a convenience function that returns a hook ready to use
322
+ *
323
+ * @param apiClient - API client instance for notifications
324
+ * @returns Pre-configured useNotifications hook
325
+ *
326
+ * @example
327
+ * // In your app setup
328
+ * import { createNotificationsHook } from 'analytica-frontend-lib';
329
+ * import api from './services/api';
330
+ *
331
+ * export const useNotifications = createNotificationsHook(api);
332
+ *
333
+ * // Then use directly in components
334
+ * const { unreadCount, fetchNotifications } = useNotifications();
335
+ */
336
+ declare const createNotificationsHook: (apiClient: NotificationApiClient) => () => {
337
+ notifications: Notification[];
338
+ unreadCount: number;
339
+ loading: boolean;
340
+ error: string | null;
341
+ hasMore: boolean;
342
+ currentPage: number;
343
+ fetchNotifications: (params?: FetchNotificationsParams) => Promise<void>;
344
+ markAsRead: (id: string) => Promise<void>;
345
+ markAllAsRead: () => Promise<void>;
346
+ deleteNotification: (id: string) => Promise<void>;
347
+ clearNotifications: () => void;
348
+ resetError: () => void;
349
+ markAsReadAndNavigate: (id: string, entityType?: string, entityId?: string) => Promise<void>;
350
+ refreshNotifications: () => Promise<void>;
351
+ handleNavigate: (entityType?: string, entityId?: string) => void;
352
+ getActionLabel: (entityType?: string) => string | undefined;
353
+ getGroupedNotifications: () => NotificationGroup[];
354
+ getFormattedGroupedNotifications: () => {
355
+ notifications: {
356
+ time: string;
357
+ entityType: NotificationEntityType | undefined;
358
+ entityId: string | undefined;
359
+ id: string;
360
+ title: string;
361
+ message: string;
362
+ type: NotificationType;
363
+ isRead: boolean;
364
+ createdAt: Date;
365
+ sender?: {
366
+ id: string;
367
+ user: {
368
+ id: string;
369
+ name: string;
370
+ email: string;
371
+ };
372
+ } | null;
373
+ activity?: {
374
+ id: string;
375
+ title: string;
376
+ type: string;
377
+ } | null;
378
+ goal?: {
379
+ id: string;
380
+ title: string;
381
+ } | null;
382
+ }[];
383
+ label: string;
384
+ }[];
385
+ };
386
+
387
+ export { CheckboxList, CheckboxListItem, FetchNotificationsParams, Notification, type NotificationActions, NotificationApiClient, NotificationEntityType, NotificationGroup, type NotificationState, type NotificationStore, NotificationType, createNotificationStore, createNotificationsHook, createUseNotificationStore, createUseNotifications, formatTimeAgo };
package/dist/index.d.ts CHANGED
@@ -47,8 +47,8 @@ export { useApiConfig } from './Auth/useApiConfig/index.js';
47
47
  export { Quiz, QuizAlternative, QuizConnectDots, QuizContent, QuizDissertative, QuizFooter, QuizHeader, QuizHeaderResult, QuizImageQuestion, QuizListResult, QuizListResultByMateria, QuizMultipleChoice, QuizQuestionList, QuizResultHeaderTitle, QuizResultPerformance, QuizResultTitle, QuizTitle, QuizTrueOrFalse, getStatusBadge } from './Quiz/index.js';
48
48
  export { ANSWER_STATUS, Activity, Lesson, QUESTION_DIFFICULTY, QUESTION_STATUS, QUESTION_TYPE, Question, QuestionResult, QuizState, SUBTYPE_ENUM, Simulated, UserAnswerItem, useQuizStore } from './Quiz/useQuizStore/index.js';
49
49
  export { default as LoadingModal } from './LoadingModal/index.js';
50
- import { N as NotificationApiClient, a as Notification, F as FetchNotificationsParams, b as NotificationGroup } from './NotificationCard-IYDURfYp.js';
51
- export { B as BackendNotification, g as BackendNotificationsResponse, c as NotificationCard, e as NotificationEntityType, d as NotificationItem, f as NotificationType, h as NotificationsResponse } from './NotificationCard-IYDURfYp.js';
50
+ import { N as NotificationApiClient, a as Notification, F as FetchNotificationsParams, b as NotificationGroup, c as NotificationEntityType, d as NotificationType } from './NotificationCard-kGUKNOqT.js';
51
+ export { B as BackendNotification, g as BackendNotificationsResponse, e as NotificationCard, f as NotificationItem, h as NotificationsResponse } from './NotificationCard-kGUKNOqT.js';
52
52
  import 'react/jsx-runtime';
53
53
 
54
54
  /**
@@ -259,4 +259,129 @@ declare const createUseNotificationStore: (apiClient: NotificationApiClient) =>
259
259
  };
260
260
  }>;
261
261
 
262
- export { CheckboxList, CheckboxListItem, FetchNotificationsParams, Notification, type NotificationActions, NotificationApiClient, NotificationGroup, type NotificationState, type NotificationStore, createNotificationStore, createUseNotificationStore, formatTimeAgo };
262
+ /**
263
+ * Create a comprehensive notifications hook with formatting and navigation
264
+ * This hook provides all notification functionality in a single interface
265
+ *
266
+ * @param apiClient - API client instance for notifications
267
+ * @returns Hook with notification state, actions, and utilities
268
+ */
269
+ declare const createUseNotifications: (apiClient: NotificationApiClient) => () => {
270
+ notifications: Notification[];
271
+ unreadCount: number;
272
+ loading: boolean;
273
+ error: string | null;
274
+ hasMore: boolean;
275
+ currentPage: number;
276
+ fetchNotifications: (params?: FetchNotificationsParams) => Promise<void>;
277
+ markAsRead: (id: string) => Promise<void>;
278
+ markAllAsRead: () => Promise<void>;
279
+ deleteNotification: (id: string) => Promise<void>;
280
+ clearNotifications: () => void;
281
+ resetError: () => void;
282
+ markAsReadAndNavigate: (id: string, entityType?: string, entityId?: string) => Promise<void>;
283
+ refreshNotifications: () => Promise<void>;
284
+ handleNavigate: (entityType?: string, entityId?: string) => void;
285
+ getActionLabel: (entityType?: string) => string | undefined;
286
+ getGroupedNotifications: () => NotificationGroup[];
287
+ getFormattedGroupedNotifications: () => {
288
+ notifications: {
289
+ time: string;
290
+ entityType: NotificationEntityType | undefined;
291
+ entityId: string | undefined;
292
+ id: string;
293
+ title: string;
294
+ message: string;
295
+ type: NotificationType;
296
+ isRead: boolean;
297
+ createdAt: Date;
298
+ sender?: {
299
+ id: string;
300
+ user: {
301
+ id: string;
302
+ name: string;
303
+ email: string;
304
+ };
305
+ } | null;
306
+ activity?: {
307
+ id: string;
308
+ title: string;
309
+ type: string;
310
+ } | null;
311
+ goal?: {
312
+ id: string;
313
+ title: string;
314
+ } | null;
315
+ }[];
316
+ label: string;
317
+ }[];
318
+ };
319
+ /**
320
+ * Create a pre-configured notifications hook
321
+ * This is a convenience function that returns a hook ready to use
322
+ *
323
+ * @param apiClient - API client instance for notifications
324
+ * @returns Pre-configured useNotifications hook
325
+ *
326
+ * @example
327
+ * // In your app setup
328
+ * import { createNotificationsHook } from 'analytica-frontend-lib';
329
+ * import api from './services/api';
330
+ *
331
+ * export const useNotifications = createNotificationsHook(api);
332
+ *
333
+ * // Then use directly in components
334
+ * const { unreadCount, fetchNotifications } = useNotifications();
335
+ */
336
+ declare const createNotificationsHook: (apiClient: NotificationApiClient) => () => {
337
+ notifications: Notification[];
338
+ unreadCount: number;
339
+ loading: boolean;
340
+ error: string | null;
341
+ hasMore: boolean;
342
+ currentPage: number;
343
+ fetchNotifications: (params?: FetchNotificationsParams) => Promise<void>;
344
+ markAsRead: (id: string) => Promise<void>;
345
+ markAllAsRead: () => Promise<void>;
346
+ deleteNotification: (id: string) => Promise<void>;
347
+ clearNotifications: () => void;
348
+ resetError: () => void;
349
+ markAsReadAndNavigate: (id: string, entityType?: string, entityId?: string) => Promise<void>;
350
+ refreshNotifications: () => Promise<void>;
351
+ handleNavigate: (entityType?: string, entityId?: string) => void;
352
+ getActionLabel: (entityType?: string) => string | undefined;
353
+ getGroupedNotifications: () => NotificationGroup[];
354
+ getFormattedGroupedNotifications: () => {
355
+ notifications: {
356
+ time: string;
357
+ entityType: NotificationEntityType | undefined;
358
+ entityId: string | undefined;
359
+ id: string;
360
+ title: string;
361
+ message: string;
362
+ type: NotificationType;
363
+ isRead: boolean;
364
+ createdAt: Date;
365
+ sender?: {
366
+ id: string;
367
+ user: {
368
+ id: string;
369
+ name: string;
370
+ email: string;
371
+ };
372
+ } | null;
373
+ activity?: {
374
+ id: string;
375
+ title: string;
376
+ type: string;
377
+ } | null;
378
+ goal?: {
379
+ id: string;
380
+ title: string;
381
+ } | null;
382
+ }[];
383
+ label: string;
384
+ }[];
385
+ };
386
+
387
+ export { CheckboxList, CheckboxListItem, FetchNotificationsParams, Notification, type NotificationActions, NotificationApiClient, NotificationEntityType, NotificationGroup, type NotificationState, type NotificationStore, NotificationType, createNotificationStore, createNotificationsHook, createUseNotificationStore, createUseNotifications, formatTimeAgo };
package/dist/index.js CHANGED
@@ -133,7 +133,9 @@ __export(src_exports, {
133
133
  VideoPlayer: () => VideoPlayer_default,
134
134
  Whiteboard: () => Whiteboard_default,
135
135
  createNotificationStore: () => createNotificationStore,
136
+ createNotificationsHook: () => createNotificationsHook,
136
137
  createUseNotificationStore: () => createUseNotificationStore,
138
+ createUseNotifications: () => createUseNotifications,
137
139
  createZustandAuthAdapter: () => createZustandAuthAdapter,
138
140
  formatTimeAgo: () => formatTimeAgo,
139
141
  getDeviceType: () => getDeviceType,
@@ -10875,6 +10877,116 @@ var NotificationCard_default = NotificationCard;
10875
10877
  var createUseNotificationStore = (apiClient) => {
10876
10878
  return createNotificationStore(apiClient);
10877
10879
  };
10880
+
10881
+ // src/hooks/useNotifications.ts
10882
+ var import_react31 = require("react");
10883
+ var createUseNotifications = (apiClient) => {
10884
+ const useNotificationStore = createUseNotificationStore(apiClient);
10885
+ return () => {
10886
+ const {
10887
+ notifications,
10888
+ unreadCount,
10889
+ loading,
10890
+ error,
10891
+ hasMore,
10892
+ currentPage,
10893
+ fetchNotifications,
10894
+ markAsRead,
10895
+ markAllAsRead,
10896
+ deleteNotification,
10897
+ clearNotifications,
10898
+ resetError,
10899
+ getGroupedNotifications
10900
+ } = useNotificationStore();
10901
+ const handleNavigate = (0, import_react31.useCallback)(
10902
+ (entityType, entityId) => {
10903
+ if (entityType && entityId) {
10904
+ switch (entityType.toUpperCase()) {
10905
+ case "ACTIVITY" /* ACTIVITY */:
10906
+ window.location.href = `/atividades/${entityId}`;
10907
+ break;
10908
+ case "GOAL" /* GOAL */:
10909
+ window.location.href = `/painel/trilhas/${entityId}`;
10910
+ break;
10911
+ default:
10912
+ break;
10913
+ }
10914
+ }
10915
+ },
10916
+ []
10917
+ );
10918
+ const getActionLabel = (0, import_react31.useCallback)(
10919
+ (entityType) => {
10920
+ if (!entityType) return void 0;
10921
+ switch (entityType.toUpperCase()) {
10922
+ case "ACTIVITY" /* ACTIVITY */:
10923
+ return "Ver atividade";
10924
+ case "GOAL" /* GOAL */:
10925
+ return "Ver meta";
10926
+ default:
10927
+ return void 0;
10928
+ }
10929
+ },
10930
+ []
10931
+ );
10932
+ const markAsReadAndNavigate = (0, import_react31.useCallback)(
10933
+ async (id, entityType, entityId) => {
10934
+ await markAsRead(id);
10935
+ if (entityType && entityId) {
10936
+ handleNavigate(entityType, entityId);
10937
+ }
10938
+ },
10939
+ [markAsRead, handleNavigate]
10940
+ );
10941
+ const refreshNotifications = (0, import_react31.useCallback)(async () => {
10942
+ resetError();
10943
+ await fetchNotifications();
10944
+ }, [resetError, fetchNotifications]);
10945
+ const formatNotification = (0, import_react31.useCallback)(
10946
+ (notification) => ({
10947
+ ...notification,
10948
+ time: formatTimeAgo(notification.createdAt),
10949
+ entityType: notification.entityType || void 0,
10950
+ entityId: notification.entityId || void 0
10951
+ }),
10952
+ []
10953
+ );
10954
+ const getFormattedGroupedNotifications = (0, import_react31.useCallback)(() => {
10955
+ const groups = getGroupedNotifications();
10956
+ return groups.map((group) => ({
10957
+ ...group,
10958
+ notifications: group.notifications.map(formatNotification)
10959
+ }));
10960
+ }, [getGroupedNotifications, formatNotification]);
10961
+ return {
10962
+ // State
10963
+ notifications,
10964
+ unreadCount,
10965
+ loading,
10966
+ error,
10967
+ hasMore,
10968
+ currentPage,
10969
+ // Actions
10970
+ fetchNotifications,
10971
+ markAsRead,
10972
+ markAllAsRead,
10973
+ deleteNotification,
10974
+ clearNotifications,
10975
+ resetError,
10976
+ markAsReadAndNavigate,
10977
+ refreshNotifications,
10978
+ // Navigation
10979
+ handleNavigate,
10980
+ // Helpers
10981
+ getActionLabel,
10982
+ getGroupedNotifications,
10983
+ getFormattedGroupedNotifications
10984
+ };
10985
+ };
10986
+ };
10987
+ var createNotificationsHook = (apiClient) => {
10988
+ return createUseNotifications(apiClient);
10989
+ };
10878
10990
  // Annotate the CommonJS export names for ESM import in node:
10879
10991
  0 && (module.exports = {
10880
10992
  ANSWER_STATUS,
@@ -10980,7 +11092,9 @@ var createUseNotificationStore = (apiClient) => {
10980
11092
  VideoPlayer,
10981
11093
  Whiteboard,
10982
11094
  createNotificationStore,
11095
+ createNotificationsHook,
10983
11096
  createUseNotificationStore,
11097
+ createUseNotifications,
10984
11098
  createZustandAuthAdapter,
10985
11099
  formatTimeAgo,
10986
11100
  getDeviceType,