diff --git a/prediqo_mobile/lib/core/theme/app_theme.dart b/prediqo_mobile/lib/core/theme/app_theme.dart index 423bdd64..153892f0 100644 --- a/prediqo_mobile/lib/core/theme/app_theme.dart +++ b/prediqo_mobile/lib/core/theme/app_theme.dart @@ -88,6 +88,11 @@ class AppTheme { behavior: SnackBarBehavior.floating, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)), backgroundColor: isDark ? AppColors.surfaceElevated : const Color(0xFF1E293B), + contentTextStyle: const TextStyle( + color: Colors.white, + fontWeight: FontWeight.w600, + fontSize: 14, + ), ), dividerTheme: DividerThemeData(color: isDark ? AppColors.border : const Color(0xFFE2E8F0)), bottomSheetTheme: const BottomSheetThemeData( diff --git a/prediqo_mobile/lib/features/auth/presentation/register_screen.dart b/prediqo_mobile/lib/features/auth/presentation/register_screen.dart index b73d7bdb..e484cc88 100644 --- a/prediqo_mobile/lib/features/auth/presentation/register_screen.dart +++ b/prediqo_mobile/lib/features/auth/presentation/register_screen.dart @@ -44,6 +44,7 @@ class _RegisterScreenState extends State { List _countries = const []; bool? _referralValid; String? _referralReason; + bool _usingDefaultReferrer = false; Timer? _referralDebounce; Timer? _formErrorTimer; @@ -119,6 +120,7 @@ class _RegisterScreenState extends State { }); return; } + setState(() => _usingDefaultReferrer = false); _referralDebounce = Timer(const Duration(milliseconds: 400), () async { final result = await sl().validateReferralCode(code); if (!mounted) return; @@ -130,6 +132,17 @@ class _RegisterScreenState extends State { }); } + void _applyDefaultReferrer() { + _referralDebounce?.cancel(); + _referralController.clear(); + setState(() { + _referralValid = null; + _referralReason = null; + _usingDefaultReferrer = true; + _formError = null; + }); + } + String? _countryLabel(String? code) { if (code == null) return null; for (final c in _countries) { @@ -224,6 +237,10 @@ class _RegisterScreenState extends State { _setFormError(s.passwordsMustMatch); return; } + if (_referralValid == false && _referralController.text.trim().isNotEmpty) { + _setFormError(s.referralFixOrUseDefault); + return; + } setState(() => _formError = null); context.read().add(AuthRegisterRequested( @@ -296,7 +313,7 @@ class _RegisterScreenState extends State { crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text(s.registerSubtitle, style: Theme.of(context).textTheme.bodyMedium), - if (invited != null && invited.isNotEmpty) ...[ + if (invited != null && invited.isNotEmpty && !_usingDefaultReferrer) ...[ const SizedBox(height: 12), Container( padding: const EdgeInsets.all(12), @@ -311,6 +328,13 @@ class _RegisterScreenState extends State { if (_formError != null) ...[ const SizedBox(height: 12), _AlertBox(message: _formError!, danger: true), + if (_referralValid == false) ...[ + const SizedBox(height: 8), + OutlinedButton( + onPressed: loading ? null : _applyDefaultReferrer, + child: Text(s.useDefaultReferrer), + ), + ], ], if (_countriesError != null) ...[ const SizedBox(height: 12), @@ -420,15 +444,29 @@ class _RegisterScreenState extends State { LengthLimitingTextInputFormatter(32), ], ), - if (_referralValid == true) ...[ + if (_usingDefaultReferrer && _referralController.text.trim().isEmpty) ...[ + const SizedBox(height: 6), + Text( + s.usingDefaultReferrer, + style: const TextStyle(color: AppColors.success, fontSize: 12), + ), + ] else if (_referralValid == true) ...[ const SizedBox(height: 6), Text(s.referralValid, style: const TextStyle(color: AppColors.success, fontSize: 12)), ] else if (_referralValid == false) ...[ const SizedBox(height: 6), Text( - _referralReason?.trim().isNotEmpty == true ? _referralReason! : s.referralInvalid, + s.localizeReferralReason(_referralReason), style: const TextStyle(color: AppColors.danger, fontSize: 12), ), + const SizedBox(height: 8), + Align( + alignment: Alignment.centerLeft, + child: OutlinedButton( + onPressed: loading ? null : _applyDefaultReferrer, + child: Text(s.useDefaultReferrer), + ), + ), ], const SizedBox(height: 24), PredPrimaryButton( diff --git a/prediqo_mobile/lib/features/share_cards/presentation/share_result_widgets.dart b/prediqo_mobile/lib/features/share_cards/presentation/share_result_widgets.dart index 07ccc1b2..f3fbb7fb 100644 --- a/prediqo_mobile/lib/features/share_cards/presentation/share_result_widgets.dart +++ b/prediqo_mobile/lib/features/share_cards/presentation/share_result_widgets.dart @@ -12,6 +12,7 @@ import '../../../core/theme/app_colors.dart'; import '../../../data/models/share_card_models.dart'; import '../../../data/repositories/share_card_repository.dart'; import '../../../l10n/app_strings.dart'; +import '../../../shared/widgets/app_snackbar.dart'; import '../../../shared/widgets/prediqo_logo.dart'; Future openShareResultDialog( @@ -113,8 +114,9 @@ class _ShareResultDialogState extends State<_ShareResultDialog> { } catch (_) { if (!mounted) return; final s = context.strings; - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(s.t('Could not export the card', 'Impossible d’exporter la carte'))), + showErrorSnackBar( + context, + s.t('Could not export the card', 'Impossible d’exporter la carte'), ); } finally { if (mounted) setState(() => _busy = false); @@ -518,7 +520,12 @@ class _ShareResultIconButtonState extends State { padding: EdgeInsets.zero, onPressed: () { if (blockedByDeposit) { - ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(blockedMsg))); + showAppSnackBar( + context, + message: blockedMsg, + backgroundColor: AppColors.warning, + duration: const Duration(seconds: 6), + ); return; } openShareResultDialog( diff --git a/prediqo_mobile/lib/l10n/app_strings.dart b/prediqo_mobile/lib/l10n/app_strings.dart index 8f001fc3..a218d56d 100644 --- a/prediqo_mobile/lib/l10n/app_strings.dart +++ b/prediqo_mobile/lib/l10n/app_strings.dart @@ -92,6 +92,52 @@ class AppStrings { String get referralCodeOptional => t('Referral code (optional)', 'Code de parrainage (optionnel)'); String get referralInvalid => t('This referral code is not valid.', 'Ce code de parrainage n’est pas valide.'); String get referralValid => t('Referral code accepted.', 'Code de parrainage accepté.'); + String get useDefaultReferrer => t( + 'Continue with the default referrer', + 'Continuer avec le parrain par défaut', + ); + String get usingDefaultReferrer => t( + 'You will be registered with the platform default referrer.', + 'Vous serez inscrit avec le parrain par défaut de la plateforme.', + ); + String get referralFixOrUseDefault => t( + 'This referral code cannot be used. Clear it or continue with the default referrer.', + 'Ce code de parrainage ne peut pas être utilisé. Effacez-le ou continuez avec le parrain par défaut.', + ); + String localizeReferralReason(String? reason) { + final r = reason?.trim() ?? ''; + if (r.isEmpty) return referralInvalid; + switch (r) { + case 'empty': + return t('No referral code provided', 'Aucun code de parrainage fourni'); + case 'program_disabled': + return t( + 'The referral program is currently disabled', + 'Le programme de parrainage est actuellement désactivé', + ); + case 'unknown_code': + return t('Unknown referral code', 'Code de parrainage inconnu'); + case 'Referrer must have completed at least one deposit': + return t( + 'The referrer must have completed at least one real-funds deposit', + 'Le parrain doit avoir effectué au moins un dépôt avec des fonds réels', + ); + case 'Referrer must have a verified email': + return t( + 'The referrer must have a verified email', + 'Le parrain doit avoir un e-mail vérifié', + ); + case 'Referrer account is not eligible': + return t( + 'The referrer account is not eligible', + 'Le compte du parrain n’est pas éligible', + ); + case 'Invalid referral code': + return t('Invalid referral code', 'Code de parrainage invalide'); + default: + return r; + } + } String get registerFieldsRequired => t( 'Please fill in all required fields.', 'Veuillez renseigner tous les champs obligatoires.', diff --git a/prediqo_web/public/brand/prediqo-mark.svg b/prediqo_web/public/brand/prediqo-mark.svg index 77c9effd..cba7c7c1 100644 --- a/prediqo_web/public/brand/prediqo-mark.svg +++ b/prediqo_web/public/brand/prediqo-mark.svg @@ -1,17 +1,34 @@ - - - - - - - + + + + + diff --git a/prediqo_web/src/features/auth/RegisterPage.tsx b/prediqo_web/src/features/auth/RegisterPage.tsx index 4e840af1..06b1b063 100644 --- a/prediqo_web/src/features/auth/RegisterPage.tsx +++ b/prediqo_web/src/features/auth/RegisterPage.tsx @@ -48,6 +48,7 @@ export function RegisterPage() { const [referralCode, setReferralCode] = useState(refFromUrl); const [referralValid, setReferralValid] = useState(null); const [referralInvalidReason, setReferralInvalidReason] = useState(null); + const [usingDefaultReferrer, setUsingDefaultReferrer] = useState(false); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [success, setSuccess] = useState(null); @@ -63,7 +64,10 @@ export function RegisterPage() { const countries = countriesQ.data ?? []; useEffect(() => { - if (refFromUrl) setReferralCode(refFromUrl); + if (refFromUrl) { + setReferralCode(refFromUrl); + setUsingDefaultReferrer(false); + } }, [refFromUrl]); useEffect(() => { @@ -73,6 +77,7 @@ export function RegisterPage() { setReferralInvalidReason(null); return; } + setUsingDefaultReferrer(false); const timer = setTimeout(async () => { try { const res = await api.get<{ valid: boolean; reason?: string }>( @@ -88,6 +93,24 @@ export function RegisterPage() { return () => clearTimeout(timer); }, [referralCode]); + const localizeReferralReason = (reason: string | null | undefined): string => { + if (!reason?.trim()) return t('auth.referralUnknown'); + const key = `auth.referralReasons.${reason}` as const; + const localized = t(key); + return localized === key ? reason : localized; + }; + + const applyDefaultReferrer = () => { + setReferralCode(''); + setReferralValid(null); + setReferralInvalidReason(null); + setUsingDefaultReferrer(true); + setError(null); + if (refFromUrl) { + nav('/register', { replace: true }); + } + }; + const resolvedCountry = country; const submit = async () => { @@ -105,6 +128,10 @@ export function RegisterPage() { setError(t('auth.countryIsoInvalid')); return; } + if (referralValid === false && referralCode.trim()) { + setError(t('auth.referralFixOrUseDefault')); + return; + } setLoading(true); try { const res = await api.post('/api/v1/auth/register', { @@ -121,7 +148,18 @@ export function RegisterPage() { setTimeout(() => nav('/login', { replace: true, state: { verifyEmail: true } }), 4000); } catch (e: unknown) { const err = e as { response?: { data?: { error?: string } }; message?: string }; - setError(apiErrorMessage(err, t('auth.registerFailed'))); + const msg = apiErrorMessage(err, t('auth.registerFailed')); + setError(msg); + const lower = msg.toLowerCase(); + if ( + lower.includes('referral') || + lower.includes('referrer') || + lower.includes('parrain') || + lower.includes('deposit') + ) { + setReferralValid(false); + setReferralInvalidReason(err.response?.data?.error ?? msg); + } } finally { setLoading(false); } @@ -140,14 +178,27 @@ export function RegisterPage() { {t('auth.registerSubtitle')} - {refFromUrl && ( + {refFromUrl && !usingDefaultReferrer && ( }} /> )} - {error && {error}} + {error && ( + + {t('auth.useDefaultReferrer')} + + ) : undefined + } + > + {error} + + )} {success && {success}} - setReferralCode(e.target.value.toUpperCase())} - fullWidth - helperText={ - referralValid === true - ? t('auth.referralValid') - : referralValid === false - ? referralInvalidReason - ? t('auth.referralInvalidWithReason', { reason: referralInvalidReason }) - : t('auth.referralUnknown') - : t('auth.referralEmpty') - } - error={referralValid === false && !!referralCode.trim()} - /> + + setReferralCode(e.target.value.toUpperCase())} + fullWidth + helperText={ + usingDefaultReferrer && !referralCode.trim() + ? t('auth.usingDefaultReferrer') + : referralValid === true + ? t('auth.referralValid') + : referralValid === false + ? referralInvalidReason + ? t('auth.referralInvalidWithReason', { + reason: localizeReferralReason(referralInvalidReason), + }) + : t('auth.referralUnknown') + : t('auth.referralEmpty') + } + error={referralValid === false && !!referralCode.trim()} + slotProps={{ + formHelperText: { + sx: + usingDefaultReferrer && !referralCode.trim() + ? { color: 'success.main' } + : undefined, + }, + }} + /> + {referralValid === false && !!referralCode.trim() && ( + + )} +