@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,261 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
6
|
-
AccountUsersPaginationParams,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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 {
|
|
4
|
-
import {
|
|
3
|
+
import { safeServerAction } from '../../../utils/safeServerAction';
|
|
4
|
+
import { accountService } from '../services/account.service';
|
|
5
|
+
import type { Account } from '../types';
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
-
|
|
7
|
+
export function findCurrentAccount() {
|
|
8
|
+
return safeServerAction<Account>(() => accountService.findCurrentAccount());
|
|
8
9
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
'use server';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
|
|
3
|
-
import { useQuery, useQueryClient } from
|
|
4
|
-
import { findCurrentAccount } from
|
|
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 = [
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
} from '../types';
|
|
12
|
-
import {
|
|
13
|
-
updateUserAction,
|
|
14
|
-
updateAccountAction,
|
|
15
|
-
updateAccountUserByIdAction,
|
|
16
|
-
deleteAccountUserAction,
|
|
17
|
-
deleteAccountAction,
|
|
18
|
-
} from '../actions/account-management.action';
|
|
19
|
-
import
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
queryClient.invalidateQueries({ queryKey:
|
|
31
|
-
queryClient.invalidateQueries({ queryKey:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
queryClient.invalidateQueries({ queryKey:
|
|
44
|
-
queryClient.invalidateQueries({ queryKey:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
}
|