@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.
Files changed (109) hide show
  1. package/dist/components/account/hooks/useTwoFactorAuthForm.mjs +5 -13
  2. package/dist/components/account/hooks/useTwoFactorAuthForm.mjs.map +1 -1
  3. package/dist/components/account/sections/MyProfileSection.mjs +30 -19
  4. package/dist/components/account/sections/MyProfileSection.mjs.map +1 -1
  5. package/dist/components/account/sections/PreferencesSection.mjs +11 -10
  6. package/dist/components/account/sections/PreferencesSection.mjs.map +1 -1
  7. package/dist/index.mjs +3 -1
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/modules/accounts/actions/account-management.action.mjs +36 -168
  10. package/dist/modules/accounts/actions/account-management.action.mjs.map +1 -1
  11. package/dist/modules/accounts/actions/find-current-account.action.mjs +3 -2
  12. package/dist/modules/accounts/actions/find-current-account.action.mjs.map +1 -1
  13. package/dist/modules/accounts/actions/list-currencies.action.mjs +3 -2
  14. package/dist/modules/accounts/actions/list-currencies.action.mjs.map +1 -1
  15. package/dist/modules/accounts/actions/list-timezones.action.mjs +3 -2
  16. package/dist/modules/accounts/actions/list-timezones.action.mjs.map +1 -1
  17. package/dist/modules/accounts/hooks/current-account.hook.mjs +2 -1
  18. package/dist/modules/accounts/hooks/current-account.hook.mjs.map +1 -1
  19. package/dist/modules/accounts/hooks/useAccountManagement.mjs +8 -5
  20. package/dist/modules/accounts/hooks/useAccountManagement.mjs.map +1 -1
  21. package/dist/modules/accounts/hooks/useCurrencies.mjs +2 -1
  22. package/dist/modules/accounts/hooks/useCurrencies.mjs.map +1 -1
  23. package/dist/modules/accounts/hooks/useTimezones.mjs +2 -1
  24. package/dist/modules/accounts/hooks/useTimezones.mjs.map +1 -1
  25. package/dist/modules/auth/actions/logout.action.mjs +6 -3
  26. package/dist/modules/auth/actions/logout.action.mjs.map +1 -1
  27. package/dist/modules/auth/actions/register.action.mjs +6 -3
  28. package/dist/modules/auth/actions/register.action.mjs.map +1 -1
  29. package/dist/modules/auth/actions/verify-two-factor.action.mjs +5 -10
  30. package/dist/modules/auth/actions/verify-two-factor.action.mjs.map +1 -1
  31. package/dist/modules/auth/hooks/logout.hook.mjs +2 -1
  32. package/dist/modules/auth/hooks/logout.hook.mjs.map +1 -1
  33. package/dist/modules/auth/hooks/register.hook.mjs +2 -1
  34. package/dist/modules/auth/hooks/register.hook.mjs.map +1 -1
  35. package/dist/modules/auth/hooks/useUserQuery.mjs +2 -2
  36. package/dist/modules/auth/hooks/useUserQuery.mjs.map +1 -1
  37. package/dist/modules/ia-credits/actions/list-ia-credits.action.mjs +3 -2
  38. package/dist/modules/ia-credits/actions/list-ia-credits.action.mjs.map +1 -1
  39. package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs +2 -1
  40. package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs.map +1 -1
  41. package/dist/modules/projects/actions/add-project-user.action.mjs +3 -2
  42. package/dist/modules/projects/actions/add-project-user.action.mjs.map +1 -1
  43. package/dist/modules/projects/actions/list-available-users.action.mjs +3 -2
  44. package/dist/modules/projects/actions/list-available-users.action.mjs.map +1 -1
  45. package/dist/modules/projects/actions/list-project-users.action.mjs +3 -2
  46. package/dist/modules/projects/actions/list-project-users.action.mjs.map +1 -1
  47. package/dist/modules/projects/actions/remove-project-user.action.mjs +3 -2
  48. package/dist/modules/projects/actions/remove-project-user.action.mjs.map +1 -1
  49. package/dist/modules/projects/hooks/list-available-users.hook.mjs +8 -1
  50. package/dist/modules/projects/hooks/list-available-users.hook.mjs.map +1 -1
  51. package/dist/modules/projects/hooks/list-project-users.hook.mjs +8 -1
  52. package/dist/modules/projects/hooks/list-project-users.hook.mjs.map +1 -1
  53. package/dist/modules/subscriptions/actions/list-subscriptions.action.mjs +3 -2
  54. package/dist/modules/subscriptions/actions/list-subscriptions.action.mjs.map +1 -1
  55. package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs +5 -1
  56. package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs.map +1 -1
  57. package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs +2 -1
  58. package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs.map +1 -1
  59. package/dist/modules/users/action/find-user-by-id.action.mjs +3 -14
  60. package/dist/modules/users/action/find-user-by-id.action.mjs.map +1 -1
  61. package/dist/modules/users/action/list-messages.action.mjs +6 -2
  62. package/dist/modules/users/action/list-messages.action.mjs.map +1 -1
  63. package/dist/modules/users/action/mark-all-messages-as-read.action.mjs +3 -2
  64. package/dist/modules/users/action/mark-all-messages-as-read.action.mjs.map +1 -1
  65. package/dist/modules/users/action/mark-message-as-read.action.mjs +3 -2
  66. package/dist/modules/users/action/mark-message-as-read.action.mjs.map +1 -1
  67. package/dist/modules/users/hooks/messages.hook.mjs +11 -9
  68. package/dist/modules/users/hooks/messages.hook.mjs.map +1 -1
  69. package/dist/utils/safeServerAction.mjs +10 -16
  70. package/dist/utils/safeServerAction.mjs.map +1 -1
  71. package/dist/utils/withAction.mjs +13 -0
  72. package/dist/utils/withAction.mjs.map +1 -0
  73. package/package.json +1 -1
  74. package/src/components/account/hooks/useTwoFactorAuthForm.tsx +101 -114
  75. package/src/components/account/sections/MyProfileSection.tsx +29 -26
  76. package/src/components/account/sections/PreferencesSection.tsx +10 -16
  77. package/src/index.ts +2 -0
  78. package/src/modules/accounts/actions/account-management.action.ts +90 -261
  79. package/src/modules/accounts/actions/find-current-account.action.ts +5 -4
  80. package/src/modules/accounts/actions/list-currencies.action.ts +8 -7
  81. package/src/modules/accounts/actions/list-timezones.action.ts +8 -7
  82. package/src/modules/accounts/hooks/current-account.hook.tsx +6 -5
  83. package/src/modules/accounts/hooks/useAccountManagement.ts +85 -83
  84. package/src/modules/accounts/hooks/useCurrencies.ts +15 -14
  85. package/src/modules/accounts/hooks/useTimezones.ts +15 -14
  86. package/src/modules/auth/actions/logout.action.ts +8 -7
  87. package/src/modules/auth/actions/register.action.ts +9 -6
  88. package/src/modules/auth/actions/verify-two-factor.action.ts +8 -21
  89. package/src/modules/auth/hooks/logout.hook.tsx +2 -1
  90. package/src/modules/auth/hooks/register.hook.tsx +2 -1
  91. package/src/modules/auth/hooks/useUserQuery.ts +2 -2
  92. package/src/modules/ia-credits/actions/list-ia-credits.action.ts +8 -11
  93. package/src/modules/ia-credits/hooks/ia-credits.hook.ts +2 -1
  94. package/src/modules/projects/actions/add-project-user.action.ts +9 -8
  95. package/src/modules/projects/actions/list-available-users.action.ts +9 -8
  96. package/src/modules/projects/actions/list-project-users.action.ts +9 -8
  97. package/src/modules/projects/actions/remove-project-user.action.ts +9 -8
  98. package/src/modules/projects/hooks/list-available-users.hook.ts +33 -26
  99. package/src/modules/projects/hooks/list-project-users.hook.ts +33 -26
  100. package/src/modules/subscriptions/actions/list-subscriptions.action.ts +9 -11
  101. package/src/modules/subscriptions/hooks/find-active-subscription.hook.ts +19 -15
  102. package/src/modules/subscriptions/hooks/list-subscriptions.hook.ts +17 -15
  103. package/src/modules/users/action/find-user-by-id.action.ts +8 -25
  104. package/src/modules/users/action/list-messages.action.ts +12 -10
  105. package/src/modules/users/action/mark-all-messages-as-read.action.ts +8 -8
  106. package/src/modules/users/action/mark-message-as-read.action.ts +8 -8
  107. package/src/modules/users/hooks/messages.hook.ts +60 -58
  108. package/src/utils/safeServerAction.ts +18 -24
  109. package/src/utils/withAction.ts +13 -0
