@greatapps/common 1.1.170 → 1.1.174
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/useChangePhoneForm.mjs +9 -1
- package/dist/components/account/hooks/useChangePhoneForm.mjs.map +1 -1
- package/dist/components/account/sections/ChangeEmailModal.mjs +2 -1
- package/dist/components/account/sections/ChangeEmailModal.mjs.map +1 -1
- package/dist/components/account/sections/ChangePhoneModal.mjs +9 -4
- package/dist/components/account/sections/ChangePhoneModal.mjs.map +1 -1
- package/dist/components/ui/form/PhoneInput.mjs +42 -1
- package/dist/components/ui/form/PhoneInput.mjs.map +1 -1
- package/dist/modules/accounts/actions/account-management.action.mjs +4 -4
- package/dist/modules/accounts/actions/account-management.action.mjs.map +1 -1
- package/dist/modules/accounts/services/account.service.mjs +4 -4
- package/dist/modules/accounts/services/account.service.mjs.map +1 -1
- package/dist/modules/auth/services/auth.service.mjs +1 -0
- package/dist/modules/auth/services/auth.service.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/account/hooks/useChangePhoneForm.tsx +78 -69
- package/src/components/account/sections/ChangeEmailModal.tsx +2 -1
- package/src/components/account/sections/ChangePhoneModal.tsx +234 -229
- package/src/components/ui/form/PhoneInput.tsx +148 -98
- package/src/modules/accounts/actions/account-management.action.ts +4 -4
- package/src/modules/accounts/services/account.service.ts +4 -4
- package/src/modules/auth/schema.ts +1 -0
- package/src/modules/auth/services/auth.service.ts +1 -0
|
@@ -1,98 +1,148 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { ComponentPropsWithoutRef, forwardRef } from 'react';
|
|
4
|
-
import Image from 'next/image';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { ComponentPropsWithoutRef, forwardRef } from 'react';
|
|
4
|
+
import Image from 'next/image';
|
|
5
|
+
import { ChevronDown } from 'lucide-react';
|
|
6
|
+
import { Input } from './Input';
|
|
7
|
+
import { Separator } from '../data-display/Separator';
|
|
8
|
+
import { cn } from '../../../infra/utils/clsx';
|
|
9
|
+
|
|
10
|
+
export interface PhoneCountry {
|
|
11
|
+
code: string;
|
|
12
|
+
label: string;
|
|
13
|
+
emoji: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const PHONE_COUNTRIES: PhoneCountry[] = [
|
|
17
|
+
{ code: '+55', label: 'Brasil', emoji: '🇧🇷' },
|
|
18
|
+
{ code: '+1', label: 'EUA', emoji: '🇺🇸' },
|
|
19
|
+
{ code: '+351', label: 'Portugal', emoji: '🇵🇹' },
|
|
20
|
+
{ code: '+54', label: 'Argentina', emoji: '🇦🇷' },
|
|
21
|
+
{ code: '+56', label: 'Chile', emoji: '🇨🇱' },
|
|
22
|
+
{ code: '+52', label: 'México', emoji: '🇲🇽' },
|
|
23
|
+
{ code: '+44', label: 'Reino Unido', emoji: '🇬🇧' },
|
|
24
|
+
{ code: '+34', label: 'Espanha', emoji: '🇪🇸' },
|
|
25
|
+
{ code: '+49', label: 'Alemanha', emoji: '🇩🇪' },
|
|
26
|
+
{ code: '+33', label: 'França', emoji: '🇫🇷' },
|
|
27
|
+
{ code: '+57', label: 'Colômbia', emoji: '🇨🇴' },
|
|
28
|
+
{ code: '+598', label: 'Uruguai', emoji: '🇺🇾' },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
interface PhoneInputProps extends Omit<ComponentPropsWithoutRef<'input'>, 'type'> {
|
|
32
|
+
label?: string;
|
|
33
|
+
optional?: boolean;
|
|
34
|
+
required?: boolean;
|
|
35
|
+
hintMessage?: string;
|
|
36
|
+
error?: boolean;
|
|
37
|
+
errorMessage?: string;
|
|
38
|
+
countryCode?: string;
|
|
39
|
+
countryFlagSrc?: string;
|
|
40
|
+
countryFlagAlt?: string;
|
|
41
|
+
classnameContainer?: string;
|
|
42
|
+
selectedCountry?: PhoneCountry;
|
|
43
|
+
onCountryChange?: (country: PhoneCountry) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const PhoneInput = forwardRef<HTMLInputElement, PhoneInputProps>(
|
|
47
|
+
(
|
|
48
|
+
{
|
|
49
|
+
label,
|
|
50
|
+
optional = false,
|
|
51
|
+
required = false,
|
|
52
|
+
hintMessage,
|
|
53
|
+
error = false,
|
|
54
|
+
errorMessage,
|
|
55
|
+
countryCode = '+55',
|
|
56
|
+
countryFlagSrc = '/icons/brazil-flag.svg',
|
|
57
|
+
countryFlagAlt = 'Brazil flag',
|
|
58
|
+
className,
|
|
59
|
+
classnameContainer,
|
|
60
|
+
selectedCountry,
|
|
61
|
+
onCountryChange,
|
|
62
|
+
...props
|
|
63
|
+
},
|
|
64
|
+
ref
|
|
65
|
+
) => {
|
|
66
|
+
const finalMessage = error && errorMessage ? errorMessage : hintMessage;
|
|
67
|
+
const showMessage = finalMessage && finalMessage.trim() !== '';
|
|
68
|
+
|
|
69
|
+
const displayCode = selectedCountry ? selectedCountry.code : countryCode;
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div className={cn('flex flex-col gap-1.5')}>
|
|
73
|
+
{label && (
|
|
74
|
+
<div className="flex items-center gap-1 paragraph-xsmall-semibold">
|
|
75
|
+
<span className="text-gray-600">{label}</span>
|
|
76
|
+
{optional && <span className="text-gray-500">(Opcional)</span>}
|
|
77
|
+
{required && <span className="text-red-600">*</span>}
|
|
78
|
+
</div>
|
|
79
|
+
)}
|
|
80
|
+
|
|
81
|
+
<div
|
|
82
|
+
className={cn(
|
|
83
|
+
'flex gap-2 items-center border rounded-lg h-10 transition-colors',
|
|
84
|
+
error
|
|
85
|
+
? 'border-red-600 hover:border-red-700'
|
|
86
|
+
: 'border-gray-200 hover:border-gray-400 focus-within:border-gray-950',
|
|
87
|
+
classnameContainer
|
|
88
|
+
)}
|
|
89
|
+
>
|
|
90
|
+
{onCountryChange ? (
|
|
91
|
+
<div className="relative flex items-center gap-2 px-4 cursor-pointer shrink-0">
|
|
92
|
+
<span className="text-base leading-none">{selectedCountry?.emoji ?? '🇧🇷'}</span>
|
|
93
|
+
<span className="paragraph-small-regular text-gray-950">{displayCode}</span>
|
|
94
|
+
<ChevronDown size={14} className="text-gray-500" />
|
|
95
|
+
<select
|
|
96
|
+
className="absolute inset-0 opacity-0 cursor-pointer w-full"
|
|
97
|
+
value={displayCode}
|
|
98
|
+
onChange={(e) => {
|
|
99
|
+
const country = PHONE_COUNTRIES.find((c) => c.code === e.target.value);
|
|
100
|
+
if (country) onCountryChange(country);
|
|
101
|
+
}}
|
|
102
|
+
>
|
|
103
|
+
{PHONE_COUNTRIES.map((c) => (
|
|
104
|
+
<option key={c.code} value={c.code}>
|
|
105
|
+
{c.emoji} {c.code} — {c.label}
|
|
106
|
+
</option>
|
|
107
|
+
))}
|
|
108
|
+
</select>
|
|
109
|
+
</div>
|
|
110
|
+
) : (
|
|
111
|
+
<div className="flex items-center gap-2 px-4">
|
|
112
|
+
<Image
|
|
113
|
+
src={countryFlagSrc}
|
|
114
|
+
alt={countryFlagAlt}
|
|
115
|
+
width={20}
|
|
116
|
+
height={20}
|
|
117
|
+
className="h-5! w-5! rounded-full"
|
|
118
|
+
/>
|
|
119
|
+
<span className="paragraph-small-regular text-gray-950">{countryCode}</span>
|
|
120
|
+
</div>
|
|
121
|
+
)}
|
|
122
|
+
|
|
123
|
+
<Separator orientation="vertical" />
|
|
124
|
+
|
|
125
|
+
<Input
|
|
126
|
+
ref={ref}
|
|
127
|
+
type="tel"
|
|
128
|
+
className={cn(
|
|
129
|
+
'paragraph-small-medium w-full h-full text-gray-950 border-0 focus-visible:ring-0 focus-visible:ring-offset-0',
|
|
130
|
+
className
|
|
131
|
+
)}
|
|
132
|
+
{...props}
|
|
133
|
+
/>
|
|
134
|
+
</div>
|
|
135
|
+
|
|
136
|
+
{showMessage && (
|
|
137
|
+
<span className={cn('paragraph-xsmall-medium', error ? 'text-red-600' : 'text-gray-600')}>
|
|
138
|
+
{finalMessage}
|
|
139
|
+
</span>
|
|
140
|
+
)}
|
|
141
|
+
</div>
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
PhoneInput.displayName = 'PhoneInput';
|
|
147
|
+
|
|
148
|
+
export default PhoneInput;
|
|
@@ -57,12 +57,12 @@ export async function confirmEmailChangeAction(token: string, newEmail: string)
|
|
|
57
57
|
return safeServerAction(() => accountService.confirmContactReset('email', token, newEmail));
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
export async function requestPhoneChangeAction(newPhone: string) {
|
|
61
|
-
return safeServerAction(() => accountService.requestContactReset('phone', newPhone));
|
|
60
|
+
export async function requestPhoneChangeAction(newPhone: string, ddi?: string) {
|
|
61
|
+
return safeServerAction(() => accountService.requestContactReset('phone', newPhone, ddi));
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export async function confirmPhoneChangeAction(token: string, newPhone: string) {
|
|
65
|
-
return safeServerAction(() => accountService.confirmContactReset('phone', token, newPhone));
|
|
64
|
+
export async function confirmPhoneChangeAction(token: string, newPhone: string, ddi?: string) {
|
|
65
|
+
return safeServerAction(() => accountService.confirmContactReset('phone', token, newPhone, ddi));
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export async function generateTwoFactorAction() {
|
|
@@ -182,11 +182,11 @@ class AccountService {
|
|
|
182
182
|
return response;
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
async requestContactReset(type: 'email' | 'phone', newContact: string): Promise<void> {
|
|
185
|
+
async requestContactReset(type: 'email' | 'phone', newContact: string, ddi?: string): Promise<void> {
|
|
186
186
|
const { id_account, id_user } = await getUserContext();
|
|
187
187
|
const response = await api.apps.post<{ status: number; message: string }>(
|
|
188
188
|
`/accounts/${id_account}/users/${id_user}/resetContact/request`,
|
|
189
|
-
{ type, newContact }
|
|
189
|
+
{ type, newContact, ...(ddi ? { ddi } : {}) }
|
|
190
190
|
);
|
|
191
191
|
|
|
192
192
|
if (response.status === 0) {
|
|
@@ -198,11 +198,11 @@ class AccountService {
|
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
async confirmContactReset(type: 'email' | 'phone', token: string, newContact: string): Promise<void> {
|
|
201
|
+
async confirmContactReset(type: 'email' | 'phone', token: string, newContact: string, ddi?: string): Promise<void> {
|
|
202
202
|
const { id_account, id_user } = await getUserContext();
|
|
203
203
|
const response = await api.apps.post<{ status: number; message: string }>(
|
|
204
204
|
`/accounts/${id_account}/users/${id_user}/resetContact/confirm`,
|
|
205
|
-
{ type, token, newContact }
|
|
205
|
+
{ type, token, newContact, ...(ddi ? { ddi } : {}) }
|
|
206
206
|
);
|
|
207
207
|
|
|
208
208
|
if (response.status === 0) {
|
|
@@ -50,6 +50,7 @@ class AuthService {
|
|
|
50
50
|
const response = await api.apps.post<LoginApiResponse>("/auth/login", {
|
|
51
51
|
email: credentials.email,
|
|
52
52
|
password: credentials.password,
|
|
53
|
+
source: credentials?.source,
|
|
53
54
|
location: clientInfo.location,
|
|
54
55
|
ip: clientInfo.ip,
|
|
55
56
|
timezone: clientInfo.timezone,
|