@greatapps/common 1.1.71 → 1.1.75

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 (56) hide show
  1. package/dist/components/layouts/AppNavBar.mjs +0 -2
  2. package/dist/components/layouts/AppNavBar.mjs.map +1 -1
  3. package/dist/components/layouts/NotificationsPopover.mjs +24 -14
  4. package/dist/components/layouts/NotificationsPopover.mjs.map +1 -1
  5. package/dist/components/pages/notifications/Notifications.mjs +106 -0
  6. package/dist/components/pages/notifications/Notifications.mjs.map +1 -0
  7. package/dist/components/widgets/notifications/NotificationCard.mjs +53 -0
  8. package/dist/components/widgets/notifications/NotificationCard.mjs.map +1 -0
  9. package/dist/index.mjs +177 -47
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/modules/auth/actions/login.action.mjs +1 -1
  12. package/dist/modules/auth/actions/login.action.mjs.map +1 -1
  13. package/dist/modules/auth/hooks/login.hook.mjs +5 -1
  14. package/dist/modules/auth/hooks/login.hook.mjs.map +1 -1
  15. package/dist/modules/auth/hooks/useUserQuery.mjs +2 -1
  16. package/dist/modules/auth/hooks/useUserQuery.mjs.map +1 -1
  17. package/dist/modules/auth/services/auth.service.mjs +2 -2
  18. package/dist/modules/auth/services/auth.service.mjs.map +1 -1
  19. package/dist/modules/users/action/list-messages.action.mjs +9 -0
  20. package/dist/modules/users/action/list-messages.action.mjs.map +1 -0
  21. package/dist/modules/users/action/mark-all-messages-as-read.action.mjs +9 -0
  22. package/dist/modules/users/action/mark-all-messages-as-read.action.mjs.map +1 -0
  23. package/dist/modules/users/action/mark-message-as-read.action.mjs +9 -0
  24. package/dist/modules/users/action/mark-message-as-read.action.mjs.map +1 -0
  25. package/dist/modules/users/hooks/messages.hook.mjs +38 -0
  26. package/dist/modules/users/hooks/messages.hook.mjs.map +1 -0
  27. package/dist/modules/users/schema/messages.schema.mjs +21 -0
  28. package/dist/modules/users/schema/messages.schema.mjs.map +1 -0
  29. package/dist/modules/users/services/messages.service.mjs +35 -0
  30. package/dist/modules/users/services/messages.service.mjs.map +1 -0
  31. package/dist/providers/auth.provider.mjs +3 -5
  32. package/dist/providers/auth.provider.mjs.map +1 -1
  33. package/dist/utils/safeServerAction.mjs +22 -0
  34. package/dist/utils/safeServerAction.mjs.map +1 -0
  35. package/package.json +1 -1
  36. package/src/components/layouts/AppNavBar.tsx +0 -4
  37. package/src/components/layouts/NotificationsPopover.tsx +27 -24
  38. package/src/components/pages/notifications/Notifications.tsx +106 -0
  39. package/src/components/widgets/notifications/NotificationCard.tsx +66 -0
  40. package/src/index.ts +267 -117
  41. package/src/modules/auth/actions/login.action.ts +1 -1
  42. package/src/modules/auth/hooks/login.hook.tsx +6 -1
  43. package/src/modules/auth/hooks/useUserQuery.ts +2 -1
  44. package/src/modules/auth/schema.ts +6 -4
  45. package/src/modules/auth/services/auth.service.ts +2 -2
  46. package/src/modules/users/action/list-messages.action.ts +10 -0
  47. package/src/modules/users/action/mark-all-messages-as-read.action.ts +8 -0
  48. package/src/modules/users/action/mark-message-as-read.action.ts +8 -0
  49. package/src/modules/users/hooks/messages.hook.ts +39 -0
  50. package/src/modules/users/schema/messages.schema.ts +47 -0
  51. package/src/modules/users/services/messages.service.ts +48 -0
  52. package/src/providers/auth.provider.tsx +6 -9
  53. package/src/utils/safeServerAction.ts +27 -0
  54. package/dist/components/layouts/NotificationItem.mjs +0 -14
  55. package/dist/components/layouts/NotificationItem.mjs.map +0 -1
  56. package/src/components/layouts/NotificationItem.tsx +0 -26
