added singleUserMode and removed StaffSection from forms
This commit is contained in:
@@ -188,11 +188,13 @@ class HomeScreen extends StatelessWidget {
|
||||
icon: Icons.add,
|
||||
label: context.l10n.commonOperation,
|
||||
color: Colors.blue,
|
||||
onTap: () {
|
||||
// Entriamo nel form! Nessun parametro extra = Nuovo Servizio
|
||||
onTap: () async {
|
||||
StaffMemberModel? createdBy = await getStaffMember(context);
|
||||
if (createdBy == null || !context.mounted) return;
|
||||
context.pushNamed(
|
||||
Routes.operationForm,
|
||||
pathParameters: {'id': 'new'},
|
||||
extra: (createdBy: createdBy, operation: null),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -207,7 +209,7 @@ class HomeScreen extends StatelessWidget {
|
||||
context.pushNamed(
|
||||
Routes.ticketForm,
|
||||
pathParameters: {'id': 'new'},
|
||||
extra: createdBy,
|
||||
extra: (createdBy: createdBy, ticket: null),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/features/customers/models/customer_model.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
import 'package:flux/features/operations/data/operations_repository.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
@@ -13,22 +14,20 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
||||
final OperationsRepository _repository = GetIt.I<OperationsRepository>();
|
||||
final SessionCubit _sessionCubit = GetIt.I<SessionCubit>();
|
||||
final Uuid _uuid = const Uuid();
|
||||
final String createdById;
|
||||
final String createdByName;
|
||||
|
||||
OperationFormCubit({required this.createdById, required this.createdByName})
|
||||
: super(
|
||||
OperationFormState(
|
||||
// Inizializziamo con un modello vuoto di sicurezza
|
||||
operation: OperationModel(
|
||||
storeId: '',
|
||||
companyId: '',
|
||||
reference: '',
|
||||
status: OperationStatus.draft,
|
||||
createdAt: DateTime.now(),
|
||||
),
|
||||
),
|
||||
);
|
||||
OperationFormCubit({
|
||||
StaffMemberModel? createdBy,
|
||||
OperationModel? existingOperation,
|
||||
}) : super(
|
||||
OperationFormState(
|
||||
operation:
|
||||
existingOperation ??
|
||||
OperationModel.empty().copyWith(
|
||||
staffId: createdBy?.id,
|
||||
staffDisplayName: createdBy?.name,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Future<void> initForm({
|
||||
OperationModel? existingOperation,
|
||||
@@ -45,26 +44,37 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
||||
),
|
||||
);
|
||||
} else if (operationId != null) {
|
||||
// Avendo separato i cubit, se ci passano solo l'ID lo scarichiamo dal DB
|
||||
final operation = await _repository.fetchOperationById(operationId);
|
||||
emit(
|
||||
state.copyWith(
|
||||
operation: operation,
|
||||
status: OperationFormStatus.ready,
|
||||
),
|
||||
);
|
||||
emit(state.copyWith(status: OperationFormStatus.loading));
|
||||
try {
|
||||
final operation = await _repository.fetchOperationById(operationId);
|
||||
emit(
|
||||
state.copyWith(
|
||||
operation: operation,
|
||||
status: OperationFormStatus.ready,
|
||||
),
|
||||
);
|
||||
} on Exception catch (e) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: OperationFormStatus.failure,
|
||||
errorMessage: e.toString(),
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// NUOVA PRATICA: Creiamo un nuovo Batch UUID
|
||||
final currentStore = _sessionCubit.state.currentStore;
|
||||
final companyId = _sessionCubit.state.company?.id ?? '';
|
||||
final newOperation = state.operation.copyWith(
|
||||
companyId: companyId,
|
||||
storeId: currentStore?.id,
|
||||
status: OperationStatus.success,
|
||||
reference: '',
|
||||
batchUuid: _uuid.v4(),
|
||||
);
|
||||
emit(
|
||||
state.copyWith(
|
||||
operation: OperationModel(
|
||||
storeId: _sessionCubit.state.currentStore?.id ?? '',
|
||||
reference: '',
|
||||
createdAt: DateTime.now(),
|
||||
companyId: _sessionCubit.state.company!.id!,
|
||||
status: OperationStatus.draft,
|
||||
batchUuid: _uuid.v4(),
|
||||
),
|
||||
operation: newOperation,
|
||||
status: OperationFormStatus.ready,
|
||||
),
|
||||
);
|
||||
|
||||
@@ -187,7 +187,9 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
state.operation.id == null ? 'Nuova Pratica' : 'Modifica Pratica',
|
||||
state.operation.id == null
|
||||
? 'Nuova Pratica - Operatore: ${state.operation.staffDisplayName}'
|
||||
: 'Modifica Pratica - Operatore: ${state.operation.staffDisplayName}',
|
||||
),
|
||||
// Mettiamo un piccolo indicatore visivo anche nella AppBar se non è OK
|
||||
actions:
|
||||
@@ -570,8 +572,8 @@ class _OperationFormScreenState extends State<OperationFormScreen> {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildStaffSection(state),
|
||||
const Divider(height: 50),
|
||||
/* _buildStaffSection(state),
|
||||
const Divider(height: 50), */
|
||||
_buildOperationStatusSection(state),
|
||||
const Divider(height: 32),
|
||||
_buildCustomerSection(state),
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/routes/routes.dart';
|
||||
import 'package:flux/core/widgets/staff_selector_modal.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
import 'package:flux/features/operations/blocs/operation_list_cubit.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@@ -113,7 +116,15 @@ class _OperationListScreenState extends State<OperationListScreen> {
|
||||
},
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => startNewOperation(context),
|
||||
onPressed: () async {
|
||||
StaffMemberModel? createdBy = await getStaffMember(context);
|
||||
if (createdBy == null || !context.mounted) return;
|
||||
context.pushNamed(
|
||||
Routes.operationForm,
|
||||
pathParameters: {'id': 'new'},
|
||||
extra: (createdBy: createdBy, operation: null),
|
||||
);
|
||||
},
|
||||
child: const Icon(Icons.add),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -12,37 +12,36 @@ import 'ticket_form_state.dart';
|
||||
class TicketFormCubit extends Cubit<TicketFormState> {
|
||||
final TicketRepository _repository = GetIt.I.get<TicketRepository>();
|
||||
final SessionCubit _sessionCubit = GetIt.I.get<SessionCubit>();
|
||||
final StaffMemberModel? _createdBy;
|
||||
|
||||
TicketFormCubit({StaffMemberModel? createdBy})
|
||||
// Costruttore: prepariamo subito il ticket base con i dati di chi lo crea
|
||||
TicketFormCubit({StaffMemberModel? createdBy, TicketModel? existingTicket})
|
||||
: super(
|
||||
// Inizializziamo con un ticket vuoto di default
|
||||
TicketFormState(
|
||||
ticket: TicketModel.empty().copyWith(
|
||||
createdById: createdBy?.id,
|
||||
createdByName: createdBy?.name,
|
||||
),
|
||||
// Se c'è un ticket esistente usa quello, ALTRIMENTI ne crea uno vuoto
|
||||
// e ci stampa subito il nome del creatore!
|
||||
ticket:
|
||||
existingTicket ??
|
||||
TicketModel.empty().copyWith(
|
||||
createdById: createdBy?.id,
|
||||
createdByName: createdBy?.name,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/// 1. INIZIALIZZAZIONE (Se stiamo modificando un ticket esistente)
|
||||
/// 1. INIZIALIZZAZIONE
|
||||
Future<void> initForm({String? id, TicketModel? existingTicket}) async {
|
||||
if (existingTicket != null) {
|
||||
// SCENARIO 1 (App Native / Navigazione interna Web):
|
||||
// Abbiamo l'oggetto intero passato via 'extra'. Lo mostriamo all'istante!
|
||||
// SCENARIO 1: Abbiamo il ticket intero passato via record
|
||||
emit(
|
||||
state.copyWith(ticket: existingTicket, status: TicketFormStatus.ready),
|
||||
);
|
||||
} else if (id != null) {
|
||||
// SCENARIO 2 (Web Refresh o Link condiviso):
|
||||
// L'utente ha premuto F5 su /tickets/form/123. L'extra è andato perso, ma abbiamo l'ID!
|
||||
emit(
|
||||
state.copyWith(status: TicketFormStatus.loading),
|
||||
); // Mostriamo uno spinner
|
||||
// SCENARIO 2: QR CODE o Web Refresh! (Hai solo l'ID)
|
||||
emit(state.copyWith(status: TicketFormStatus.loading));
|
||||
|
||||
try {
|
||||
final fetchedTicket = await _repository.getTicketById(
|
||||
id,
|
||||
); // Lo scarichiamo!
|
||||
// Boom! Lo scarica dal database in tempo reale
|
||||
final fetchedTicket = await _repository.getTicketById(id);
|
||||
emit(
|
||||
state.copyWith(ticket: fetchedTicket, status: TicketFormStatus.ready),
|
||||
);
|
||||
@@ -55,19 +54,17 @@ class TicketFormCubit extends Cubit<TicketFormState> {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// SCENARIO 3 (Nuovo Ticket):
|
||||
// È un nuovo ticket! Inseriamo i default base (Azienda, Negozio, Creatore)
|
||||
// SCENARIO 3: Nuovo Ticket
|
||||
final currentStore = _sessionCubit.state.currentStore;
|
||||
final companyId = _sessionCubit.state.company?.id ?? '';
|
||||
|
||||
final newTicket = TicketModel.empty().copyWith(
|
||||
// IL TRUCCO È QUI: Usiamo `state.ticket` invece di `TicketModel.empty()`.
|
||||
// `state.ticket` HA GIÀ i dati di 'createdBy' settati nel costruttore!
|
||||
final newTicket = state.ticket.copyWith(
|
||||
companyId: companyId,
|
||||
storeId: currentStore?.id,
|
||||
createdById: createdBy.id,
|
||||
createdByName: _createdBy.name,
|
||||
// Impostiamo lo stato iniziale
|
||||
ticketStatus: TicketStatus.open,
|
||||
ticketType: TicketType.repair, // Default
|
||||
ticketStatus: TicketStatus.open, // <-- O il tuo status di default
|
||||
ticketType: TicketType.repair,
|
||||
);
|
||||
|
||||
emit(state.copyWith(ticket: newTicket, status: TicketFormStatus.ready));
|
||||
|
||||
@@ -297,7 +297,9 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
ticket.id == null ? 'Nuova Scheda Assistenza' : 'Modifica Scheda',
|
||||
ticket.id == null
|
||||
? 'Nuovo Ticket - Operatore: ${state.ticket.createdByName}'
|
||||
: 'Modifica Ticket - Operatore: ${state.ticket.createdByName}',
|
||||
),
|
||||
actions: [
|
||||
BlocBuilder<TicketFormCubit, TicketFormState>(
|
||||
@@ -559,7 +561,7 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
icon: Icons.person,
|
||||
themeColor: Colors.indigo,
|
||||
children: [
|
||||
StaffSection(
|
||||
/* StaffSection(
|
||||
label: 'Creato Da',
|
||||
staffId: ticket.createdById,
|
||||
staffName: ticket.createdByName,
|
||||
@@ -567,7 +569,7 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
.read<TicketFormCubit>()
|
||||
.updateCreator(staffId: staff.id!, staffName: staff.name),
|
||||
),
|
||||
const Divider(height: 32),
|
||||
const Divider(height: 32), */
|
||||
SharedCustomerSection(
|
||||
customer: ticket.customer,
|
||||
onCustomerSelected: (customer) =>
|
||||
|
||||
@@ -160,7 +160,7 @@ class _TicketListScreenState extends State<TicketListScreen> {
|
||||
context.pushNamed(
|
||||
Routes.ticketForm,
|
||||
pathParameters: {'id': 'new'},
|
||||
extra: createdBy,
|
||||
extra: (createdBy: createdBy, ticket: null),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user