@@ -1,261 +1,90 @@
1
- "use server";
2
-
3
- import { accountService } from "../services/account.service";
4
- import { ApiError } from "../../../infra/api/types";
5
- import type {
6
- AccountUsersPaginationParams,
7
- AccountUsersActionResult,
8
- ChangePasswordActionResult,
9
- ChangePasswordRequest,
10
- ContactResetResult,
11
- CreateAccountUserRequest,
12
- DeleteAccountActionResult,
13
- DeleteUserActionResult,
14
- TwoFactorActionResult,
15
- TwoFactorGenerateResult,
16
- UpdateAccountActionResult,
17
- UpdateAccountRequest,
18
- UpdateAccountUserRequest,
19
- UpdateUserActionResult,
20
- } from "../types";
21
- import { twoFactorService } from "../services/two-factor.service";
22
-
23
- export async function listAccountUsersAction(
24
- params?: AccountUsersPaginationParams
25
- ): Promise<AccountUsersActionResult> {
26
- try {
27
- const { users, total } = await accountService.listAccountUsers(params);
28
- return { success: true, data: users, total };
29
- } catch (error) {
30
- if (error instanceof ApiError)
31
- return { success: false, error: error.message };
32
- return {
33
- success: false,
34
- error: "Erro ao listar usuários. Tente novamente.",
35
- };
36
- }
37
- }
38
-
39
- export async function updateUserAction(
40
- user: UpdateAccountUserRequest
41
- ): Promise<UpdateUserActionResult> {
42
- try {
43
- const result = await accountService.updateAccountUser(user);
44
- return { success: true, data: result };
45
- } catch (error) {
46
- if (error instanceof ApiError)
47
- return { success: false, error: error.message };
48
- return {
49
- success: false,
50
- error: "Erro ao atualizar usuário. Tente novamente.",
51
- };
52
- }
53
- }
54
-
55
- export async function updateAccountUserByIdAction(
56
- userId: number,
57
- user: UpdateAccountUserRequest
58
- ): Promise<UpdateUserActionResult> {
59
- try {
60
- const result = await accountService.updateAccountUserById(userId, user);
61
- return { success: true, data: result };
62
- } catch (error) {
63
- if (error instanceof ApiError)
64
- return { success: false, error: error.message };
65
- return {
66
- success: false,
67
- error: "Erro ao atualizar usuário. Tente novamente.",
68
- };
69
- }
70
- }
71
-
72
- export async function updateAccountAction(
73
- data: UpdateAccountRequest
74
- ): Promise<UpdateAccountActionResult> {
75
- try {
76
- await accountService.updateAccount(data);
77
- return { success: true };
78
- } catch (error) {
79
- if (error instanceof ApiError)
80
- return { success: false, error: error.message };
81
- return {
82
- success: false,
83
- error: "Erro ao atualizar conta. Tente novamente.",
84
- };
85
- }
86
- }
87
-
88
- export async function deleteAccountUserAction(
89
- userId: number
90
- ): Promise<DeleteUserActionResult> {
91
- try {
92
- await accountService.deleteAccountUser(userId);
93
- return { success: true };
94
- } catch (error) {
95
- if (error instanceof ApiError)
96
- return { success: false, error: error.message };
97
- return {
98
- success: false,
99
- error: "Erro ao remover usuário. Tente novamente.",
100
- };
101
- }
102
- }
103
-
104
- export async function deleteAccountAction(): Promise<DeleteAccountActionResult> {
105
- try {
106
- await accountService.deleteAccount();
107
- return { success: true };
108
- } catch (error) {
109
- if (error instanceof ApiError)
110
- return { success: false, error: error.message };
111
- return { success: false, error: "Erro ao excluir conta. Tente novamente." };
112
- }
113
- }
114
-
115
- export async function createAccountUserAction(
116
- user: CreateAccountUserRequest
117
- ): Promise<AccountUsersActionResult> {
118
- try {
119
- const result = await accountService.createAccountUser(user);
120
- return { success: true, data: result.data };
121
- } catch (error) {
122
- if (error instanceof ApiError)
123
- return { success: false, error: error.message };
124
- return { success: false, error: "Erro ao criar usuário. Tente novamente." };
125
- }
126
- }
127
-
128
- export async function changePasswordAction(
129
- data: ChangePasswordRequest
130
- ): Promise<ChangePasswordActionResult> {
131
- try {
132
- await accountService.changePassword(data);
133
- return { success: true };
134
- } catch (error) {
135
- if (error instanceof ApiError)
136
- return { success: false, error: error.message };
137
- return { success: false, error: "Erro ao alterar senha. Tente novamente." };
138
- }
139
- }
140
-
141
- export async function requestEmailChangeAction(
142
- newEmail: string
143
- ): Promise<ContactResetResult> {
144
- try {
145
- await accountService.requestContactReset("email", newEmail);
146
- return { success: true };
147
- } catch (error) {
148
- if (error instanceof ApiError)
149
- return { success: false, error: error.message };
150
- return {
151
- success: false,
152
- error:
153
- "E-mail já existente ou ocorreu um erro. Tente novamente mais tarde.",
154
- };
155
- }
156
- }
157
-
158
- export async function confirmEmailChangeAction(
159
- token: string,
160
- newEmail: string
161
- ): Promise<ContactResetResult> {
162
- try {
163
- await accountService.confirmContactReset("email", token, newEmail);
164
- return { success: true };
165
- } catch (error) {
166
- if (error instanceof ApiError)
167
- return { success: false, error: error.message };
168
- return {
169
- success: false,
170
- error: "Código inválido ou expirado. Tente novamente.",
171
- };
172
- }
173
- }
174
-
175
- export async function requestPhoneChangeAction(
176
- newPhone: string
177
- ): Promise<ContactResetResult> {
178
- try {
179
- await accountService.requestContactReset("phone", newPhone);
180
- return { success: true };
181
- } catch (error) {
182
- if (error instanceof ApiError)
183
- return { success: false, error: error.message };
184
- return {
185
- success: false,
186
- error:
187
- "Número já existente ou ocorreu um erro. Tente novamente mais tarde.",
188
- };
189
- }
190
- }
191
-
192
- export async function confirmPhoneChangeAction(
193
- token: string,
194
- newPhone: string
195
- ): Promise<ContactResetResult> {
196
- try {
197
- await accountService.confirmContactReset("phone", token, newPhone);
198
- return { success: true };
199
- } catch (error) {
200
- if (error instanceof ApiError)
201
- return { success: false, error: error.message };
202
- return {
203
- success: false,
204
- error: "Código inválido ou expirado. Tente novamente.",
205
- };
206
- }
207
- }
208
-
209
- export async function generateTwoFactorAction(): Promise<TwoFactorGenerateResult> {
210
- try {
211
- const result = await twoFactorService.generate();
212
- return {
213
- success: true,
214
- qrcode: result.data.qrcode,
215
- backupCodes: result.data.backup_codes,
216
- };
217
- } catch (error) {
218
- if (error instanceof ApiError)
219
- return { success: false, error: error.message };
220
- return { success: false, error: "Erro ao gerar QR Code. Tente novamente." };
221
- }
222
- }
223
-
224
- export async function confirmTwoFactorAction(
225
- code: string
226
- ): Promise<TwoFactorActionResult> {
227
- try {
228
- await twoFactorService.confirm(code);
229
- await accountService.updateAccountUser({ two_factor_authentication: true });
230
- } catch (error) {
231
- if (error instanceof ApiError)
232
- return { success: false, error: error.message };
233
- return { success: false, error: "Código inválido. Tente novamente." };
234
- }
235
-
236
- return { success: true };
237
- }
238
-
239
- export async function disableTwoFactorAction(
240
- code: string
241
- ): Promise<TwoFactorActionResult> {
242
- try {
243
- await twoFactorService.verify(code);
244
- } catch (error) {
245
- if (error instanceof ApiError)
246
- return { success: false, error: error.message };
247
- return { success: false, error: "Código inválido. Tente novamente." };
248
- }
249
-
250
- try {
251
- await twoFactorService.disable();
252
- return { success: true };
253
- } catch (error) {
254
- if (error instanceof ApiError)
255
- return { success: false, error: error.message };
256
- return {
257
- success: false,
258
- error: "Erro ao desabilitar 2FA. Tente novamente.",
259
- };
260
- }
261
- }
1
+ 'use server';
2
+
3
+ import { safeServerAction } from '../../../utils/safeServerAction';
4
+ import { accountService } from '../services/account.service';
5
+ import type {
6
+ AccountUsersPaginationParams,
7
+ ChangePasswordRequest,
8
+ CreateAccountUserRequest,
9
+ UpdateAccountRequest,
10
+ UpdateAccountUserRequest,
11
+ } from '../types';
12
+ import { twoFactorService } from '../services/two-factor.service';
13
+
14
+ export function listAccountUsersAction(params?: AccountUsersPaginationParams) {
15
+ return safeServerAction(async () => {
16
+ const { users, total } = await accountService.listAccountUsers(params);
17
+ return { data: users, total };
18
+ });
19
+ }
20
+
21
+ export function updateUserAction(user: UpdateAccountUserRequest) {
22
+ return safeServerAction(() => accountService.updateAccountUser(user));
23
+ }
24
+
25
+ export function updateAccountUserByIdAction(
26
+ userId: number,
27
+ user: UpdateAccountUserRequest
28
+ ) {
29
+ return safeServerAction(() => accountService.updateAccountUserById(userId, user));
30
+ }
31
+
32
+ export function updateAccountAction(data: UpdateAccountRequest) {
33
+ return safeServerAction(() => accountService.updateAccount(data));
34
+ }
35
+
36
+ export function deleteAccountUserAction(userId: number) {
37
+ return safeServerAction(() => accountService.deleteAccountUser(userId));
38
+ }
39
+
40
+ export function deleteAccountAction() {
41
+ return safeServerAction(() => accountService.deleteAccount());
42
+ }
43
+
44
+ export function createAccountUserAction(user: CreateAccountUserRequest) {
45
+ return safeServerAction(() => accountService.createAccountUser(user));
46
+ }
47
+
48
+ export function changePasswordAction(data: ChangePasswordRequest) {
49
+ return safeServerAction(() => accountService.changePassword(data));
50
+ }
51
+
52
+ export function requestEmailChangeAction(newEmail: string) {
53
+ return safeServerAction(() => accountService.requestContactReset('email', newEmail));
54
+ }
55
+
56
+ export function confirmEmailChangeAction(token: string, newEmail: string) {
57
+ return safeServerAction(() => accountService.confirmContactReset('email', token, newEmail));
58
+ }
59
+
60
+ export function requestPhoneChangeAction(newPhone: string) {
61
+ return safeServerAction(() => accountService.requestContactReset('phone', newPhone));
62
+ }
63
+
64
+ export function confirmPhoneChangeAction(token: string, newPhone: string) {
65
+ return safeServerAction(() => accountService.confirmContactReset('phone', token, newPhone));
66
+ }
67
+
68
+ export function generateTwoFactorAction() {
69
+ return safeServerAction(async () => {
70
+ const result = await twoFactorService.generate();
71
+ return {
72
+ qrcode: result.data.qrcode,
73
+ backupCodes: result.data.backup_codes,
74
+ };
75
+ });
76
+ }
77
+
78
+ export function confirmTwoFactorAction(code: string) {
79
+ return safeServerAction(async () => {
80
+ await twoFactorService.confirm(code);
81
+ await accountService.updateAccountUser({ two_factor_authentication: true });
82
+ });
83
+ }
84
+
85
+ export function disableTwoFactorAction(code: string) {
86
+ return safeServerAction(async () => {
87
+ await twoFactorService.verify(code);
88
+ await twoFactorService.disable();
89
+ });
90
+ }
@@ -1,8 +1,9 @@
1
1
  'use server';
