rework-onboarding (#7)
Onboarding completato, ora super rapido e top Reviewed-on: http://catelliub.zapto.org:3000/brontomark/flux/pulls/7 Co-authored-by: Mark M2 Macbook <marco@catelli.it> Co-committed-by: Mark M2 Macbook <marco@catelli.it>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/features/master_data/staff/data/staff_repository.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
import 'package:flux/features/master_data/store/models/store_model.dart';
|
||||
@@ -10,7 +10,7 @@ part 'staff_state.dart';
|
||||
|
||||
class StaffCubit extends Cubit<StaffState> {
|
||||
final StaffRepository _repository = GetIt.I.get<StaffRepository>();
|
||||
final SessionBloc _sessionBloc = GetIt.I<SessionBloc>();
|
||||
final SessionCubit _sessionCubit = GetIt.I<SessionCubit>();
|
||||
|
||||
StaffCubit() : super(const StaffState());
|
||||
|
||||
@@ -19,7 +19,7 @@ class StaffCubit extends Cubit<StaffState> {
|
||||
emit(state.copyWith(isLoading: true, error: null));
|
||||
try {
|
||||
final staff = await _repository.getStaffMembers(
|
||||
_sessionBloc.state.company!.id,
|
||||
_sessionCubit.state.company!.id!,
|
||||
);
|
||||
final Map<String, List<StoreModel>> storesByStaff = {};
|
||||
for (StaffMemberModel member in staff) {
|
||||
|
||||
@@ -1,47 +1,119 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flux/core/utils/string_extensions.dart'; // Assicurati che il percorso sia corretto
|
||||
|
||||
// L'Enum magico e blindato per il sistema
|
||||
enum SystemRole {
|
||||
admin,
|
||||
manager,
|
||||
user;
|
||||
|
||||
// Helper per convertire dal DB a Dart in sicurezza
|
||||
static SystemRole fromString(String? value) {
|
||||
return SystemRole.values.firstWhere(
|
||||
(e) => e.name == value,
|
||||
orElse: () => SystemRole.user, // Fallback paranoico al livello più basso
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class StaffMemberModel extends Equatable {
|
||||
final String? id;
|
||||
final String name;
|
||||
final String email;
|
||||
final String phone;
|
||||
final bool isActive;
|
||||
final String companyId;
|
||||
final String userId;
|
||||
final String name;
|
||||
final String? email;
|
||||
final String? phoneNumber;
|
||||
final String? jobTitle;
|
||||
final SystemRole systemRole;
|
||||
final bool isActive;
|
||||
|
||||
const StaffMemberModel({
|
||||
this.id,
|
||||
required this.name,
|
||||
this.email = '',
|
||||
this.phone = '',
|
||||
this.isActive = true,
|
||||
required this.companyId,
|
||||
required this.userId,
|
||||
required this.name,
|
||||
this.email,
|
||||
this.phoneNumber,
|
||||
this.jobTitle,
|
||||
this.systemRole = SystemRole.user,
|
||||
this.isActive = true,
|
||||
});
|
||||
|
||||
StaffMemberModel copyWith({
|
||||
String? id,
|
||||
String? companyId,
|
||||
String? userId,
|
||||
String? name,
|
||||
String? surname,
|
||||
String? email,
|
||||
String? phoneNumber,
|
||||
String? jobTitle,
|
||||
SystemRole? systemRole,
|
||||
bool? isActive,
|
||||
}) {
|
||||
return StaffMemberModel(
|
||||
id: id ?? this.id,
|
||||
companyId: companyId ?? this.companyId,
|
||||
userId: userId ?? this.userId,
|
||||
name: name ?? this.name,
|
||||
email: email ?? this.email,
|
||||
phoneNumber: phoneNumber ?? this.phoneNumber,
|
||||
jobTitle: jobTitle ?? this.jobTitle,
|
||||
systemRole: systemRole ?? this.systemRole,
|
||||
isActive: isActive ?? this.isActive,
|
||||
);
|
||||
}
|
||||
|
||||
factory StaffMemberModel.empty() {
|
||||
return const StaffMemberModel(
|
||||
companyId: '',
|
||||
userId: '',
|
||||
name: '',
|
||||
email: '',
|
||||
phoneNumber: '',
|
||||
jobTitle: '',
|
||||
systemRole: SystemRole.user,
|
||||
isActive: true,
|
||||
);
|
||||
}
|
||||
|
||||
factory StaffMemberModel.fromMap(Map<String, dynamic> map) {
|
||||
return StaffMemberModel(
|
||||
id: map['id'],
|
||||
// Applichiamo il tuo myFormat per visualizzare i nomi correttamente
|
||||
name: (map['name'] as String).myFormat(),
|
||||
// L'email la teniamo lowercase per standard tecnico
|
||||
email: (map['email'] as String? ?? '').toLowerCase().trim(),
|
||||
phone: (map['phone'] as String? ?? '').trim(),
|
||||
id: map['id'] as String?,
|
||||
companyId: map['company_id'] ?? '',
|
||||
userId: map['user_id'] ?? '',
|
||||
name: map['name'] ?? '',
|
||||
email: map['email'] as String?,
|
||||
phoneNumber: map['phone_number'] as String?,
|
||||
jobTitle: map['job_title'] as String?,
|
||||
systemRole: SystemRole.fromString(map['system_role']),
|
||||
isActive: map['is_active'] ?? true,
|
||||
companyId: map['company_id'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
if (id != null) 'id': id,
|
||||
'name': name.toLowerCase().trim(), // Salviamo pulito per le query
|
||||
'email': email.toLowerCase().trim(),
|
||||
'phone': phone.trim(),
|
||||
'is_active': isActive,
|
||||
'company_id': companyId,
|
||||
'user_id': userId,
|
||||
'name': name,
|
||||
if (email != null) 'email': email,
|
||||
if (phoneNumber != null) 'phone_number': phoneNumber,
|
||||
if (jobTitle != null) 'job_title': jobTitle,
|
||||
'system_role': systemRole.name, // Trasforma SystemRole.admin in 'admin'
|
||||
'is_active': isActive,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, name, email, phone, isActive, companyId];
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
companyId,
|
||||
userId,
|
||||
name,
|
||||
email,
|
||||
phoneNumber,
|
||||
jobTitle,
|
||||
systemRole,
|
||||
isActive,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/core/theme/theme.dart';
|
||||
import 'package:flux/core/widgets/flux_text_field.dart';
|
||||
import 'package:flux/features/master_data/staff/blocs/staff_cubit.dart'; // Tuo percorso
|
||||
@@ -135,8 +135,13 @@ class _StaffScreenState extends State<StaffScreen> {
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (member.email.isNotEmpty) Text(member.email),
|
||||
Text(member.phone.isNotEmpty ? member.phone : "Nessun telefono"),
|
||||
if (member.email != null && member.email!.isNotEmpty)
|
||||
Text(member.email!),
|
||||
Text(
|
||||
member.phoneNumber != null && member.phoneNumber!.isNotEmpty
|
||||
? member.phoneNumber!
|
||||
: "Nessun telefono",
|
||||
),
|
||||
],
|
||||
),
|
||||
trailing: const Icon(Icons.edit_note),
|
||||
@@ -148,7 +153,7 @@ class _StaffScreenState extends State<StaffScreen> {
|
||||
void _openStaffForm(BuildContext context, {StaffMemberModel? member}) {
|
||||
final nameController = TextEditingController(text: member?.name);
|
||||
final emailController = TextEditingController(text: member?.email);
|
||||
final phoneController = TextEditingController(text: member?.phone);
|
||||
final phoneController = TextEditingController(text: member?.phoneNumber);
|
||||
|
||||
// 1. Inizializziamo la lista temporanea attingendo dallo stato del Cubit
|
||||
// Usiamo storesByStaff (la mappa che indicizza i negozi per ogni ID dipendente)
|
||||
@@ -264,16 +269,16 @@ class _StaffScreenState extends State<StaffScreen> {
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
final companyId = context
|
||||
.read<SessionBloc>()
|
||||
.read<SessionCubit>()
|
||||
.state
|
||||
.company!
|
||||
.id;
|
||||
|
||||
final updatedMember = StaffMemberModel(
|
||||
.id!;
|
||||
//TODO sistemare StaffScreen per il nuovo modello
|
||||
/* final updatedMember = StaffMemberModel(
|
||||
id: member?.id,
|
||||
name: nameController.text,
|
||||
email: emailController.text,
|
||||
phone: phoneController.text,
|
||||
phoneNumber: phoneController.text,
|
||||
companyId: companyId,
|
||||
);
|
||||
|
||||
@@ -281,7 +286,7 @@ class _StaffScreenState extends State<StaffScreen> {
|
||||
context.read<StaffCubit>().saveStaffWithStores(
|
||||
member: updatedMember,
|
||||
selectedStoreIds: tempSelectedStores,
|
||||
);
|
||||
); */
|
||||
|
||||
Navigator.pop(context);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user