@@ -0,0 +1,47 @@
1
+ import { z } from 'zod';
2
+
3
+ export const MessageSchema = z.object({
4
+ id: z.string(),
5
+ deleted: z.number(),
6
+ datetime_alt: z.string().nullable(),
7
+ datetime_del: z.string().nullable(),
8
+ datetime_add: z.string(),
9
+ id_wl: z.number(),
10
+ id_account: z.number(),
11
+ id_user: z.number(),
12
+ status: z.number().nullable(),
13
+ type: z.string(),
14
+ subject: z.string(),
15
+ message: z.string(),
16
+ to: z.string(),
17
+ url: z.string(),
18
+ });
19
+
20
+ export type Message = z.infer<typeof MessageSchema>;
21
+
22
+ export interface FindMessagesParams {
23
+ id_user: number;
24
+ type: string;
25
+ limit: number;
26
+ page: number;
27
+ status: number;
28
+ order: 'asc' | 'desc';
29
+ }
30
+
31
+ export interface ListMessagesApiResponse {
32
+ status: 0 | 1;
33
+ total: number;
34
+ data: Message[];
35
+ totalUnread: number;
36
+ message?: string;
37
+ }
38
+
39
+ export interface MarkAsReadApiResponse {
40
+ status: 0 | 1;
41
+ message?: string;
42
+ }
43
+
44
+ export interface MarkAllAsReadApiResponse {
45
+ status: 0 | 1;
46
+ message?: string;
47
+ }
@@ -0,0 +1,48 @@
1
+ import 'server-only';
2
+
3
+ import { api } from '../../../infra/api/client';
4
+ import { buildQueryParams } from '../../../infra/utils/params';
5
+ import { getUserContext } from '../../auth/utils/get-user-context';
6
+ import {
7
+ FindMessagesParams,
8
+ ListMessagesApiResponse,
9
+ MarkAsReadApiResponse,
10
+ MarkAllAsReadApiResponse,
11
+ } from '../schema/messages.schema';
12
+
13
+ class MessagesService {
14
+ async listMessages(
15
+ params?: Partial<FindMessagesParams>
16
+ ): Promise<ListMessagesApiResponse> {
17
+ const { id_account, id_user } = await getUserContext();
18
+
19
+ const query = buildQueryParams({
20
+ id_account,
21
+ id_user,
22
+ type: 'notification',
23
+ limit: 20,
24
+ page: 1,
25
+ order: 'desc',
26
+ ...params,
27
+ });
28
+
29
+ const url = `/accounts/${id_account}/messages${query ? `?${query}` : ''}`;
30
+ return api.apps.get<ListMessagesApiResponse>(url);
31
+ }
32
+
33
+ async markAsRead(messageId: string): Promise<MarkAsReadApiResponse> {
34
+ const { id_account } = await getUserContext();
35
+
36
+ const url = `/accounts/${id_account}/messages/${messageId}/action/markAsRead`;
37
+ return api.apps.put<MarkAsReadApiResponse>(url);
38
+ }
39
+
40
+ async markAllAsRead(): Promise<MarkAllAsReadApiResponse> {
41
+ const { id_account, id_user } = await getUserContext();
42
+
43
+ const url = `/accounts/${id_account}/messages/action/markAllAsRead`;
44
+ return api.apps.put<MarkAllAsReadApiResponse>(url, { id_user });
45
+ }
46
+ }
47
+
48
+ export const messagesService = new MessagesService();
@@ -23,9 +23,9 @@ import {
23
23
  } from "../modules/auth/schema";
24
24
 
25
25
  export type LoginResult =