2
2
 
3
- import { accountService } from "../services/account.service";
4
- import { Account } from "../types";
3
+ import { safeServerAction } from '../../../utils/safeServerAction';
4
+ import { accountService } from '../services/account.service';
5
+ import type { Account } from '../types';
5
6
 
6
- export async function findCurrentAccount(): Promise<Account> {
7
- return await accountService.findCurrentAccount();
7
+ export function findCurrentAccount() {
8
+ return safeServerAction<Account>(() => accountService.findCurrentAccount());
8
9
  }
@@ -1,7 +1,8 @@
1
- 'use server';
2
-
3
- import { currencyService } from '../services/currency.service';
4
-
5
- export async function listCurrenciesAction() {
6
- return currencyService.fetchOptions();
7
- }
1
+ 'use server';
2
+
3
+ import { safeServerAction } from '../../../utils/safeServerAction';
4
+ import { currencyService } from '../services/currency.service';
5
+
6
+ export function listCurrenciesAction() {
7
+ return safeServerAction(() => currencyService.fetchOptions());
8
+ }
@@ -1,7 +1,8 @@
1
- 'use server';
2
-
3
- import { timezoneService } from '../services/timezone.service';
4
-
5
- export async function listTimezonesAction() {
6
- return timezoneService.fetchOptions();
7
- }
1
+ 'use server';
2
+
3
+ import { safeServerAction } from '../../../utils/safeServerAction';
4
+ import { timezoneService } from '../services/timezone.service';
5
+
6
+ export function listTimezonesAction() {
7
+ return safeServerAction(() => timezoneService.fetchOptions());
8
+ }
@@ -1,14 +1,15 @@
1
- "use client";
1
+ 'use client';
2
2
 
3
- import { useQuery, useQueryClient } from "@tanstack/react-query";
4
- import { findCurrentAccount } from "../actions/find-current-account.action";
3
+ import { useQuery, useQueryClient } from '@tanstack/react-query';
4
+ import { findCurrentAccount } from '../actions/find-current-account.action';
5
+ import { withAction } from '../../../utils/withAction';
5
6
 
6
- export const ACCOUNT_QUERY_KEY = ["account"];
7
+ export const ACCOUNT_QUERY_KEY = ['account'];
7
8
 
8
9
  export function useCurrentAccount() {
9
10
  return useQuery({
10
11
  queryKey: ACCOUNT_QUERY_KEY,
11
- queryFn: findCurrentAccount,
12
+ queryFn: withAction(findCurrentAccount),
12
13
  staleTime: 0,
13
14
  gcTime: 10 * 60 * 1000,
14
15
  retry: false,
@@ -1,83 +1,85 @@
1
- 'use client';
2
-
3
- import { useMutation, useQueryClient } from '@tanstack/react-query';
4
- import { USER_QUERY_KEY } from '../../auth/hooks/useUserQuery';
5
- import { ACCOUNT_QUERY_KEY } from './current-account.hook';
6
- import type {
7
- UpdateAccountRequest,
8
- UpdateAccountUserRequest,
9
- DeleteUserActionResult,
10
- DeleteAccountActionResult,
11
- } from '../types';
12
- import {
13
- updateUserAction,
14
- updateAccountAction,
15
- updateAccountUserByIdAction,
16
- deleteAccountUserAction,
17
- deleteAccountAction,
18
- } from '../actions/account-management.action';
19
- import type { UseMutationOptions } from '@tanstack/react-query';
20
-
21
- const ACCOUNT_USERS_QUERY_KEY = ['account-users'];
22
-
23
- export function useUpdateAccount() {
24
- const queryClient = useQueryClient();
25
-
26
- return useMutation({
27
- mutationFn: (data: UpdateAccountRequest) => updateAccountAction(data),
28
- onSuccess: () => {
29
- queryClient.invalidateQueries({ queryKey: ACCOUNT_USERS_QUERY_KEY });
30
- queryClient.invalidateQueries({ queryKey: ACCOUNT_QUERY_KEY });
31
- queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
32
- },
33
- });
34
- }
35
-
36
- export function useUpdateAccountUser() {
37
- const queryClient = useQueryClient();
38
-
39
- return useMutation({
40
- mutationFn: updateUserAction,
41
- onSuccess: () => {
42
- queryClient.invalidateQueries({ queryKey: ACCOUNT_USERS_QUERY_KEY });
43
- queryClient.invalidateQueries({ queryKey: ACCOUNT_QUERY_KEY });
44
- queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
45
- },
46
- });
47
- }
48
-
49
- export function useUpdateAccountUserById() {
50
- const queryClient = useQueryClient();
51
-
52
- return useMutation({
53
- mutationFn: ({ userId, ...user }: UpdateAccountUserRequest & { userId: number }) =>
54
- updateAccountUserByIdAction(userId, user),
55
- onSuccess: () => {
56
- queryClient.invalidateQueries({ queryKey: ACCOUNT_USERS_QUERY_KEY });
57
- },
58
- });
59
- }
60
-
61
- export function useDeleteAccountUser(
62
- options?: UseMutationOptions<DeleteUserActionResult, Error, number>
63
- ) {
64
- const queryClient = useQueryClient();
65
-
66
- return useMutation({
67
- mutationFn: (userId: number) => deleteAccountUserAction(userId),
68
- ...options,
69
- onSuccess: (...params) => {
70
- options?.onSuccess?.(...params);
71
- queryClient.invalidateQueries({ queryKey: ACCOUNT_USERS_QUERY_KEY });
72
- },
73
- });
74
- }
75
-
76
- export function useDeleteAccount(
77
- options?: UseMutationOptions<DeleteAccountActionResult, Error, void>
78
- ) {
79
- return useMutation({
80
- mutationFn: () => deleteAccountAction(),
81
- ...options,
82
- });
83
- }
1
+ 'use client';
2
+
3
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
4
+ import { USER_QUERY_KEY } from '../../auth/hooks/useUserQuery';
5
+ import { ACCOUNT_QUERY_KEY } from './current-account.hook';
6
+ import type {
7
+ UpdateAccountRequest,
8
+ UpdateAccountUserRequest,
9
+ DeleteAccountUserResponse,
10
+ DeleteAccountResponse,
11
+ } from '../types';
12
+ import {
13
+ updateUserAction,
14
+ updateAccountAction,
15
+ updateAccountUserByIdAction,
16
+ deleteAccountUserAction,
17
+ deleteAccountAction,
18
+ } from '../actions/account-management.action';
19
+ import { withAction } from '../../../utils/withAction';
20
+ import type { UseMutationOptions } from '@tanstack/react-query';
21
+
22
+ const ACCOUNT_USERS_QUERY_KEY = ['account-users'];
23
+
24
+ export function useUpdateAccount() {
25
+ const queryClient = useQueryClient();
26
+
27
+ return useMutation({
28
+ mutationFn: withAction(updateAccountAction),
29
+ onSuccess: () => {
30
+ queryClient.invalidateQueries({ queryKey: ACCOUNT_USERS_QUERY_KEY });
31
+ queryClient.invalidateQueries({ queryKey: ACCOUNT_QUERY_KEY });
32
+ queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
33
+ },
34
+ });
35
+ }
36
+
37
+ export function useUpdateAccountUser() {
38
+ const queryClient = useQueryClient();
39
+
40
+ return useMutation({
41
+ mutationFn: withAction(updateUserAction),
42
+ onSuccess: () => {
43
+ queryClient.invalidateQueries({ queryKey: ACCOUNT_USERS_QUERY_KEY });
44
+ queryClient.invalidateQueries({ queryKey: ACCOUNT_QUERY_KEY });
45
+ queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
46
+ },
47
+ });
48
+ }
49
+
50
+ export function useUpdateAccountUserById() {
51
+ const queryClient = useQueryClient();
52
+
53
+ return useMutation({
54
+ mutationFn: withAction(({ userId, ...user }: UpdateAccountUserRequest & { userId: number }) =>
55
+ updateAccountUserByIdAction(userId, user)
56
+ ),
57
+ onSuccess: () => {
58
+ queryClient.invalidateQueries({ queryKey: ACCOUNT_USERS_QUERY_KEY });
59
+ },
60
+ });
61
+ }
62
+
63
+ export function useDeleteAccountUser(
64
+ options?: UseMutationOptions<DeleteAccountUserResponse, Error, number>
65
+ ) {
66
+ const queryClient = useQueryClient();
67
+
68
+ return useMutation({
69
+ mutationFn: withAction(deleteAccountUserAction),
70
+ ...options,
71
+ onSuccess: (...params) => {
72
+ options?.onSuccess?.(...params);
73
+ queryClient.invalidateQueries({ queryKey: ACCOUNT_USERS_QUERY_KEY });
74
+ },
75
+ });
76
+ }
77
+
78
+ export function useDeleteAccount(
79
+ options?: UseMutationOptions<DeleteAccountResponse, Error, void>
80
+ ) {
81
+ return useMutation({
82
+ mutationFn: withAction(deleteAccountAction),
83
+ ...options,
84
+ });
85
+ }
@@ -1,14 +1,15 @@
1
- 'use client';
2
-
3
- import { useQuery } from '@tanstack/react-query';
4
- import { listCurrenciesAction } from '../actions/list-currencies.action';
5
-
6
- export const CURRENCIES_QUERY_KEY = ['currencies'];
7
-
8
- export function useCurrencies() {
9
- return useQuery({
10
- queryKey: CURRENCIES_QUERY_KEY,
11
- queryFn: listCurrenciesAction,
12
- staleTime: Infinity,
13
- });
14
- }
1
+ 'use client';
2
+
3
+ import { useQuery } from '@tanstack/react-query';
4
+ import { listCurrenciesAction } from '../actions/list-currencies.action';
5
+ import { withAction } from '../../../utils/withAction';
6
+
7
+ export const CURRENCIES_QUERY_KEY = ['currencies'];
8
+
9
+ export function useCurrencies() {
10
+ return useQuery({
11
+ queryKey: CURRENCIES_QUERY_KEY,
12
+ queryFn: withAction(listCurrenciesAction),
13
+ staleTime: Infinity,
14
+ });
15
+ }
@@ -1,14 +1,15 @@
1
- 'use client';
2
-
3
- import { useQuery } from '@tanstack/react-query';
4
- import { listTimezonesAction } from '../actions/list-timezones.action';
5
-
6
- export const TIMEZONES_QUERY_KEY = ['timezones'];
7
-
8
- export function useTimezones() {
9
- return useQuery({
10
- queryKey: TIMEZONES_QUERY_KEY,
11
- queryFn: listTimezonesAction,
12
- staleTime: Infinity,
13
- });
14
- }
1
+ 'use client';
2
+
3
+ import { useQuery } from '@tanstack/react-query';
4
+ import { listTimezonesAction } from '../actions/list-timezones.action';
5
+ import { withAction } from '../../../utils/withAction';
6
+
7
+ export const TIMEZONES_QUERY_KEY = ['timezones'];
8
+
9
+ export function useTimezones() {
10
+ return useQuery({
11
+ queryKey: TIMEZONES_QUERY_KEY,
12
+ queryFn: withAction(listTimezonesAction),
13
+ staleTime: Infinity,
14
+ });
15
+ }