@greatapps/common 1.1.70 → 1.1.73
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.
- package/dist/components/account/AccountModals.mjs +18 -0
- package/dist/components/account/AccountModals.mjs.map +1 -0
- package/dist/components/account/ConfigurationsMyAccountModal.mjs +132 -0
- package/dist/components/account/ConfigurationsMyAccountModal.mjs.map +1 -0
- package/dist/components/account/ConfirmDeleteAccountModal.mjs +45 -0
- package/dist/components/account/ConfirmDeleteAccountModal.mjs.map +1 -0
- package/dist/components/account/ConfirmGlobalPreferencesModal.mjs +45 -0
- package/dist/components/account/ConfirmGlobalPreferencesModal.mjs.map +1 -0
- package/dist/components/account/DeleteAccountModal.mjs +123 -0
- package/dist/components/account/DeleteAccountModal.mjs.map +1 -0
- package/dist/components/account/DisableTwoFactorAuthModal.mjs +67 -0
- package/dist/components/account/DisableTwoFactorAuthModal.mjs.map +1 -0
- package/dist/components/account/IsntPossibleDeleteAccountModal.mjs +42 -0
- package/dist/components/account/IsntPossibleDeleteAccountModal.mjs.map +1 -0
- package/dist/components/account/TwoFactorAuthModal.mjs +190 -0
- package/dist/components/account/TwoFactorAuthModal.mjs.map +1 -0
- package/dist/components/account/constants.mjs +29 -0
- package/dist/components/account/constants.mjs.map +1 -0
- package/dist/components/handlers/SearchParamsHandler.mjs +24 -0
- package/dist/components/handlers/SearchParamsHandler.mjs.map +1 -0
- package/dist/components/layouts/AppMobileNavBar.mjs +53 -0
- package/dist/components/layouts/AppMobileNavBar.mjs.map +1 -0
- package/dist/components/layouts/AppNavBar.mjs +73 -0
- package/dist/components/layouts/AppNavBar.mjs.map +1 -0
- package/dist/components/layouts/MainLayout.mjs +60 -0
- package/dist/components/layouts/MainLayout.mjs.map +1 -0
- package/dist/components/layouts/MdSideBarNavigation.mjs +39 -0
- package/dist/components/layouts/MdSideBarNavigation.mjs.map +1 -0
- package/dist/components/layouts/NavBar.mjs +64 -0
- package/dist/components/layouts/NavBar.mjs.map +1 -0
- package/dist/components/layouts/NavBarItem.mjs +23 -0
- package/dist/components/layouts/NavBarItem.mjs.map +1 -0
- package/dist/components/layouts/NotificationItem.mjs +11 -0
- package/dist/components/layouts/NotificationItem.mjs.map +1 -0
- package/dist/components/layouts/NotificationsPopover.mjs +96 -0
- package/dist/components/layouts/NotificationsPopover.mjs.map +1 -0
- package/dist/components/layouts/ProfilePopover.mjs +150 -0
- package/dist/components/layouts/ProfilePopover.mjs.map +1 -0
- package/dist/components/layouts/SideBarNavigation.mjs +22 -0
- package/dist/components/layouts/SideBarNavigation.mjs.map +1 -0
- package/dist/components/layouts/UsersSelectorPopover.mjs +236 -0
- package/dist/components/layouts/UsersSelectorPopover.mjs.map +1 -0
- package/dist/components/modals/ModalManager.mjs +19 -0
- package/dist/components/modals/ModalManager.mjs.map +1 -0
- package/dist/components/modals/Modals.mjs +20 -0
- package/dist/components/modals/Modals.mjs.map +1 -0
- package/dist/enums/AccountSectionType.mjs +11 -0
- package/dist/enums/AccountSectionType.mjs.map +1 -0
- package/dist/hooks/copy-to-clipboard.hook.mjs +39 -0
- package/dist/hooks/copy-to-clipboard.hook.mjs.map +1 -0
- package/dist/hooks/useCountdownTimer.mjs +29 -0
- package/dist/hooks/useCountdownTimer.mjs.map +1 -0
- package/dist/hooks/useIsMobile.mjs +18 -0
- package/dist/hooks/useIsMobile.mjs.map +1 -0
- package/dist/hooks/usePasswordVisibility.mjs +13 -0
- package/dist/hooks/usePasswordVisibility.mjs.map +1 -0
- package/dist/index.mjs +434 -0
- package/dist/index.mjs.map +1 -0
- package/dist/infra/api/client.mjs +122 -0
- package/dist/infra/api/client.mjs.map +1 -0
- package/dist/infra/api/types.mjs +31 -0
- package/dist/infra/api/types.mjs.map +1 -0
- package/dist/infra/utils/client-info.mjs +27 -0
- package/dist/infra/utils/client-info.mjs.map +1 -0
- package/dist/infra/utils/clsx.mjs +9 -0
- package/dist/infra/utils/clsx.mjs.map +1 -0
- package/dist/infra/utils/params.mjs +21 -0
- package/dist/infra/utils/params.mjs.map +1 -0
- package/dist/infra/utils/parser.mjs +24 -0
- package/dist/infra/utils/parser.mjs.map +1 -0
- package/dist/infra/utils/percentage.mjs +20 -0
- package/dist/infra/utils/percentage.mjs.map +1 -0
- package/dist/middlewares/chain.mjs +37 -0
- package/dist/middlewares/chain.mjs.map +1 -0
- package/dist/middlewares/create-auth-middleware.mjs +28 -0
- package/dist/middlewares/create-auth-middleware.mjs.map +1 -0
- package/dist/middlewares/types.mjs +11 -0
- package/dist/middlewares/types.mjs.map +1 -0
- package/dist/modules/accounts/types.mjs +1 -0
- package/dist/modules/accounts/types.mjs.map +1 -0
- package/dist/modules/auth/actions/login.action.mjs +1 -1
- package/dist/modules/auth/actions/login.action.mjs.map +1 -1
- package/dist/modules/auth/hooks/login.hook.mjs +5 -1
- package/dist/modules/auth/hooks/login.hook.mjs.map +1 -1
- package/dist/modules/auth/hooks/useUserQuery.mjs +2 -1
- package/dist/modules/auth/hooks/useUserQuery.mjs.map +1 -1
- package/dist/modules/auth/schema.mjs +1 -0
- package/dist/modules/auth/schema.mjs.map +1 -0
- package/dist/modules/auth/services/auth.service.mjs +2 -2
- package/dist/modules/auth/services/auth.service.mjs.map +1 -1
- package/dist/modules/ia-credits/types.mjs +25 -0
- package/dist/modules/ia-credits/types.mjs.map +1 -0
- package/dist/modules/projects/types.mjs +22 -0
- package/dist/modules/projects/types.mjs.map +1 -0
- package/dist/modules/subscriptions/types.mjs +57 -0
- package/dist/modules/subscriptions/types.mjs.map +1 -0
- package/dist/modules/users/action/list-messages.action.mjs +9 -0
- package/dist/modules/users/action/list-messages.action.mjs.map +1 -0
- package/dist/modules/users/action/mark-all-messages-as-read.action.mjs +9 -0
- package/dist/modules/users/action/mark-all-messages-as-read.action.mjs.map +1 -0
- package/dist/modules/users/action/mark-message-as-read.action.mjs +9 -0
- package/dist/modules/users/action/mark-message-as-read.action.mjs.map +1 -0
- package/dist/modules/users/hooks/messages.hook.mjs +38 -0
- package/dist/modules/users/hooks/messages.hook.mjs.map +1 -0
- package/dist/modules/users/schema/messages.schema.mjs +21 -0
- package/dist/modules/users/schema/messages.schema.mjs.map +1 -0
- package/dist/modules/users/schema.mjs +11 -0
- package/dist/modules/users/schema.mjs.map +1 -0
- package/dist/modules/users/services/messages.service.mjs +35 -0
- package/dist/modules/users/services/messages.service.mjs.map +1 -0
- package/dist/modules/whitelabel/schema.mjs +1 -0
- package/dist/modules/whitelabel/schema.mjs.map +1 -0
- package/dist/providers/auth.provider.mjs +98 -0
- package/dist/providers/auth.provider.mjs.map +1 -0
- package/dist/providers/query.provider.mjs +41 -0
- package/dist/providers/query.provider.mjs.map +1 -0
- package/dist/providers/whitelabel.provider.mjs +34 -0
- package/dist/providers/whitelabel.provider.mjs.map +1 -0
- package/dist/server.mjs +74 -0
- package/dist/server.mjs.map +1 -0
- package/dist/store/useAccountModals.mjs +18 -0
- package/dist/store/useAccountModals.mjs.map +1 -0
- package/dist/store/useMdSidebarStore.mjs +11 -0
- package/dist/store/useMdSidebarStore.mjs.map +1 -0
- package/dist/store/useModalManager.mjs +75 -0
- package/dist/store/useModalManager.mjs.map +1 -0
- package/dist/utils/browser/clipboard.mjs +36 -0
- package/dist/utils/browser/clipboard.mjs.map +1 -0
- package/dist/utils/file/index.mjs +9 -0
- package/dist/utils/file/index.mjs.map +1 -0
- package/dist/utils/format/masks.mjs +56 -0
- package/dist/utils/format/masks.mjs.map +1 -0
- package/dist/utils/intl/locales.mjs +12 -0
- package/dist/utils/intl/locales.mjs.map +1 -0
- package/dist/utils/safeServerAction.mjs +22 -0
- package/dist/utils/safeServerAction.mjs.map +1 -0
- package/dist/utils/validators/account.mjs +26 -0
- package/dist/utils/validators/account.mjs.map +1 -0
- package/dist/utils/validators/common.mjs +47 -0
- package/dist/utils/validators/common.mjs.map +1 -0
- package/package.json +1 -1
- package/src/components/layouts/AppNavBar.tsx +0 -4
- package/src/components/layouts/NotificationItem.tsx +2 -2
- package/src/components/layouts/NotificationsPopover.tsx +25 -22
- package/src/index.ts +267 -117
- package/src/modules/auth/actions/login.action.ts +1 -1
- package/src/modules/auth/hooks/login.hook.tsx +6 -1
- package/src/modules/auth/hooks/useUserQuery.ts +2 -1
- package/src/modules/auth/schema.ts +6 -4
- package/src/modules/auth/services/auth.service.ts +2 -2
- package/src/modules/users/action/list-messages.action.ts +10 -0
- package/src/modules/users/action/mark-all-messages-as-read.action.ts +8 -0
- package/src/modules/users/action/mark-message-as-read.action.ts +8 -0
- package/src/modules/users/hooks/messages.hook.ts +39 -0
- package/src/modules/users/schema/messages.schema.ts +46 -0
- package/src/modules/users/services/messages.service.ts +48 -0
- package/src/providers/auth.provider.tsx +6 -9
- package/src/utils/safeServerAction.ts +27 -0
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
order: 'asc' | 'desc';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface ListMessagesApiResponse {
|
|
31
|
+
status: 0 | 1;
|
|
32
|
+
total: number;
|
|
33
|
+
data: Message[];
|
|
34
|
+
totalUnread: number;
|
|
35
|
+
message?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface MarkAsReadApiResponse {
|
|
39
|
+
status: 0 | 1;
|
|
40
|
+
message?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface MarkAllAsReadApiResponse {
|
|
44
|
+
status: 0 | 1;
|
|
45
|
+
message?: string;
|
|
46
|
+
}
|
|
@@ -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
|
-
| {
|
|
27
|
-
| {
|
|
28
|
-
| {
|
|
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.
|
|
79
|
-
return {
|
|
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 {
|
|
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
|
+
}
|