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,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,
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user