26
- | { status: "success" }
27
- | { status: "two_factor_required"; cookie: string }
28
- | { status: "error"; message: string };
26
+ | { result: "success" }
27
+ | { result: "two_factor_required"; cookie: string }
28
+ | { result: "error"; message: string };
29
29
  import {
30
30
  useCurrentAccount,
31
31
  useInvalidateAccount,
@@ -75,11 +75,8 @@ export function AuthProvider({ children }: AuthProviderProps) {
75
75
  async (credentials: LoginRequest): Promise<LoginResult> => {
76
76
  const data = await loginMutate(credentials);
77
77
 
78
- if (data.status == 0)
79
- return { status: "error", message: data.message || "Login failed" };
80
-
81
- if (data.twoFactorRequired) {
82
- return { status: "two_factor_required", cookie: data.cookie };
78
+ if (data.result === "two_factor_required") {
79
+ return { result: "two_factor_required", cookie: data.cookie };
83
80
  }
84
81
 
85
82
  invalidateUser();
@@ -87,7 +84,7 @@ export function AuthProvider({ children }: AuthProviderProps) {
87
84
 
88
85
  setUserData(data.user);
89
86
 
90
- return { status: "success" };
87
+ return { result: "success" };
91
88
  },
92
89
  [setUserData, invalidateUser, invalidateAccount]
93
90
  );
@@ -0,0 +1,27 @@
1
+ export class ServerActionError extends Error {
2
+ status: number;
3
+
4
+ constructor(message: string, status: number) {
5
+ super(message);
6
+ this.name = 'ServerActionError';
7
+ this.status = status;
8
+ }
9
+ }
10
+
11
+ export async function safeServerAction<
12
+ TArgs extends any[],
13
+ TResult extends Record<string, any>,
14
+ >(
15
+ action: (...args: TArgs) => Promise<TResult>,
16
+ ...args: TArgs
17
+ ): Promise<Omit<TResult, 'error'>> {
18
+ const result: TResult = await action(...args);
19
+
20
+ if (result.status === 0 || result.result === 'error' || result.error) {
21
+ const msg = result.message || result.error || 'Erro na ação';
22
+ throw new ServerActionError(msg, result.status || 0);
23
+ }
24
+
25
+ const { error, ...successData } = result;
26
+ return successData as Omit<TResult, 'error'>;
27
+ }
@@ -1,14 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- function NotificationItem({ icon, iconBgColor, title, time, showBorder = true }) {
3
- return /* @__PURE__ */ jsxs("div", { className: `flex items-center gap-3 px-4 py-5 ${showBorder ? "border-b border-gray-200" : ""}`, children: [
4
- /* @__PURE__ */ jsx("div", { className: `flex items-center justify-center rounded-full ${iconBgColor} size-10`, children: icon }),
5
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5", children: [
6
- /* @__PURE__ */ jsx("span", { className: "paragraph-small-semibold text-gray-950", children: title }),
7
- /* @__PURE__ */ jsx("span", { className: "paragraph-xsmall-medium text-gray-500", children: time })
8
- ] })
9
- ] });
10
- }
11
- export {
12
- NotificationItem
13
- };
14
- //# sourceMappingURL=NotificationItem.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/components/layouts/NotificationItem.tsx"],"sourcesContent":["import { ReactNode } from \"react\";\r\n\r\ntype NotificationItemProps = {\r\n icon: ReactNode;\r\n iconBgColor: string;\r\n title: string;\r\n time: string;\r\n showBorder?: boolean;\r\n}\r\n\r\nfunction NotificationItem({ icon, iconBgColor, title, time, showBorder = true }: NotificationItemProps) {\r\n return (\r\n <div className={`flex items-center gap-3 px-4 py-5 ${showBorder ? 'border-b border-gray-200' : ''}`}>\r\n <div className={`flex items-center justify-center rounded-full ${iconBgColor} size-10`}>\r\n {icon}\r\n </div>\r\n <div className=\"flex flex-col gap-1.5\">\r\n <span className=\"paragraph-small-semibold text-gray-950\">{title}</span>\r\n <span className=\"paragraph-xsmall-medium text-gray-500\">{time}</span>\r\n </div>\r\n </div>\r\n );\r\n}\r\n\r\nexport { NotificationItem };\r\nexport type { NotificationItemProps };\r\n"],"mappings":"AAaY,cAGA,YAHA;AAHZ,SAAS,iBAAiB,EAAE,MAAM,aAAa,OAAO,MAAM,aAAa,KAAK,GAA0B;AACpG,SACI,qBAAC,SAAI,WAAW,qCAAqC,aAAa,6BAA6B,EAAE,IAC7F;AAAA,wBAAC,SAAI,WAAW,iDAAiD,WAAW,YACvE,gBACL;AAAA,IACA,qBAAC,SAAI,WAAU,yBACX;AAAA,0BAAC,UAAK,WAAU,0CAA0C,iBAAM;AAAA,MAChE,oBAAC,UAAK,WAAU,yCAAyC,gBAAK;AAAA,OAClE;AAAA,KACJ;AAER;","names":[]}
@@ -1,26 +0,0 @@
1
- import { ReactNode } from "react";
2
-
3
- type NotificationItemProps = {
4
- icon: ReactNode;
5
- iconBgColor: string;
6
- title: string;
7
- time: string;
8
- showBorder?: boolean;
9
- }
10
-
11
- function NotificationItem({ icon, iconBgColor, title, time, showBorder = true }: NotificationItemProps) {
12
- return (
13
- <div className={`flex items-center gap-3 px-4 py-5 ${showBorder ? 'border-b border-gray-200' : ''}`}>
14
- <div className={`flex items-center justify-center rounded-full ${iconBgColor} size-10`}>
15
- {icon}
16
- </div>
17
- <div className="flex flex-col gap-1.5">
18
- <span className="paragraph-small-semibold text-gray-950">{title}</span>
19
- <span className="paragraph-xsmall-medium text-gray-500">{time}</span>
20
- </div>
21
- </div>
22
- );
23
- }
24
-
25
- export { NotificationItem };
26
- export type { NotificationItemProps };