mmmmh
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flux/core/blocs/session/session_bloc.dart';
|
||||
import 'package:flux/features/staff/models/staff_member_model.dart';
|
||||
import 'package:flux/features/store/data/store_repository.dart';
|
||||
import 'package:flux/features/store/models/store_model.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
@@ -12,7 +13,8 @@ class StoreBloc extends Bloc<StoreEvent, StoreState> {
|
||||
final StoreRepository _repository = GetIt.I<StoreRepository>();
|
||||
final SessionBloc _sessionBloc;
|
||||
|
||||
StoreBloc(this._sessionBloc) : super(const StoreState(stores: [])) {
|
||||
StoreBloc(this._sessionBloc)
|
||||
: super(const StoreState(stores: [], staffByStore: {})) {
|
||||
on<CreateStoreRequested>(_onCreateStore);
|
||||
on<LoadStoresRequested>(_onLoadStores);
|
||||
}
|
||||
@@ -41,10 +43,20 @@ class StoreBloc extends Bloc<StoreEvent, StoreState> {
|
||||
final stores = await _repository.getStoresByCompany(
|
||||
_sessionBloc.state.company!.id,
|
||||
);
|
||||
final staffByStore = <StoreModel, List<StaffMemberModel>>{};
|
||||
|
||||
for (final store in stores) {
|
||||
final staff = await _repository.getStaffMembersInStore(
|
||||
_sessionBloc.state.company!.id,
|
||||
);
|
||||
staffByStore[store] = staff;
|
||||
}
|
||||
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: StoreStatus.success,
|
||||
stores: stores, // Assicurati di avere 'stores' nello StoreState
|
||||
staffByStore: staffByStore,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
|
||||
@@ -7,12 +7,14 @@ class StoreState extends Equatable {
|
||||
final StoreModel? store;
|
||||
final String? errorMessage;
|
||||
final List<StoreModel> stores;
|
||||
final Map<StoreModel, List<StaffMemberModel>> staffByStore;
|
||||
|
||||
const StoreState({
|
||||
this.status = StoreStatus.initial,
|
||||
this.store,
|
||||
this.errorMessage,
|
||||
required this.stores,
|
||||
required this.staffByStore,
|
||||
});
|
||||
|
||||
StoreState copyWith({
|
||||
@@ -20,15 +22,23 @@ class StoreState extends Equatable {
|
||||
StoreModel? store,
|
||||
String? errorMessage,
|
||||
List<StoreModel>? stores,
|
||||
Map<StoreModel, List<StaffMemberModel>>? staffByStore,
|
||||
}) {
|
||||
return StoreState(
|
||||
status: status ?? this.status,
|
||||
store: store ?? this.store,
|
||||
errorMessage: errorMessage ?? this.errorMessage,
|
||||
stores: stores ?? this.stores,
|
||||
staffByStore: staffByStore ?? this.staffByStore,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [status, store, errorMessage, stores];
|
||||
List<Object?> get props => [
|
||||
status,
|
||||
store,
|
||||
errorMessage,
|
||||
stores,
|
||||
staffByStore,
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user