aiuto
This commit is contained in:
@@ -1,51 +1,69 @@
|
||||
part of 'session_bloc.dart';
|
||||
part of 'session_cubit.dart';
|
||||
|
||||
/// Definisce lo stato macroscopico della sessione
|
||||
enum SessionStatus {
|
||||
unknown,
|
||||
initial,
|
||||
unauthenticated,
|
||||
authenticatedNoCompany, // Loggato ma deve creare l'azienda
|
||||
authenticatedNoStore, // Ha l'azienda ma deve creare/scegliere il primo negozio
|
||||
ready,
|
||||
onboardingRequired,
|
||||
authenticated,
|
||||
}
|
||||
|
||||
/// Definisce lo step esatto dell'onboarding (Paranoia Mode)
|
||||
enum OnboardingStep {
|
||||
none, // Non serve onboarding
|
||||
company, // Step 1: Manca l'azienda
|
||||
store, // Step 2: Manca il negozio
|
||||
staff, // Step 3: Manca il profilo staff ("Paziente Zero")
|
||||
completed, // Flusso terminato con successo
|
||||
}
|
||||
|
||||
class SessionState extends Equatable {
|
||||
final SessionStatus status;
|
||||
final String? userId;
|
||||
final User? user; // Utente di Supabase Auth
|
||||
final CompanyModel? company;
|
||||
final StoreModel? selectedStore;
|
||||
final List<StoreModel> availableStores; // Utile per uno switcher in futuro
|
||||
final StoreModel? currentStore;
|
||||
final StaffMemberModel? currentStaff;
|
||||
final OnboardingStep onboardingStep;
|
||||
|
||||
const SessionState({
|
||||
this.status = SessionStatus.unknown,
|
||||
this.userId,
|
||||
this.status = SessionStatus.initial,
|
||||
this.user,
|
||||
this.company,
|
||||
this.selectedStore,
|
||||
this.availableStores = const [],
|
||||
this.currentStore,
|
||||
this.currentStaff,
|
||||
this.onboardingStep = OnboardingStep.none,
|
||||
});
|
||||
|
||||
/// Metodo per creare una copia dello stato modificando solo i campi necessari
|
||||
SessionState copyWith({
|
||||
SessionStatus? status,
|
||||
User? user,
|
||||
CompanyModel? company,
|
||||
StoreModel? currentStore,
|
||||
StaffMemberModel? currentStaff,
|
||||
OnboardingStep? onboardingStep,
|
||||
}) {
|
||||
return SessionState(
|
||||
status: status ?? this.status,
|
||||
user: user ?? this.user,
|
||||
company: company ?? this.company,
|
||||
currentStore: currentStore ?? this.currentStore,
|
||||
currentStaff: currentStaff ?? this.currentStaff,
|
||||
onboardingStep: onboardingStep ?? this.onboardingStep,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
status,
|
||||
userId,
|
||||
user,
|
||||
company,
|
||||
selectedStore,
|
||||
availableStores,
|
||||
currentStore,
|
||||
currentStaff,
|
||||
onboardingStep,
|
||||
];
|
||||
|
||||
// copyWith per aggiornare solo un pezzo (es. quando cambi negozio)
|
||||
SessionState copyWith({
|
||||
SessionStatus? status,
|
||||
String? userId,
|
||||
CompanyModel? company,
|
||||
StoreModel? selectedStore,
|
||||
List<StoreModel>? availableStores,
|
||||
}) {
|
||||
return SessionState(
|
||||
status: status ?? this.status,
|
||||
userId: userId ?? this.userId,
|
||||
company: company ?? this.company,
|
||||
selectedStore: selectedStore ?? this.selectedStore,
|
||||
availableStores: availableStores ?? this.availableStores,
|
||||
);
|
||||
}
|
||||
// Helper rapidi per la UI
|
||||
bool get isAuthenticated => status == SessionStatus.authenticated;
|
||||
bool get needsOnboarding => status == SessionStatus.onboardingRequired;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user