@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,114 +1,101 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { useState, useCallback, useEffect } from 'react';
|
|
4
|
-
import { useMutation } from '@tanstack/react-query';
|
|
5
|
-
import { toast } from 'sonner';
|
|
6
|
-
import { Toast } from '../../ui/feedback/Toast';
|
|
7
|
-
import { copyToClipboard } from '../../../utils/browser/clipboard';
|
|
8
|
-
import {
|
|
9
|
-
generateTwoFactorAction,
|
|
10
|
-
confirmTwoFactorAction,
|
|
11
|
-
} from '../../../modules/accounts/actions/account-management.action';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const [
|
|
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
|
-
const
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
generateMutation.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
isGenerating: generateMutation.isPending,
|
|
103
|
-
isConfirming: confirmMutation.isPending,
|
|
104
|
-
generateFailed,
|
|
105
|
-
retryGenerate: triggerGenerate,
|
|
106
|
-
qrcode: generateMutation.data?.qrcode,
|
|
107
|
-
backupCodes: generateMutation.data?.backupCodes ?? [],
|
|
108
|
-
step,
|
|
109
|
-
handleSubmit,
|
|
110
|
-
handleFinalize,
|
|
111
|
-
handleCopyCodes,
|
|
112
|
-
resetForm,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState, useCallback, useEffect } from 'react';
|
|
4
|
+
import { useMutation } from '@tanstack/react-query';
|
|
5
|
+
import { toast } from 'sonner';
|
|
6
|
+
import { Toast } from '../../ui/feedback/Toast';
|
|
7
|
+
import { copyToClipboard } from '../../../utils/browser/clipboard';
|
|
8
|
+
import {
|
|
9
|
+
generateTwoFactorAction,
|
|
10
|
+
confirmTwoFactorAction,
|
|
11
|
+
} from '../../../modules/accounts/actions/account-management.action';
|
|
12
|
+
import { withAction } from '../../../utils/withAction';
|
|
13
|
+
|
|
14
|
+
type Step = 'code' | 'recovery';
|
|
15
|
+
|
|
16
|
+
interface UseTwoFactorAuthFormProps {
|
|
17
|
+
onSuccess?: () => void;
|
|
18
|
+
open?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default function useTwoFactorAuthForm({ onSuccess, open }: UseTwoFactorAuthFormProps = {}) {
|
|
22
|
+
const [code, setCode] = useState('');
|
|
23
|
+
const [step, setStep] = useState<Step>('code');
|
|
24
|
+
|
|
25
|
+
const generateMutation = useMutation({
|
|
26
|
+
mutationFn: withAction(generateTwoFactorAction),
|
|
27
|
+
onError: () => {
|
|
28
|
+
toast.custom((t) => (
|
|
29
|
+
<Toast variant="error" message="Erro ao gerar QR Code. Tente novamente." toastId={t} />
|
|
30
|
+
));
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const confirmMutation = useMutation({
|
|
35
|
+
mutationFn: withAction(confirmTwoFactorAction),
|
|
36
|
+
onSuccess: () => {
|
|
37
|
+
setStep('recovery');
|
|
38
|
+
},
|
|
39
|
+
onError: () => {
|
|
40
|
+
toast.custom((t) => (
|
|
41
|
+
<Toast variant="error" message="Erro ao confirmar código. Tente novamente." toastId={t} />
|
|
42
|
+
));
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const { mutate: triggerGenerate } = generateMutation;
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (open) {
|
|
50
|
+
triggerGenerate();
|
|
51
|
+
}
|
|
52
|
+
}, [open, triggerGenerate]);
|
|
53
|
+
|
|
54
|
+
const generateFailed = generateMutation.isError;
|
|
55
|
+
|
|
56
|
+
const isCodeComplete = code.length === 6;
|
|
57
|
+
|
|
58
|
+
const handleSubmit = () => {
|
|
59
|
+
if (!isCodeComplete) return;
|
|
60
|
+
confirmMutation.mutate(code);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const handleFinalize = () => {
|
|
64
|
+
onSuccess?.();
|
|
65
|
+
setTimeout(resetForm, 300);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const handleCopyCodes = useCallback(async () => {
|
|
69
|
+
const codes = generateMutation.data?.backupCodes ?? [];
|
|
70
|
+
const success = await copyToClipboard(codes.join('\n'));
|
|
71
|
+
if (success) {
|
|
72
|
+
toast.custom((t) => (
|
|
73
|
+
<Toast variant="success" message="Códigos copiados com sucesso" toastId={t} />
|
|
74
|
+
));
|
|
75
|
+
}
|
|
76
|
+
}, [generateMutation.data]);
|
|
77
|
+
|
|
78
|
+
const resetForm = () => {
|
|
79
|
+
setCode('');
|
|
80
|
+
setStep('code');
|
|
81
|
+
generateMutation.reset();
|
|
82
|
+
confirmMutation.reset();
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
code,
|
|
87
|
+
setCode,
|
|
88
|
+
isCodeComplete,
|
|
89
|
+
isGenerating: generateMutation.isPending,
|
|
90
|
+
isConfirming: confirmMutation.isPending,
|
|
91
|
+
generateFailed,
|
|
92
|
+
retryGenerate: triggerGenerate,
|
|
93
|
+
qrcode: generateMutation.data?.qrcode,
|
|
94
|
+
backupCodes: generateMutation.data?.backupCodes ?? [],
|
|
95
|
+
step,
|
|
96
|
+
handleSubmit,
|
|
97
|
+
handleFinalize,
|
|
98
|
+
handleCopyCodes,
|
|
99
|
+
resetForm,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -84,47 +84,50 @@ export function MyProfileSection({ onClose, storageUrl }: MyProfileSectionProps)
|
|
|
84
84
|
};
|
|
85
85
|
|
|
86
86
|
const handleDelete = async () => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
try {
|
|
88
|
+
if (isOwner) {
|
|
89
|
+
await deleteAccount.mutateAsync();
|
|
90
|
+
} else {
|
|
91
|
+
await deleteAccountUser.mutateAsync(user!.id);
|
|
92
|
+
}
|
|
93
|
+
await logout();
|
|
94
|
+
} catch (error) {
|
|
92
95
|
toast.custom((t) => (
|
|
93
96
|
<Toast
|
|
94
97
|
variant="error"
|
|
95
|
-
message={
|
|
98
|
+
message={error instanceof Error ? error.message : 'Erro ao excluir. Tente novamente.'}
|
|
96
99
|
toastId={t}
|
|
97
100
|
/>
|
|
98
101
|
));
|
|
99
102
|
setDeleteConfirmOpen(false);
|
|
100
|
-
return;
|
|
101
103
|
}
|
|
102
|
-
|
|
103
|
-
await logout();
|
|
104
104
|
};
|
|
105
105
|
|
|
106
106
|
const onSubmit = async (data: MyProfileFormData) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
try {
|
|
108
|
+
await updateAccountUser.mutateAsync({
|
|
109
|
+
name: data.name,
|
|
110
|
+
gender: GENDER_OPTIONS.find((g) => g.value === data.gender)?.apiValue,
|
|
111
|
+
...(selectedPhoto ? { photo: selectedPhoto } : {}),
|
|
112
|
+
...(photoRemoved ? { photo: '' } : {}),
|
|
113
|
+
});
|
|
113
114
|
|
|
114
|
-
|
|
115
|
+
form.reset(data);
|
|
116
|
+
setSelectedPhoto(null);
|
|
117
|
+
setPhotoRemoved(false);
|
|
115
118
|
toast.custom((t) => (
|
|
116
|
-
<Toast variant="
|
|
119
|
+
<Toast variant="success" message="Perfil atualizado com sucesso" toastId={t} />
|
|
120
|
+
));
|
|
121
|
+
onClose();
|
|
122
|
+
} catch (error) {
|
|
123
|
+
toast.custom((t) => (
|
|
124
|
+
<Toast
|
|
125
|
+
variant="error"
|
|
126
|
+
message={error instanceof Error ? error.message : 'Erro ao atualizar perfil'}
|
|
127
|
+
toastId={t}
|
|
128
|
+
/>
|
|
117
129
|
));
|
|
118
|
-
return;
|
|
119
130
|
}
|
|
120
|
-
|
|
121
|
-
form.reset(data);
|
|
122
|
-
setSelectedPhoto(null);
|
|
123
|
-
setPhotoRemoved(false);
|
|
124
|
-
toast.custom((t) => (
|
|
125
|
-
<Toast variant="success" message="Perfil atualizado com sucesso" toastId={t} />
|
|
126
|
-
));
|
|
127
|
-
onClose();
|
|
128
131
|
};
|
|
129
132
|
|
|
130
133
|
return (
|
|
@@ -87,28 +87,14 @@ export function PreferencesSection({ onClose }: PreferencesSectionProps) {
|
|
|
87
87
|
setIsSaving(true);
|
|
88
88
|
try {
|
|
89
89
|
const apiLanguage = LANGUAGE_OPTIONS.find((o) => o.value === data.language)?.apiValue ?? data.language.toLowerCase();
|
|
90
|
-
|
|
90
|
+
await updateAccountUser.mutateAsync({
|
|
91
91
|
language: apiLanguage,
|
|
92
92
|
receive_sms: data.receive_sms,
|
|
93
93
|
receive_email: data.receive_email,
|
|
94
94
|
});
|
|
95
95
|
|
|
96
|
-
if (!userResult.success) {
|
|
97
|
-
toast.custom((t) => (
|
|
98
|
-
<Toast variant="error" message={userResult.error ?? 'Erro ao salvar preferências'} toastId={t} />
|
|
99
|
-
));
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
96
|
if (canEditPreferences && Object.keys(accountFields).length > 0) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (!accountResult.success) {
|
|
107
|
-
toast.custom((t) => (
|
|
108
|
-
<Toast variant="error" message={accountResult.error ?? 'Erro ao salvar preferências da conta'} toastId={t} />
|
|
109
|
-
));
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
97
|
+
await updateAccount.mutateAsync(accountFields);
|
|
112
98
|
}
|
|
113
99
|
|
|
114
100
|
reset(data);
|
|
@@ -116,6 +102,14 @@ export function PreferencesSection({ onClose }: PreferencesSectionProps) {
|
|
|
116
102
|
<Toast variant="success" message="Preferências salvas com sucesso" toastId={t} />
|
|
117
103
|
));
|
|
118
104
|
onClose();
|
|
105
|
+
} catch (error) {
|
|
106
|
+
toast.custom((t) => (
|
|
107
|
+
<Toast
|
|
108
|
+
variant="error"
|
|
109
|
+
message={error instanceof Error ? error.message : 'Erro ao salvar preferências'}
|
|
110
|
+
toastId={t}
|
|
111
|
+
/>
|
|
112
|
+
));
|
|
119
113
|
} finally {
|
|
120
114
|
setIsSaving(false);
|
|
121
115
|
}
|
package/src/index.ts
CHANGED
|
@@ -74,6 +74,8 @@ export type {
|
|
|
74
74
|
export { cn } from "./infra/utils/clsx";
|
|
75
75
|
export { buildQueryParams } from "./infra/utils/params";
|
|
76
76
|
export { parseSchema, parseResult } from "./infra/utils/parser";
|
|
77
|
+
export { withAction } from "./utils/withAction";
|
|
78
|
+
export { safeServerAction } from "./utils/safeServerAction";
|
|
77
79
|
|
|
78
80
|
// Layout
|
|
79
81
|
export {
|