@greatapps/common 1.1.98 → 1.1.100
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/hooks/useTwoFactorAuthForm.mjs +5 -13
- package/dist/components/account/hooks/useTwoFactorAuthForm.mjs.map +1 -1
- package/dist/components/account/sections/MyProfileSection.mjs +30 -19
- package/dist/components/account/sections/MyProfileSection.mjs.map +1 -1
- package/dist/components/account/sections/PreferencesSection.mjs +11 -10
- package/dist/components/account/sections/PreferencesSection.mjs.map +1 -1
- package/dist/index.mjs +3 -1
- package/dist/index.mjs.map +1 -1
- package/dist/modules/accounts/actions/account-management.action.mjs +36 -168
- package/dist/modules/accounts/actions/account-management.action.mjs.map +1 -1
- package/dist/modules/accounts/actions/find-current-account.action.mjs +3 -2
- package/dist/modules/accounts/actions/find-current-account.action.mjs.map +1 -1
- package/dist/modules/accounts/actions/list-currencies.action.mjs +3 -2
- package/dist/modules/accounts/actions/list-currencies.action.mjs.map +1 -1
- package/dist/modules/accounts/actions/list-timezones.action.mjs +3 -2
- package/dist/modules/accounts/actions/list-timezones.action.mjs.map +1 -1
- package/dist/modules/accounts/hooks/current-account.hook.mjs +2 -1
- package/dist/modules/accounts/hooks/current-account.hook.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useAccountManagement.mjs +8 -5
- package/dist/modules/accounts/hooks/useAccountManagement.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useCurrencies.mjs +2 -1
- package/dist/modules/accounts/hooks/useCurrencies.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useTimezones.mjs +2 -1
- package/dist/modules/accounts/hooks/useTimezones.mjs.map +1 -1
- package/dist/modules/auth/actions/logout.action.mjs +6 -3
- package/dist/modules/auth/actions/logout.action.mjs.map +1 -1
- package/dist/modules/auth/actions/register.action.mjs +6 -3
- package/dist/modules/auth/actions/register.action.mjs.map +1 -1
- package/dist/modules/auth/actions/verify-two-factor.action.mjs +5 -10
- package/dist/modules/auth/actions/verify-two-factor.action.mjs.map +1 -1
- package/dist/modules/auth/hooks/logout.hook.mjs +2 -1
- package/dist/modules/auth/hooks/logout.hook.mjs.map +1 -1
- package/dist/modules/auth/hooks/register.hook.mjs +2 -1
- package/dist/modules/auth/hooks/register.hook.mjs.map +1 -1
- package/dist/modules/auth/hooks/useUserQuery.mjs +2 -2
- package/dist/modules/auth/hooks/useUserQuery.mjs.map +1 -1
- package/dist/modules/ia-credits/actions/list-ia-credits.action.mjs +3 -2
- package/dist/modules/ia-credits/actions/list-ia-credits.action.mjs.map +1 -1
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs +2 -1
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs.map +1 -1
- package/dist/modules/projects/actions/add-project-user.action.mjs +3 -2
- package/dist/modules/projects/actions/add-project-user.action.mjs.map +1 -1
- package/dist/modules/projects/actions/list-available-users.action.mjs +3 -2
- package/dist/modules/projects/actions/list-available-users.action.mjs.map +1 -1
- package/dist/modules/projects/actions/list-project-users.action.mjs +3 -2
- package/dist/modules/projects/actions/list-project-users.action.mjs.map +1 -1
- package/dist/modules/projects/actions/remove-project-user.action.mjs +3 -2
- package/dist/modules/projects/actions/remove-project-user.action.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-available-users.hook.mjs +8 -1
- package/dist/modules/projects/hooks/list-available-users.hook.mjs.map +1 -1
- package/dist/modules/projects/hooks/list-project-users.hook.mjs +8 -1
- package/dist/modules/projects/hooks/list-project-users.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/actions/list-subscriptions.action.mjs +3 -2
- package/dist/modules/subscriptions/actions/list-subscriptions.action.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs +5 -1
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs +2 -1
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs.map +1 -1
- package/dist/modules/users/action/find-user-by-id.action.mjs +3 -14
- package/dist/modules/users/action/find-user-by-id.action.mjs.map +1 -1
- package/dist/modules/users/action/list-messages.action.mjs +6 -2
- package/dist/modules/users/action/list-messages.action.mjs.map +1 -1
- package/dist/modules/users/action/mark-all-messages-as-read.action.mjs +3 -2
- package/dist/modules/users/action/mark-all-messages-as-read.action.mjs.map +1 -1
- package/dist/modules/users/action/mark-message-as-read.action.mjs +3 -2
- package/dist/modules/users/action/mark-message-as-read.action.mjs.map +1 -1
- package/dist/modules/users/hooks/messages.hook.mjs +11 -9
- package/dist/modules/users/hooks/messages.hook.mjs.map +1 -1
- package/dist/utils/safeServerAction.mjs +10 -16
- package/dist/utils/safeServerAction.mjs.map +1 -1
- package/dist/utils/withAction.mjs +13 -0
- package/dist/utils/withAction.mjs.map +1 -0
- package/package.json +1 -1
- package/src/components/account/hooks/useTwoFactorAuthForm.tsx +101 -114
- package/src/components/account/sections/MyProfileSection.tsx +29 -26
- package/src/components/account/sections/PreferencesSection.tsx +10 -16
- package/src/index.ts +2 -0
- package/src/modules/accounts/actions/account-management.action.ts +90 -261
- package/src/modules/accounts/actions/find-current-account.action.ts +5 -4
- package/src/modules/accounts/actions/list-currencies.action.ts +8 -7
- package/src/modules/accounts/actions/list-timezones.action.ts +8 -7
- package/src/modules/accounts/hooks/current-account.hook.tsx +6 -5
- package/src/modules/accounts/hooks/useAccountManagement.ts +85 -83
- package/src/modules/accounts/hooks/useCurrencies.ts +15 -14
- package/src/modules/accounts/hooks/useTimezones.ts +15 -14
- package/src/modules/auth/actions/logout.action.ts +8 -7
- package/src/modules/auth/actions/register.action.ts +9 -6
- package/src/modules/auth/actions/verify-two-factor.action.ts +8 -21
- package/src/modules/auth/hooks/logout.hook.tsx +2 -1
- package/src/modules/auth/hooks/register.hook.tsx +2 -1
- package/src/modules/auth/hooks/useUserQuery.ts +2 -2
- package/src/modules/ia-credits/actions/list-ia-credits.action.ts +8 -11
- package/src/modules/ia-credits/hooks/ia-credits.hook.ts +2 -1
- package/src/modules/projects/actions/add-project-user.action.ts +9 -8
- package/src/modules/projects/actions/list-available-users.action.ts +9 -8
- package/src/modules/projects/actions/list-project-users.action.ts +9 -8
- package/src/modules/projects/actions/remove-project-user.action.ts +9 -8
- package/src/modules/projects/hooks/list-available-users.hook.ts +33 -26
- package/src/modules/projects/hooks/list-project-users.hook.ts +33 -26
- package/src/modules/subscriptions/actions/list-subscriptions.action.ts +9 -11
- package/src/modules/subscriptions/hooks/find-active-subscription.hook.ts +19 -15
- package/src/modules/subscriptions/hooks/list-subscriptions.hook.ts +17 -15
- package/src/modules/users/action/find-user-by-id.action.ts +8 -25
- package/src/modules/users/action/list-messages.action.ts +12 -10
- package/src/modules/users/action/mark-all-messages-as-read.action.ts +8 -8
- package/src/modules/users/action/mark-message-as-read.action.ts +8 -8
- package/src/modules/users/hooks/messages.hook.ts +60 -58
- package/src/utils/safeServerAction.ts +18 -24
- package/src/utils/withAction.ts +13 -0
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { authService } from
|
|
3
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
+
import { getClientInfoFromRequest } from '../../../infra/utils/client-info';
|
|
5
|
+
import { authService } from '../services/auth.service';
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export function logoutAction() {
|
|
8
|
+
return safeServerAction(async () => {
|
|
9
|
+
const clientInfo = await getClientInfoFromRequest();
|
|
10
|
+
return authService.logout(clientInfo);
|
|
11
|
+
});
|
|
11
12
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
+
import { RegisterRequest } from '../schema';
|
|
5
|
+
import { authService } from '../services/auth.service';
|
|
6
|
+
import { getClientInfoFromRequest } from '../../../infra/utils/client-info';
|
|
6
7
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
export function registerAction(data: RegisterRequest) {
|
|
9
|
+
return safeServerAction(async () => {
|
|
10
|
+
const clientInfo = await getClientInfoFromRequest();
|
|
11
|
+
return authService.register(data, clientInfo);
|
|
12
|
+
});
|
|
10
13
|
}
|
|
@@ -1,28 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
'use server';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { getClientInfoFromRequest } from
|
|
3
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
+
import { authService } from '../services/auth.service';
|
|
5
|
+
import { getClientInfoFromRequest } from '../../../infra/utils/client-info';
|
|
6
6
|
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
code: string
|
|
10
|
-
): Promise<{ status: 0 | 1; message?: string }> {
|
|
11
|
-
try {
|
|
7
|
+
export function verifyTwoFactorAction(cookie: string, code: string) {
|
|
8
|
+
return safeServerAction(async () => {
|
|
12
9
|
if (!/^\d{6}$/.test(code)) {
|
|
13
|
-
|
|
10
|
+
throw new Error('Formato inválido');
|
|
14
11
|
}
|
|
15
|
-
|
|
16
12
|
const clientInfo = await getClientInfoFromRequest();
|
|
17
13
|
await authService.verifyTwoFactor(cookie, code, clientInfo);
|
|
18
|
-
|
|
19
|
-
return { status: 1 };
|
|
20
|
-
} catch (error) {
|
|
21
|
-
return {
|
|
22
|
-
status: 0,
|
|
23
|
-
message:
|
|
24
|
-
(error as ApiError).message ||
|
|
25
|
-
"Ocorreu um erro durante a verificação de dois fatores",
|
|
26
|
-
};
|
|
27
|
-
}
|
|
14
|
+
});
|
|
28
15
|
}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { useMutation } from "@tanstack/react-query";
|
|
4
4
|
import { logoutAction } from "../actions/logout.action";
|
|
5
|
+
import { withAction } from "../../../utils/withAction";
|
|
5
6
|
|
|
6
7
|
export function useLogout() {
|
|
7
8
|
return useMutation({
|
|
8
|
-
mutationFn: logoutAction,
|
|
9
|
+
mutationFn: withAction(logoutAction),
|
|
9
10
|
});
|
|
10
11
|
}
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import { useMutation } from "@tanstack/react-query";
|
|
4
4
|
import { registerAction } from "../actions/register.action";
|
|
5
|
+
import { withAction } from "../../../utils/withAction";
|
|
5
6
|
|
|
6
7
|
export function useRegister() {
|
|
7
8
|
return useMutation({
|
|
8
|
-
mutationFn: registerAction,
|
|
9
|
+
mutationFn: withAction(registerAction),
|
|
9
10
|
});
|
|
10
11
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { useMutation, useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query';
|
|
4
4
|
import { User } from '../../users/schema';
|
|
5
|
-
import {
|
|
5
|
+
import { withAction } from '../../../utils/withAction';
|
|
6
6
|
|
|
7
7
|
export const USER_QUERY_KEY = ['user'];
|
|
8
8
|
|
|
@@ -45,7 +45,7 @@ export function useTwoFactorVerify() {
|
|
|
45
45
|
return useMutation({
|
|
46
46
|
mutationFn: async ({ cookie, code }: { cookie: string; code: string }) => {
|
|
47
47
|
const { verifyTwoFactorAction } = await import('../actions/verify-two-factor.action');
|
|
48
|
-
return
|
|
48
|
+
return withAction(() => verifyTwoFactorAction(cookie, code))();
|
|
49
49
|
},
|
|
50
50
|
onSuccess: () => {
|
|
51
51
|
queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
): Promise<PaginatedSuccessResult<IaCreditOperation>> {
|
|
10
|
-
return iaCreditsService.listOperations(subscriptionId);
|
|
11
|
-
}
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
+
import { iaCreditsService } from '../services/ia-credits.service';
|
|
5
|
+
|
|
6
|
+
export function listIaCreditsAction(subscriptionId: number | string) {
|
|
7
|
+
return safeServerAction(() => iaCreditsService.listOperations(subscriptionId));
|
|
8
|
+
}
|
|
@@ -5,6 +5,7 @@ import { useQuery } from '@tanstack/react-query';
|
|
|
5
5
|
import { listIaCreditsAction } from '../actions/list-ia-credits.action';
|
|
6
6
|
import type { IaCreditOperation, IaCreditsSummary } from '../types';
|
|
7
7
|
import { useActiveSubscription } from '../../subscriptions/hooks/find-active-subscription.hook';
|
|
8
|
+
import { withAction } from '../../../utils/withAction';
|
|
8
9
|
|
|
9
10
|
function calculateSummary(operations: IaCreditOperation[]): IaCreditsSummary {
|
|
10
11
|
const today = new Date();
|
|
@@ -74,7 +75,7 @@ export function useIaCredits() {
|
|
|
74
75
|
|
|
75
76
|
const query = useQuery({
|
|
76
77
|
queryKey: ['ia-credits', subscriptionId],
|
|
77
|
-
queryFn: () => listIaCreditsAction(subscriptionId!),
|
|
78
|
+
queryFn: withAction(() => listIaCreditsAction(subscriptionId!)),
|
|
78
79
|
enabled: subscriptionId != null,
|
|
79
80
|
});
|
|
80
81
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
+
import { projectUsersService } from '../services/project-users.service';
|
|
5
|
+
import type { AddRemoveProjectUsersParams } from '../types';
|
|
6
|
+
|
|
7
|
+
export function addProjectUserAction(params: AddRemoveProjectUsersParams) {
|
|
8
|
+
return safeServerAction(() => projectUsersService.addToProject(params));
|
|
9
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
+
import { projectUsersService } from '../services/project-users.service';
|
|
5
|
+
import type { ListUsersParams } from '../types';
|
|
6
|
+
|
|
7
|
+
export function listAvailableUsersAction(projectId: number, params: ListUsersParams = {}) {
|
|
8
|
+
return safeServerAction(() => projectUsersService.listNotInProject(projectId, params));
|
|
9
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
+
import { projectUsersService } from '../services/project-users.service';
|
|
5
|
+
import type { ListUsersParams } from '../types';
|
|
6
|
+
|
|
7
|
+
export function listProjectUsersAction(projectId: number, params: ListUsersParams = {}) {
|
|
8
|
+
return safeServerAction(() => projectUsersService.listInProject(projectId, params));
|
|
9
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
+
import { projectUsersService } from '../services/project-users.service';
|
|
5
|
+
import type { AddRemoveProjectUsersParams } from '../types';
|
|
6
|
+
|
|
7
|
+
export function removeProjectUserAction(params: AddRemoveProjectUsersParams) {
|
|
8
|
+
return safeServerAction(() => projectUsersService.removeFromProject(params));
|
|
9
|
+
}
|
|
@@ -1,26 +1,33 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
4
|
-
import { listAvailableUsersAction } from '../actions/list-available-users.action';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
4
|
+
import { listAvailableUsersAction } from '../actions/list-available-users.action';
|
|
5
|
+
import { withAction } from '../../../utils/withAction';
|
|
6
|
+
|
|
7
|
+
const PAGE_SIZE = 20;
|
|
8
|
+
|
|
9
|
+
export const LIST_AVAILABLE_USERS_BASE_KEY = (projectId: number) => ['project-users', projectId, 'out'];
|
|
10
|
+
export const LIST_AVAILABLE_USERS_QUERY_KEY = (projectId: number, search: string = '') => [
|
|
11
|
+
...LIST_AVAILABLE_USERS_BASE_KEY(projectId),
|
|
12
|
+
search,
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
export function useListAvailableUsers(projectId: number, search: string = '') {
|
|
16
|
+
return useInfiniteQuery({
|
|
17
|
+
queryKey: LIST_AVAILABLE_USERS_QUERY_KEY(projectId, search),
|
|
18
|
+
queryFn: ({ pageParam }) =>
|
|
19
|
+
withAction(() =>
|
|
20
|
+
listAvailableUsersAction(projectId, {
|
|
21
|
+
search: search || undefined,
|
|
22
|
+
page: pageParam as number,
|
|
23
|
+
limit: PAGE_SIZE,
|
|
24
|
+
})
|
|
25
|
+
)(),
|
|
26
|
+
getNextPageParam: (lastPage, allPages) => {
|
|
27
|
+
const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);
|
|
28
|
+
return loaded < lastPage.total ? allPages.length + 1 : undefined;
|
|
29
|
+
},
|
|
30
|
+
initialPageParam: 1,
|
|
31
|
+
enabled: !!projectId,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -1,26 +1,33 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
4
|
-
import { listProjectUsersAction } from '../actions/list-project-users.action';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
4
|
+
import { listProjectUsersAction } from '../actions/list-project-users.action';
|
|
5
|
+
import { withAction } from '../../../utils/withAction';
|
|
6
|
+
|
|
7
|
+
const PAGE_SIZE = 20;
|
|
8
|
+
|
|
9
|
+
export const LIST_PROJECT_USERS_BASE_KEY = (projectId: number) => ['project-users', projectId, 'in'];
|
|
10
|
+
export const LIST_PROJECT_USERS_QUERY_KEY = (projectId: number, search: string = '') => [
|
|
11
|
+
...LIST_PROJECT_USERS_BASE_KEY(projectId),
|
|
12
|
+
search,
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
export function useListProjectUsers(projectId: number, search: string = '') {
|
|
16
|
+
return useInfiniteQuery({
|
|
17
|
+
queryKey: LIST_PROJECT_USERS_QUERY_KEY(projectId, search),
|
|
18
|
+
queryFn: ({ pageParam }) =>
|
|
19
|
+
withAction(() =>
|
|
20
|
+
listProjectUsersAction(projectId, {
|
|
21
|
+
search: search || undefined,
|
|
22
|
+
page: pageParam as number,
|
|
23
|
+
limit: PAGE_SIZE,
|
|
24
|
+
})
|
|
25
|
+
)(),
|
|
26
|
+
getNextPageParam: (lastPage, allPages) => {
|
|
27
|
+
const loaded = allPages.reduce((sum, p) => sum + p.data.length, 0);
|
|
28
|
+
return loaded < lastPage.total ? allPages.length + 1 : undefined;
|
|
29
|
+
},
|
|
30
|
+
initialPageParam: 1,
|
|
31
|
+
enabled: !!projectId,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import type {
|
|
5
|
-
import { subscriptionsService } from '../services/subscriptions.service';
|
|
6
|
-
|
|
7
|
-
export
|
|
8
|
-
params
|
|
9
|
-
|
|
10
|
-
return subscriptionsService.listSubscriptions(params);
|
|
11
|
-
}
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
+
import type { FindSubscriptionsParams } from '../types';
|
|
5
|
+
import { subscriptionsService } from '../services/subscriptions.service';
|
|
6
|
+
|
|
7
|
+
export function listSubscriptionsAction(params?: Partial<FindSubscriptionsParams>) {
|
|
8
|
+
return safeServerAction(() => subscriptionsService.listSubscriptions(params));
|
|
9
|
+
}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useQuery } from '@tanstack/react-query';
|
|
4
|
-
import { listSubscriptionsAction } from '../actions/list-subscriptions.action';
|
|
5
|
-
import { parseResult } from '../../../infra/utils/parser';
|
|
6
|
-
import { SubscriptionSchema } from '../types';
|
|
7
|
-
import { SUBSCRIPTIONS_QUERY_KEY } from './list-subscriptions.hook';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useQuery } from '@tanstack/react-query';
|
|
4
|
+
import { listSubscriptionsAction } from '../actions/list-subscriptions.action';
|
|
5
|
+
import { parseResult } from '../../../infra/utils/parser';
|
|
6
|
+
import { SubscriptionSchema } from '../types';
|
|
7
|
+
import { SUBSCRIPTIONS_QUERY_KEY } from './list-subscriptions.hook';
|
|
8
|
+
import { withAction } from '../../../utils/withAction';
|
|
9
|
+
|
|
10
|
+
export function useActiveSubscription() {
|
|
11
|
+
return useQuery({
|
|
12
|
+
queryKey: [...SUBSCRIPTIONS_QUERY_KEY, 'active'],
|
|
13
|
+
queryFn: async () =>
|
|
14
|
+
parseResult(
|
|
15
|
+
SubscriptionSchema,
|
|
16
|
+
await withAction(() => listSubscriptionsAction({ active: true }))()
|
|
17
|
+
),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useQuery } from '@tanstack/react-query';
|
|
4
|
-
import { listSubscriptionsAction } from '../actions/list-subscriptions.action';
|
|
5
|
-
import { parseResult } from '../../../infra/utils/parser';
|
|
6
|
-
import { SubscriptionSchema, type FindSubscriptionsParams } from '../types';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useQuery } from '@tanstack/react-query';
|
|
4
|
+
import { listSubscriptionsAction } from '../actions/list-subscriptions.action';
|
|
5
|
+
import { parseResult } from '../../../infra/utils/parser';
|
|
6
|
+
import { SubscriptionSchema, type FindSubscriptionsParams } from '../types';
|
|
7
|
+
import { withAction } from '../../../utils/withAction';
|
|
8
|
+
|
|
9
|
+
export const SUBSCRIPTIONS_QUERY_KEY = ['subscriptions'];
|
|
10
|
+
|
|
11
|
+
export function useSubscriptions(params?: Partial<FindSubscriptionsParams>) {
|
|
12
|
+
return useQuery({
|
|
13
|
+
queryKey: [...SUBSCRIPTIONS_QUERY_KEY, params],
|
|
14
|
+
queryFn: async () =>
|
|
15
|
+
parseResult(SubscriptionSchema, await withAction(() => listSubscriptionsAction(params))()),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -1,25 +1,8 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
error?: string;
|
|
10
|
-
}> {
|
|
11
|
-
try {
|
|
12
|
-
const user = await userService.findById();
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
success: true,
|
|
16
|
-
data: user,
|
|
17
|
-
};
|
|
18
|
-
} catch (error) {
|
|
19
|
-
console.error('[findUserById] Error:', error);
|
|
20
|
-
return {
|
|
21
|
-
success: false,
|
|
22
|
-
error: error instanceof Error ? error.message : 'Erro desconhecido',
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
+
import { userService } from '../services/user.service';
|
|
5
|
+
|
|
6
|
+
export function findUserById() {
|
|
7
|
+
return safeServerAction(() => userService.findById());
|
|
8
|
+
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
}
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
+
import { messagesService } from '../services/messages.service';
|
|
5
|
+
import type { FindMessagesParams } from '../schema/messages.schema';
|
|
6
|
+
|
|
7
|
+
export function listMessagesAction(params?: Partial<FindMessagesParams>) {
|
|
8
|
+
return safeServerAction(async () => {
|
|
9
|
+
const result = await messagesService.listMessages(params);
|
|
10
|
+
return { data: result.data, total: result.total, totalUnread: result.totalUnread };
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
return messagesService.markAllAsRead();
|
|
8
|
-
}
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
+
import { messagesService } from '../services/messages.service';
|
|
5
|
+
|
|
6
|
+
export function markAllMessagesAsReadAction() {
|
|
7
|
+
return safeServerAction(() => messagesService.markAllAsRead());
|
|
8
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
return messagesService.markAsRead(messageId);
|
|
8
|
-
}
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
+
import { messagesService } from '../services/messages.service';
|
|
5
|
+
|
|
6
|
+
export function markMessageAsReadAction(messageId: string) {
|
|
7
|
+
return safeServerAction(() => messagesService.markAsRead(messageId));
|
|
8
|
+
}
|