From 212f33ff516842565771bc3f0c28665bc04af5b4 Mon Sep 17 00:00:00 2001 From: Mark M2 Macbook Date: Sun, 3 May 2026 13:03:50 +0200 Subject: [PATCH] aggiunta staff section a OperationFormScreen Co-authored-by: Copilot --- lib/core/routes/app_router.dart | 22 +++++++++- .../master_data/staff/blocs/staff_cubit.dart | 2 +- .../master_data/staff/blocs/staff_state.dart | 5 +++ .../operations/ui/widgets/staff_section.dart | 43 +++++++++---------- 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/lib/core/routes/app_router.dart b/lib/core/routes/app_router.dart index 1ea8bba..1ac0980 100644 --- a/lib/core/routes/app_router.dart +++ b/lib/core/routes/app_router.dart @@ -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() + .state + .currentStore! + .id!; context.read().loadCustomers(); context.read().loadActiveProvidersForStore( - GetIt.I.get().state.currentStore!.id!, + currentStoreId, ); context.read().loadModels(); context.read().loadBrands(); + context.read().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() + .state + .currentStore! + .id!; + context.read().loadCustomers(); + context.read().loadActiveProvidersForStore( + currentStoreId, + ); + context.read().loadModels(); + context.read().loadBrands(); + context.read().loadStaffForStore(currentStoreId); return BlocProvider( create: (context) => OperationFilesBloc(operationId: operationId), child: OperationMobileUploadScreen( diff --git a/lib/features/master_data/staff/blocs/staff_cubit.dart b/lib/features/master_data/staff/blocs/staff_cubit.dart index 8cd77f5..d231167 100644 --- a/lib/features/master_data/staff/blocs/staff_cubit.dart +++ b/lib/features/master_data/staff/blocs/staff_cubit.dart @@ -56,7 +56,7 @@ class StaffCubit extends Cubit { 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())); } diff --git a/lib/features/master_data/staff/blocs/staff_state.dart b/lib/features/master_data/staff/blocs/staff_state.dart index 2a3b7d4..f3d0723 100644 --- a/lib/features/master_data/staff/blocs/staff_state.dart +++ b/lib/features/master_data/staff/blocs/staff_state.dart @@ -7,6 +7,7 @@ class StaffState extends Equatable { final List allStaff; final Map> storesByStaff; final Map> staffByStore; + final List 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? allStaff, Map>? storesByStaff, Map>? staffByStore, + List? 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, ]; } diff --git a/lib/features/operations/ui/widgets/staff_section.dart b/lib/features/operations/ui/widgets/staff_section.dart index 7c41e07..00967b1 100644 --- a/lib/features/operations/ui/widgets/staff_section.dart +++ b/lib/features/operations/ui/widgets/staff_section.dart @@ -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().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( - // builder: (context, state) { - // final staffMembers = state.storeStaff; - - // Sostituisci questo blocco 'simulato' con i dati veri del tuo BlocBuilder - Builder( - builder: (context) { + BlocBuilder( + 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() + .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().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