aggiunta staff section a OperationFormScreen
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user