mmmh
All checks were successful
Build and Release FLUX (Multi-Platform) / build-android (push) Successful in 2m11s
Build and Release FLUX (Multi-Platform) / build-web (push) Successful in 1m1s
Build and Release FLUX (Multi-Platform) / build-windows (push) Successful in 8m5s

This commit is contained in:
2026-06-04 12:34:38 +02:00
parent 01515910b6
commit 4efc3ce182
14 changed files with 517 additions and 426 deletions

View File

@@ -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(),
),
);
}
}
}
}