feat-ultimi_servizi-contratti_in_scadenza #12

Merged
brontomark merged 18 commits from feat-ultimi_servizi-contratti_in_scadenza into main 2026-05-04 15:36:42 +02:00
4 changed files with 47 additions and 25 deletions
Showing only changes of commit 212f33ff51 - Show all commits

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

View File

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

View File

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

View File

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