ticket refinements
This commit is contained in:
@@ -348,6 +348,32 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
trackingCubit.loadTrackings(ticketId, TrackingParentType.ticket);
|
||||
}
|
||||
|
||||
void _deleteTicket(TicketModel ticket, {Color color = Colors.red}) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Conferma Cancellazione'),
|
||||
content: Text(
|
||||
'Sei sicuro di voler cancellare il ticket "${ticket.referenceId}"? Questa azione è irreversibile.',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Annulla'),
|
||||
),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(backgroundColor: color),
|
||||
onPressed: () {
|
||||
context.read<TicketFormCubit>().deleteTicket();
|
||||
Navigator.of(context).pop(); // Chiude il dialog
|
||||
},
|
||||
child: const Text('Cancella Ticket'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
@@ -359,6 +385,10 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
_syncTextControllers(state.ticket);
|
||||
}
|
||||
|
||||
if (state.status == TicketFormStatus.deleted) {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
if (state.status == TicketFormStatus.success) {
|
||||
context.read<TicketListCubit>().loadTickets(refresh: true);
|
||||
_showSuccessActions(
|
||||
@@ -388,66 +418,61 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
: 'Modifica Ticket - Operatore: ${state.ticket.createdByName}',
|
||||
),
|
||||
actions: [
|
||||
BlocBuilder<TicketFormCubit, TicketFormState>(
|
||||
builder: (context, state) {
|
||||
final ticket = state.ticket;
|
||||
|
||||
// Se il ticket non è ancora salvato, niente azioni rapide
|
||||
if (ticket.id == null || ticket.id!.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
// CONDIZIONE A: Da iniziare
|
||||
if (ticket.ticketStatus == TicketStatus.open ||
|
||||
ticket.ticketStatus == TicketStatus.waitingForParts) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16.0,
|
||||
vertical: 8.0,
|
||||
),
|
||||
child: FilledButton.icon(
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor:
|
||||
Colors.amber.shade700, // Colore Action
|
||||
),
|
||||
onPressed: () async {
|
||||
StaffMemberModel? takenBy = await getStaffMember(
|
||||
context,
|
||||
);
|
||||
if (takenBy == null || !context.mounted) return;
|
||||
context.read<TicketFormCubit>().takeInCharge(
|
||||
staffId: takenBy.id!,
|
||||
staffName: takenBy.name,
|
||||
);
|
||||
_navigateToWorkspace(ticket.id!);
|
||||
},
|
||||
icon: const Icon(Icons.play_arrow, color: Colors.white),
|
||||
label: const Text(
|
||||
'Prendi in Carico',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
// CONDIZIONE B: Già in lavorazione
|
||||
else if (ticket.ticketStatus == TicketStatus.inProgress) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16.0,
|
||||
vertical: 8.0,
|
||||
),
|
||||
child: FilledButton.icon(
|
||||
onPressed: () => _navigateToWorkspace(ticket.id!),
|
||||
icon: const Icon(Icons.handyman),
|
||||
label: const Text('Vai a Lavorazione'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Se è chiuso o in altri stati strani, nascondiamo il bottone
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
if (ticket.id != null) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16.0,
|
||||
vertical: 8.0,
|
||||
),
|
||||
child: FilledButton.icon(
|
||||
onPressed: () => _deleteTicket(ticket, color: Colors.red),
|
||||
icon: const Icon(Icons.delete),
|
||||
label: const Text('Cancella Ticket'),
|
||||
),
|
||||
),
|
||||
],
|
||||
if (ticket.ticketStatus == TicketStatus.open ||
|
||||
ticket.ticketStatus == TicketStatus.waitingForParts) ...[
|
||||
// CONDIZIONE A: Da iniziare
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16.0,
|
||||
vertical: 8.0,
|
||||
),
|
||||
child: FilledButton.icon(
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: Colors.amber.shade700, // Colore Action
|
||||
),
|
||||
onPressed: () async {
|
||||
StaffMemberModel? takenBy = await getStaffMember(context);
|
||||
if (takenBy == null || !context.mounted) return;
|
||||
context.read<TicketFormCubit>().takeInCharge(
|
||||
staffId: takenBy.id!,
|
||||
staffName: takenBy.name,
|
||||
);
|
||||
_navigateToWorkspace(ticket.id!);
|
||||
},
|
||||
icon: const Icon(Icons.play_arrow, color: Colors.white),
|
||||
label: const Text(
|
||||
'Prendi in Carico',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
if (ticket.ticketStatus == TicketStatus.inProgress) ...[
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16.0,
|
||||
vertical: 8.0,
|
||||
),
|
||||
child: FilledButton.icon(
|
||||
onPressed: () => _navigateToWorkspace(ticket.id!),
|
||||
icon: const Icon(Icons.handyman),
|
||||
label: const Text('Vai a Lavorazione'),
|
||||
),
|
||||
),
|
||||
],
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 16.0),
|
||||
child: Chip(
|
||||
|
||||
Reference in New Issue
Block a user