@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.
@@ -1,98 +1,148 @@
1
- 'use client';
2
-
3
- import { ComponentPropsWithoutRef, forwardRef } from 'react';
4
- import Image from 'next/image';
5
- import { Input } from './Input';
6
- import { Separator } from '../data-display/Separator';
7
- import { cn } from '../../../infra/utils/clsx';
8
-
9
- interface PhoneInputProps extends Omit<ComponentPropsWithoutRef<'input'>, 'type'> {
10
- label?: string;
11
- optional?: boolean;
12
- required?: boolean;
13
- hintMessage?: string;
14
- error?: boolean;
15
- errorMessage?: string;
16
- countryCode?: string;
17
- countryFlagSrc?: string;
18
- countryFlagAlt?: string;
19
- classnameContainer?: string;
20
- }
21
-
22
- const PhoneInput = forwardRef<HTMLInputElement, PhoneInputProps>(
23
- (
24
- {
25
- label,
26
- optional = false,
27
- required = false,
28
- hintMessage,
29
- error = false,
30
- errorMessage,
31
- countryCode = '+55',
32
- countryFlagSrc = '/icons/brazil-flag.svg',
33
- countryFlagAlt = 'Brazil flag',
34
- className,
35
- classnameContainer,
36
- ...props
37
- },
38
- ref
39
- ) => {
40
- const finalMessage = error && errorMessage ? errorMessage : hintMessage;
41
- const showMessage = finalMessage && finalMessage.trim() !== '';
42
-
43
- return (
44
- <div className={cn('flex flex-col gap-1.5')}>
45
- {label && (
46
- <div className="flex items-center gap-1 paragraph-xsmall-semibold">
47
- <span className="text-gray-600">{label}</span>
48
- {optional && <span className="text-gray-500">(Opcional)</span>}
49
- {required && <span className="text-red-600">*</span>}
50
- </div>
51
- )}
52
-
53
- <div
54
- className={cn(
55
- 'flex gap-2 items-center border rounded-lg h-10 transition-colors',
56
- error
57
- ? 'border-red-600 hover:border-red-700'
58
- : 'border-gray-200 hover:border-gray-400 focus-within:border-gray-950',
59
- classnameContainer
60
- )}
61
- >
62
- <div className="flex items-center gap-2 px-4">
63
- <Image
64
- src={countryFlagSrc}
65
- alt={countryFlagAlt}
66
- width={20}
67
- height={20}
68
- className="h-5! w-5! rounded-full"
69
- />
70
- <span className="paragraph-small-regular text-gray-950">{countryCode}</span>
71
- </div>
72
-
73
- <Separator orientation="vertical" />
74
-
75
- <Input
76
- ref={ref}
77
- type="tel"
78
- className={cn(
79
- 'paragraph-small-medium w-full h-full text-gray-950 border-0 focus-visible:ring-0 focus-visible:ring-offset-0',
80
- className
81
- )}
82
- {...props}
83
- />
84
- </div>
85
-
86
- {showMessage && (
87
- <span className={cn('paragraph-xsmall-medium', error ? 'text-red-600' : 'text-gray-600')}>
88
- {finalMessage}
89
- </span>
90
- )}
91
- </div>
92
- );
93
- }
94
- );
95
-
96
- PhoneInput.displayName = 'PhoneInput';
97
-
98
- export default PhoneInput;
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) {
@@ -70,6 +70,7 @@ export interface AuthState {
70
70
  export interface LoginRequest {
71
71
  email: string;
72
72
  password: string;
73
+ source?: string;
73
74
  rememberMe?: boolean;
74
75
  }
75
76
 
@@ -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,