110 lines
3.2 KiB
Dart
110 lines
3.2 KiB
Dart
|
|
part of 'task_form_cubit.dart';
|
||
|
|
|
||
|
|
enum TaskFormStatus { initial, loading, submitting, success, failure }
|
||
|
|
|
||
|
|
/// Placeholder finto per i futuri reminder (pg_cron)
|
||
|
|
class TaskReminder extends Equatable {
|
||
|
|
final String type; // es. 'email', 'push'
|
||
|
|
final int minutesBefore;
|
||
|
|
const TaskReminder({required this.type, required this.minutesBefore});
|
||
|
|
@override
|
||
|
|
List<Object?> get props => [type, minutesBefore];
|
||
|
|
}
|
||
|
|
|
||
|
|
class TaskFormState extends Equatable {
|
||
|
|
final TaskFormStatus status;
|
||
|
|
final String? id; // Null se stiamo creando un nuovo task
|
||
|
|
final String title;
|
||
|
|
final String description;
|
||
|
|
final DateTime? dueDate;
|
||
|
|
final TaskStatus taskStatus;
|
||
|
|
|
||
|
|
// --- SCOPING & ASSIGNMENTS ---
|
||
|
|
final bool isGlobal;
|
||
|
|
final List<String> selectedStaffIds;
|
||
|
|
final List<StaffMemberModel> availableStaff;
|
||
|
|
final Map<String, List<StaffMemberModel>> groupedAvailableStaff;
|
||
|
|
|
||
|
|
// --- FUTURI ANCORAGGI ---
|
||
|
|
final List<TaskReminder> reminders;
|
||
|
|
final String? linkedTicketId;
|
||
|
|
final String? linkedEmailId;
|
||
|
|
|
||
|
|
final String? errorMessage;
|
||
|
|
|
||
|
|
const TaskFormState({
|
||
|
|
this.status = TaskFormStatus.initial,
|
||
|
|
this.id,
|
||
|
|
this.title = '',
|
||
|
|
this.description = '',
|
||
|
|
this.dueDate,
|
||
|
|
this.taskStatus = TaskStatus.open,
|
||
|
|
this.isGlobal = false,
|
||
|
|
this.selectedStaffIds = const [],
|
||
|
|
this.availableStaff = const [],
|
||
|
|
this.groupedAvailableStaff = const {},
|
||
|
|
this.reminders = const [],
|
||
|
|
this.linkedTicketId,
|
||
|
|
this.linkedEmailId,
|
||
|
|
this.errorMessage,
|
||
|
|
});
|
||
|
|
|
||
|
|
// MAGIA: Il form è valido solo se c'è un titolo e, opzionalmente, altre regole.
|
||
|
|
bool get isFormValid => title.trim().isNotEmpty;
|
||
|
|
|
||
|
|
TaskFormState copyWith({
|
||
|
|
TaskFormStatus? status,
|
||
|
|
String? id,
|
||
|
|
String? title,
|
||
|
|
String? description,
|
||
|
|
DateTime? dueDate,
|
||
|
|
bool clearDueDate = false, // Trucco Ninja per rimettere a null una data!
|
||
|
|
TaskStatus? taskStatus,
|
||
|
|
bool? isGlobal,
|
||
|
|
List<String>? selectedStaffIds,
|
||
|
|
List<StaffMemberModel>? availableStaff,
|
||
|
|
Map<String, List<StaffMemberModel>>? groupedAvailableStaff,
|
||
|
|
List<TaskReminder>? reminders,
|
||
|
|
String? linkedTicketId,
|
||
|
|
String? linkedEmailId,
|
||
|
|
String? errorMessage,
|
||
|
|
}) {
|
||
|
|
return TaskFormState(
|
||
|
|
status: status ?? this.status,
|
||
|
|
id: id ?? this.id,
|
||
|
|
title: title ?? this.title,
|
||
|
|
description: description ?? this.description,
|
||
|
|
dueDate: clearDueDate ? null : (dueDate ?? this.dueDate),
|
||
|
|
taskStatus: taskStatus ?? this.taskStatus,
|
||
|
|
isGlobal: isGlobal ?? this.isGlobal,
|
||
|
|
selectedStaffIds: selectedStaffIds ?? this.selectedStaffIds,
|
||
|
|
availableStaff: availableStaff ?? this.availableStaff,
|
||
|
|
groupedAvailableStaff:
|
||
|
|
groupedAvailableStaff ?? this.groupedAvailableStaff,
|
||
|
|
reminders: reminders ?? this.reminders,
|
||
|
|
linkedTicketId: linkedTicketId ?? this.linkedTicketId,
|
||
|
|
linkedEmailId: linkedEmailId ?? this.linkedEmailId,
|
||
|
|
errorMessage:
|
||
|
|
errorMessage, // Se copyWith è chiamato senza errore, lo pulisce in automatico
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
@override
|
||
|
|
List<Object?> get props => [
|
||
|
|
status,
|
||
|
|
id,
|
||
|
|
title,
|
||
|
|
description,
|
||
|
|
dueDate,
|
||
|
|
taskStatus,
|
||
|
|
isGlobal,
|
||
|
|
selectedStaffIds,
|
||
|
|
availableStaff,
|
||
|
|
groupedAvailableStaff,
|
||
|
|
reminders,
|
||
|
|
linkedTicketId,
|
||
|
|
linkedEmailId,
|
||
|
|
errorMessage,
|
||
|
|
];
|
||
|
|
}
|