petitspas/frontend/lib/services/reprise_session.dart
Julien Martin c26ed00374 fix(#112): préremplissage AM complet en reprise + lien login repositionné
Parse dates/places/consentement de façon robuste, rafraîchit l'étape 2 AM
et place « J'ai un numéro de dossier » sous « Créer un compte ».

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 17:29:31 +02:00

59 lines
1.7 KiB
Dart

import 'package:p_tits_pas/models/am_registration_data.dart';
import 'package:p_tits_pas/models/reprise_dossier.dart';
import 'package:p_tits_pas/models/user_registration_data.dart';
import 'package:p_tits_pas/services/api/api_config.dart';
import 'package:p_tits_pas/utils/reprise_mapper.dart';
/// Contexte reprise après refus (token e-mail ou identify). Ticket #112.
class RepriseSession {
RepriseSession._();
static String? _token;
static String? _role;
static String? _photoUrl;
static String? _photoUrlForApi;
static bool get isActive =>
_token != null && _token!.trim().isNotEmpty;
static String? get token => _token;
static bool get isParent => _role == 'parent';
static bool get isAm => _role == 'assistante_maternelle';
/// URL absolue pour l'affichage.
static String? get photoUrl => _photoUrl;
/// Chemin relatif API (`/uploads/…`) pour PATCH sans re-upload.
static String? get photoUrlForApi => _photoUrlForApi;
static void start({
required String token,
required RepriseDossier dossier,
}) {
_token = token.trim();
_role = dossier.role;
final raw = dossier.photoUrl?.trim();
_photoUrlForApi = raw != null && raw.isNotEmpty ? raw : null;
_photoUrl = _photoUrlForApi != null
? ApiConfig.absoluteMediaUrl(_photoUrlForApi)
: null;
}
static void clear() {
_token = null;
_role = null;
_photoUrl = null;
_photoUrlForApi = null;
}
static void applyToParent(UserRegistrationData data, RepriseDossier dossier) {
RepriseMapper.applyParentDossier(data, dossier);
}
static void applyToAm(AmRegistrationData data, RepriseDossier dossier) {
RepriseMapper.applyAmDossier(data, dossier);
}
}