After adding the alternative for the referral code

This commit is contained in:
Your Name 2026-08-08 14:34:24 +02:00
parent 2d9b3ff5a7
commit cefaab29f1
10 changed files with 269 additions and 43 deletions

View File

@ -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(

View File

@ -44,6 +44,7 @@ class _RegisterScreenState extends State<RegisterScreen> {
List<CountryOption> _countries = const [];
bool? _referralValid;
String? _referralReason;
bool _usingDefaultReferrer = false;
Timer? _referralDebounce;
Timer? _formErrorTimer;
@ -119,6 +120,7 @@ class _RegisterScreenState extends State<RegisterScreen> {
});
return;
}
setState(() => _usingDefaultReferrer = false);
_referralDebounce = Timer(const Duration(milliseconds: 400), () async {
final result = await sl<AuthRepository>().validateReferralCode(code);
if (!mounted) return;
@ -130,6 +132,17 @@ class _RegisterScreenState extends State<RegisterScreen> {
});
}
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<RegisterScreen> {
_setFormError(s.passwordsMustMatch);
return;
}
if (_referralValid == false && _referralController.text.trim().isNotEmpty) {
_setFormError(s.referralFixOrUseDefault);
return;
}
setState(() => _formError = null);
context.read<AuthBloc>().add(AuthRegisterRequested(
@ -296,7 +313,7 @@ class _RegisterScreenState extends State<RegisterScreen> {
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<RegisterScreen> {
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<RegisterScreen> {
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(

View File

@ -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<void> 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<ShareResultIconButton> {
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(

View File

@ -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.',

View File

@ -1,17 +1,34 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 128 128" role="img" aria-label="Prediqo mark">
<rect width="128" height="128" rx="28" fill="#0B0F1A"/>
<rect x="8" y="8" width="112" height="112" rx="24" fill="none" stroke="#D4AF37" stroke-width="3.5"/>
<!-- Custom P stem with cut ends -->
<path d="M34 28 L54 28 L54 100 L42 108 L34 100 Z" fill="#10B981"/>
<!-- Bowl = open concentric arcs (target) -->
<path d="M54 32
C 92 32, 104 48, 104 64
C 104 80, 92 96, 54 96"
fill="none" stroke="#10B981" stroke-width="11" stroke-linecap="round"/>
<path d="M54 44
C 82 44, 90 52, 90 64
C 90 76, 82 84, 54 84"
fill="none" stroke="#34D399" stroke-width="6.5" stroke-linecap="round"/>
<circle cx="70" cy="64" r="7" fill="#10B981"/>
<path d="M70 52 L72 58 L78.5 60 L72 62 L70 68 L68 62 L61.5 60 L68 58 Z" fill="#D4AF37"/>
<path d="M34 22 H49 V106 H34 Z" fill="#10B981"/>
<path
d="M49 31
H72
C92 31 106 43 106 59
C106 75 92 87 72 87
H49
V72
H70
C82 72 90 67 90 59
C90 51 82 46 70 46
H49 Z"
fill="#10B981"
/>
<path
d="M49 43
H71
C81 43 88 49 88 59
C88 69 81 75 71 75
H49
V66
H68
C74 66 79 64 79 59
C79 54 74 52 68 52
H49 Z"
fill="#34D399"
opacity="0.95"
/>
<circle cx="74" cy="59" r="6.5" fill="#10B981"/>
<path d="M74 48 L76 53.5 L82 55.5 L76 57.5 L74 63 L72 57.5 L66 55.5 L72 53.5 Z" fill="#D4AF37"/>
</svg>

Before

Width:  |  Height:  |  Size: 898 B

After

Width:  |  Height:  |  Size: 907 B

View File

@ -48,6 +48,7 @@ export function RegisterPage() {
const [referralCode, setReferralCode] = useState(refFromUrl);
const [referralValid, setReferralValid] = useState<boolean | null>(null);
const [referralInvalidReason, setReferralInvalidReason] = useState<string | null>(null);
const [usingDefaultReferrer, setUsingDefaultReferrer] = useState(false);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [success, setSuccess] = useState<string | null>(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<RegisterResponse>('/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() {
</Typography>
<Typography sx={{ opacity: 0.75, mt: 0.5 }}>{t('auth.registerSubtitle')}</Typography>
{refFromUrl && (
{refFromUrl && !usingDefaultReferrer && (
<Alert severity="info" sx={{ mt: 2 }}>
<Trans i18nKey="auth.invitedWithCode" values={{ code: refFromUrl }} components={{ strong: <strong /> }} />
</Alert>
)}
<Stack spacing={2} sx={{ mt: 3 }}>
{error && <Alert severity="error">{error}</Alert>}
{error && (
<Alert
severity="error"
action={
referralValid === false ? (
<Button color="inherit" size="small" onClick={applyDefaultReferrer}>
{t('auth.useDefaultReferrer')}
</Button>
) : undefined
}
>
{error}
</Alert>
)}
{success && <Alert severity="success">{success}</Alert>}
<TextField
@ -218,22 +269,46 @@ export function RegisterPage() {
placeholder={t('auth.nationalityPlaceholder')}
/>
<TextField
label={t('auth.referralCodeOptional')}
value={referralCode}
onChange={(e) => 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()}
/>
<Box>
<TextField
label={t('auth.referralCodeOptional')}
value={referralCode}
onChange={(e) => 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() && (
<Button
variant="outlined"
size="small"
onClick={applyDefaultReferrer}
sx={{ mt: 1 }}
>
{t('auth.useDefaultReferrer')}
</Button>
)}
</Box>
<Button variant="contained" onClick={submit} disabled={loading} size="large">
{loading ? t('auth.creatingAccount') : t('auth.signUp')}

View File

@ -12,12 +12,18 @@ import CloseRoundedIcon from '@mui/icons-material/CloseRounded';
import HeadsetMicRoundedIcon from '@mui/icons-material/HeadsetMicRounded';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useAuth } from '../../../shared/auth/AuthContext';
import { SupportChatPanel } from './SupportChatPanel';
import { requestSupportNotificationPermission, shouldAskNotificationPermission } from '../utils/notifications';
/** Floating support button — visible on all pages including login/register. */
/**
* Floating support chat for players and guests.
* Hidden for staff: they already have Support in the sidebar, and the FAB
* would cover dense admin UI (tables, pagination, scrollbars).
*/
export function SupportWidget() {
const { t } = useTranslation();
const { isStaff } = useAuth();
const [open, setOpen] = useState(false);
const [mounted, setMounted] = useState(false);
@ -27,6 +33,8 @@ export function SupportWidget() {
}
}, [open]);
if (isStaff) return null;
const openWidget = () => {
setMounted(true);
setOpen(true);

View File

@ -847,11 +847,11 @@ export function UserManagementPage() {
},
{
field: 'actions',
headerName: t('admin.users.columns.copy'),
width: 90,
headerName: t('admin.users.columns.actions'),
width: 132,
sortable: false,
renderCell: (p: { row: AdminUser }) => (
<Stack direction="row" spacing={0.5}>
<Stack direction="row" spacing={0.5} sx={{ width: '100%', justifyContent: 'center' }}>
<Tooltip title={t('admin.users.tooltips.copyUserId')} arrow placement="top">
<IconButton size="small" onClick={() => copy(p.row.id)} aria-label={t('admin.users.tooltips.copyUserId')}>
<ContentCopyRoundedIcon fontSize="small" />

View File

@ -118,6 +118,20 @@ export const en = {
referralUnknown: 'Unknown or ineligible referral code',
referralInvalidWithReason: 'Referral code not accepted: {{reason}}',
referralEmpty: 'Leave empty to use the platform default referrer',
useDefaultReferrer: 'Continue with the default referrer',
usingDefaultReferrer: 'You will be registered with the platform default referrer.',
referralFixOrUseDefault:
'This referral code cannot be used. Clear it or continue with the default referrer.',
referralReasons: {
empty: 'No referral code provided',
program_disabled: 'The referral program is currently disabled',
unknown_code: 'Unknown referral code',
'Referrer must have completed at least one deposit':
'The referrer must have completed at least one real-funds deposit',
'Referrer must have a verified email': 'The referrer must have a verified email',
'Referrer account is not eligible': 'The referrer account is not eligible',
'Invalid referral code': 'Invalid referral code',
},
creatingAccount: 'Creating account…',
registerFieldsRequired:
'Full name, email, password, confirm password, country of residence, and gender are required.',
@ -1119,6 +1133,7 @@ export const en = {
nonLocked: 'Non locked',
credsValid: 'Creds valid',
copy: 'Copy',
actions: 'Actions',
},
tooltips: {
verifyEmail: 'Click to mark email as verified (admin)',

View File

@ -120,6 +120,20 @@ export const fr = {
referralUnknown: 'Code de parrainage inconnu ou non éligible',
referralInvalidWithReason: 'Code de parrainage refusé : {{reason}}',
referralEmpty: 'Laissez vide pour utiliser le parrain par défaut de la plateforme',
useDefaultReferrer: 'Continuer avec le parrain par défaut',
usingDefaultReferrer: 'Vous serez inscrit avec le parrain par défaut de la plateforme.',
referralFixOrUseDefault:
'Ce code de parrainage ne peut pas être utilisé. Effacez-le ou continuez avec le parrain par défaut.',
referralReasons: {
empty: 'Aucun code de parrainage fourni',
program_disabled: 'Le programme de parrainage est actuellement désactivé',
unknown_code: 'Code de parrainage inconnu',
'Referrer must have completed at least one deposit':
'Le parrain doit avoir effectué au moins un dépôt avec des fonds réels',
'Referrer must have a verified email': 'Le parrain doit avoir un e-mail vérifié',
'Referrer account is not eligible': 'Le compte du parrain n’est pas éligible',
'Invalid referral code': 'Code de parrainage invalide',
},
creatingAccount: 'Création du compte…',
registerFieldsRequired:
'Le nom complet, l’e-mail, le mot de passe, la confirmation, le pays de résidence et le sexe sont obligatoires.',
@ -1134,6 +1148,7 @@ export const fr = {
nonLocked: 'Non verrouillé',
credsValid: 'Ident. valides',
copy: 'Copier',
actions: 'Actions',
},
tooltips: {
verifyEmail: 'Cliquer pour marquer l’e-mail comme vérifié (admin)',