mmmh
This commit is contained in:
@@ -8,6 +8,7 @@ import 'package:flux/features/settings/data/settings_repository.dart';
|
||||
import 'package:flux/features/tasks/data/task_repository.dart';
|
||||
import 'package:flux/features/tasks/models/task_model.dart';
|
||||
import 'package:flux/features/tasks/models/task_reminder_config.dart';
|
||||
import 'package:flux/features/tasks/models/task_status.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
part 'task_form_state.dart';
|
||||
|
||||
@@ -30,7 +31,7 @@ class TaskFormCubit extends Cubit<TaskFormState> {
|
||||
}
|
||||
|
||||
String get _companyId => _sessionCubit.state.company!.id!;
|
||||
String get _currentUserId => _sessionCubit.state.currentStaffMember!.id!;
|
||||
StaffMemberModel get _currentUser => _sessionCubit.state.currentStaffMember!;
|
||||
String? get _currentStoreId => _sessionCubit.state.currentStore?.id;
|
||||
|
||||
// --- ARMED INITIALIZATION (Nuovo, Esistente o Deep Link) ---
|
||||
@@ -129,7 +130,7 @@ class TaskFormCubit extends Cubit<TaskFormState> {
|
||||
try {
|
||||
final defaults = await _settingsRepository.getMyReminderDefaults(
|
||||
companyId: _companyId,
|
||||
staffId: _currentUserId,
|
||||
staffId: _currentUser.id!,
|
||||
);
|
||||
final initialReminders = defaults
|
||||
.map(
|
||||
@@ -155,7 +156,7 @@ class TaskFormCubit extends Cubit<TaskFormState> {
|
||||
try {
|
||||
final existingConfigs = await _repository.fetchPersonalReminders(
|
||||
taskId: taskId,
|
||||
staffId: _currentUserId,
|
||||
staffId: _currentUser.id!,
|
||||
);
|
||||
emit(state.copyWith(reminders: existingConfigs));
|
||||
} catch (e) {
|
||||
@@ -218,7 +219,7 @@ class TaskFormCubit extends Cubit<TaskFormState> {
|
||||
final taskToSave = TaskModel(
|
||||
id: state.id,
|
||||
companyId: _companyId,
|
||||
createdById: _currentUserId,
|
||||
createdBy: _currentUser,
|
||||
title: state.title.trim(),
|
||||
description: state.description.trim(),
|
||||
dueDate: state.dueDate,
|
||||
@@ -233,14 +234,14 @@ class TaskFormCubit extends Cubit<TaskFormState> {
|
||||
await _repository.createTask(
|
||||
task: taskToSave,
|
||||
assignedStaffIds: state.selectedStaffIds,
|
||||
currentUserId: _currentUserId,
|
||||
currentUserId: _currentUser.id!,
|
||||
currentUserCustomReminders: state.reminders,
|
||||
);
|
||||
} else {
|
||||
await _repository.updateTask(
|
||||
task: taskToSave,
|
||||
assignedStaffIds: state.selectedStaffIds,
|
||||
currentUserId: _currentUserId,
|
||||
currentUserId: _currentUser.id!,
|
||||
currentUserCustomReminders: state.reminders,
|
||||
);
|
||||
}
|
||||
@@ -254,4 +255,47 @@ class TaskFormCubit extends Cubit<TaskFormState> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteTask() async {
|
||||
if (state.id == null) return;
|
||||
emit(state.copyWith(status: TaskFormStatus.submitting));
|
||||
try {
|
||||
await _repository.deleteTask(state.id!);
|
||||
emit(state.copyWith(status: TaskFormStatus.success));
|
||||
} catch (e) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: TaskFormStatus.failure,
|
||||
errorMessage: e.toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateTaskStatus(TaskStatus newStatus) async {
|
||||
try {
|
||||
// Chiamiamo il repo passando il task aggiornato
|
||||
await _repository.updateTaskStatus(
|
||||
taskId: state.id!,
|
||||
newStatus: newStatus,
|
||||
updatedById: _currentUser.id!,
|
||||
);
|
||||
|
||||
if (!isClosed) {
|
||||
// Se l'update va a buon fine, aggiorniamo lo stato locale del cubit
|
||||
emit(
|
||||
state.copyWith(status: TaskFormStatus.success, taskStatus: newStatus),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (!isClosed) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: TaskFormStatus.failure,
|
||||
errorMessage: e.toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ class TaskFormState extends Equatable {
|
||||
final bool isGlobal;
|
||||
final List<String> selectedStaffIds;
|
||||
final List<TaskReminderConfig> reminders;
|
||||
final Map<String, List<StaffMemberModel>>
|
||||
groupedAvailableStaff; // <-- RIPRISTINATO
|
||||
final Map<String, List<StaffMemberModel>> groupedAvailableStaff;
|
||||
final String? errorMessage;
|
||||
final TaskStatus taskStatus;
|
||||
|
||||
const TaskFormState({
|
||||
this.id,
|
||||
@@ -26,6 +26,7 @@ class TaskFormState extends Equatable {
|
||||
this.reminders = const [],
|
||||
this.groupedAvailableStaff = const {},
|
||||
this.errorMessage,
|
||||
this.taskStatus = TaskStatus.open,
|
||||
});
|
||||
|
||||
bool get isFormValid => title.trim().isNotEmpty;
|
||||
@@ -41,6 +42,7 @@ class TaskFormState extends Equatable {
|
||||
List<TaskReminderConfig>? reminders,
|
||||
Map<String, List<StaffMemberModel>>? groupedAvailableStaff,
|
||||
String? errorMessage,
|
||||
TaskStatus? taskStatus,
|
||||
}) {
|
||||
return TaskFormState(
|
||||
id: id ?? this.id,
|
||||
@@ -54,6 +56,7 @@ class TaskFormState extends Equatable {
|
||||
groupedAvailableStaff:
|
||||
groupedAvailableStaff ?? this.groupedAvailableStaff,
|
||||
errorMessage: errorMessage,
|
||||
taskStatus: taskStatus ?? this.taskStatus,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -69,5 +72,6 @@ class TaskFormState extends Equatable {
|
||||
reminders,
|
||||
groupedAvailableStaff,
|
||||
errorMessage,
|
||||
taskStatus,
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user