aggiunta staff section a OperationFormScreen

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-05-03 13:03:50 +02:00
parent eb66a707cc
commit 212f33ff51
4 changed files with 47 additions and 25 deletions

View File

@@ -19,6 +19,7 @@ import 'package:flux/features/master_data/products/blocs/product_cubit.dart';
import 'package:flux/features/master_data/products/ui/products_screen.dart';
import 'package:flux/features/master_data/providers/blocs/provider_cubit.dart';
import 'package:flux/features/master_data/providers/ui/providers_master_data_screen.dart';
import 'package:flux/features/master_data/staff/blocs/staff_cubit.dart';
import 'package:flux/features/master_data/staff/ui/staff_screen.dart';
import 'package:flux/features/master_data/store/ui/stores_screen.dart';
import 'package:flux/features/onboarding/blocs/onboarding_cubit.dart';
@@ -179,12 +180,19 @@ class AppRouter {
builder: (context, state) {
final existingOperation = state.extra as OperationModel?;
final operationId = state.uri.queryParameters['operationId'];
final currentStoreId = GetIt.I
.get<SessionCubit>()
.state
.currentStore!
.id!;
context.read<CustomersCubit>().loadCustomers();
context.read<ProvidersCubit>().loadActiveProvidersForStore(
GetIt.I.get<SessionCubit>().state.currentStore!.id!,
currentStoreId,
);
context.read<ProductsCubit>().loadModels();
context.read<ProductsCubit>().loadBrands();
context.read<StaffCubit>().loadStaffForStore(currentStoreId);
return BlocProvider(
create: (context) => OperationFilesBloc(
operationId: operationId ?? existingOperation?.id,
@@ -202,6 +210,18 @@ class AppRouter {
final operationId = state.pathParameters['id']!;
final operationName =
state.uri.queryParameters['name'] ?? 'Pratica';
final currentStoreId = GetIt.I
.get<SessionCubit>()
.state
.currentStore!
.id!;
context.read<CustomersCubit>().loadCustomers();
context.read<ProvidersCubit>().loadActiveProvidersForStore(
currentStoreId,
);
context.read<ProductsCubit>().loadModels();
context.read<ProductsCubit>().loadBrands();
context.read<StaffCubit>().loadStaffForStore(currentStoreId);
return BlocProvider(
create: (context) => OperationFilesBloc(operationId: operationId),
child: OperationMobileUploadScreen(

View File

@@ -56,7 +56,7 @@ class StaffCubit extends Cubit<StaffState> {
state.staffByStore,
);
newMap[storeId] = staffInStore;
emit(state.copyWith(staffByStore: newMap));
emit(state.copyWith(staffByStore: newMap, storeStaff: staffInStore));
} catch (e) {
emit(state.copyWith(status: StaffStatus.error, error: e.toString()));
}

View File

@@ -7,6 +7,7 @@ class StaffState extends Equatable {
final List<StaffMemberModel> allStaff;
final Map<String, List<StoreModel>> storesByStaff;
final Map<String, List<StaffMemberModel>> staffByStore;
final List<StaffMemberModel> storeStaff;
final String? error;
const StaffState({
@@ -14,6 +15,7 @@ class StaffState extends Equatable {
this.allStaff = const [],
this.storesByStaff = const {},
this.staffByStore = const {},
this.storeStaff = const [],
this.error,
});
@@ -22,6 +24,7 @@ class StaffState extends Equatable {
List<StaffMemberModel>? allStaff,
Map<String, List<StoreModel>>? storesByStaff,
Map<String, List<StaffMemberModel>>? staffByStore,
List<StaffMemberModel>? storeStaff,
String? error,
}) {
return StaffState(
@@ -29,6 +32,7 @@ class StaffState extends Equatable {
allStaff: allStaff ?? this.allStaff,
storesByStaff: storesByStaff ?? this.storesByStaff,
staffByStore: staffByStore ?? this.staffByStore,
storeStaff: storeStaff ?? this.storeStaff,
error: error,
);
}
@@ -39,6 +43,7 @@ class StaffState extends Equatable {
allStaff,
storesByStaff,
staffByStore,
storeStaff,
error,
];
}

View File

@@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flux/core/blocs/session/session_cubit.dart';
import 'package:flux/features/master_data/staff/blocs/staff_cubit.dart';
import 'package:flux/features/operations/blocs/operations_cubit.dart';
import 'package:flux/features/operations/models/operation_model.dart';
import 'package:get_it/get_it.dart';
// IMPORTA IL TUO CUBIT DELLO STAFF
// import 'package:flux/features/staff/blocs/staff_cubit.dart';
@@ -13,7 +16,9 @@ class StaffSection extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final selectedStaffId = currentOp?.staffId;
final selectedStaffId =
currentOp?.staffId ??
GetIt.I.get<SessionCubit>().state.currentStaffMember?.id;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -27,37 +32,27 @@ class StaffSection extends StatelessWidget {
),
),
),
// Ascoltiamo il Cubit che contiene la lista dei membri dello staff del negozio
// BlocBuilder<StaffCubit, StaffState>(
// builder: (context, state) {
// final staffMembers = state.storeStaff;
// Sostituisci questo blocco 'simulato' con i dati veri del tuo BlocBuilder
Builder(
builder: (context) {
BlocBuilder<StaffCubit, StaffState>(
builder: (context, state) {
// Dati finti per farti vedere la UI, piallali quando attacchi il BlocBuilder!
final staffMembers = [
{'id': '1', 'name': 'Tu (Admin)'},
{'id': '2', 'name': 'Marco'},
{'id': '3', 'name': 'Giulia'},
];
final staffMembers = state.storeStaff;
final currentLoggedStaffMember = GetIt.I
.get<SessionCubit>()
.state
.currentStaffMember;
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: staffMembers.map((staff) {
final staffId = staff['id'] as String;
final staffName = staff['name'] as String;
final isSelected = staffId == selectedStaffId;
final isSelected = staff.id == selectedStaffId;
return GestureDetector(
onTap: () {
// Aggiorniamo la form con un solo tap!
context.read<OperationsCubit>().updateOperationFields(
staffId: staffId,
staffDisplayName: staffName,
staffId: staff.id,
staffDisplayName: staff.name,
);
},
child: AnimatedContainer(
@@ -99,7 +94,7 @@ class StaffSection extends StatelessWidget {
? Colors.white
: theme.colorScheme.primaryContainer,
child: Text(
staffName.substring(0, 1).toUpperCase(),
staff.name.substring(0, 1).toUpperCase(),
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
@@ -111,7 +106,9 @@ class StaffSection extends StatelessWidget {
),
const SizedBox(width: 8),
Text(
staffName,
staff == currentLoggedStaffMember
? 'Tu (${staff.name})'
: staff.name,
style: TextStyle(
fontWeight: isSelected
? FontWeight.bold