ticket form funzionante! devo ancora provare a salvare però
This commit is contained in:
@@ -196,7 +196,7 @@ class HomeScreen extends StatelessWidget {
|
||||
color: Colors.redAccent,
|
||||
onTap: () {
|
||||
// Andiamo alla lista! (Da lì poi aggiungeremo il tasto "+" per il form)
|
||||
context.push('/tickets');
|
||||
context.push('/tickets/form/new');
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
|
||||
@@ -4,10 +4,10 @@ import 'package:flux/core/blocs/session/session_cubit.dart';
|
||||
import 'package:flux/features/attachments/blocs/attachments_bloc.dart';
|
||||
import 'package:flux/features/operations/blocs/operations_cubit.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/shared_customer_section.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/customer_section.dart';
|
||||
import 'package:flux/features/operations/ui/widgets/details_section.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/shared_attachments_section.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/shared_staff_section.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/attachments_section.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/staff_section.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
|
||||
class OperationFormScreen extends StatefulWidget {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/shared_model_section.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/model_section.dart';
|
||||
import 'package:flux/features/master_data/providers/blocs/provider_cubit.dart';
|
||||
import 'package:flux/features/operations/blocs/operations_cubit.dart';
|
||||
import 'package:flux/features/operations/models/operation_model.dart';
|
||||
|
||||
@@ -17,12 +17,36 @@ class TicketFormCubit extends Cubit<TicketFormState> {
|
||||
);
|
||||
|
||||
/// 1. INIZIALIZZAZIONE (Se stiamo modificando un ticket esistente)
|
||||
void initForm(TicketModel? existingTicket) {
|
||||
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!
|
||||
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
|
||||
try {
|
||||
final fetchedTicket = await _repository.getTicketById(
|
||||
id,
|
||||
); // Lo scarichiamo!
|
||||
emit(
|
||||
state.copyWith(ticket: fetchedTicket, status: TicketFormStatus.ready),
|
||||
);
|
||||
} catch (e) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: TicketFormStatus.failure,
|
||||
errorMessage: 'Ticket non trovato',
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// SCENARIO 3 (Nuovo Ticket):
|
||||
// È un nuovo ticket! Inseriamo i default base (Azienda, Negozio, Creatore)
|
||||
final currentUser = _sessionCubit.state.currentStaffMember;
|
||||
final currentStore = _sessionCubit.state.currentStore;
|
||||
|
||||
@@ -170,7 +170,7 @@ class TicketRepository {
|
||||
|
||||
/// Recupera un ticket specifico CON TUTTE LE RELAZIONI espanse (Cliente e Modelli)
|
||||
/// Questa è la vera magia di Supabase!
|
||||
Future<TicketModel> getTicketWithDetails(String ticketId) async {
|
||||
Future<TicketModel> getTicketById(String ticketId) async {
|
||||
try {
|
||||
// Usiamo i nomi esatti delle Foreign Key che hai definito nell'SQL!
|
||||
final response = await _supabase
|
||||
|
||||
@@ -3,15 +3,16 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flux/features/tickets/blocs/ticket_form_cubit.dart';
|
||||
import 'package:flux/features/tickets/blocs/ticket_form_state.dart';
|
||||
import 'package:flux/features/tickets/models/ticket_model.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/shared_customer_section.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/shared_model_section.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/shared_staff_section.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/customer_section.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/model_section.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/staff_section.dart';
|
||||
import 'package:flux/features/tickets/models/ticket_status_extension.dart'; // Il tuo widget agnostico dello staff
|
||||
|
||||
class TicketFormScreen extends StatefulWidget {
|
||||
final TicketModel? existingTicket;
|
||||
final String? ticketId;
|
||||
|
||||
const TicketFormScreen({super.key, this.existingTicket});
|
||||
const TicketFormScreen({super.key, this.existingTicket, this.ticketId});
|
||||
|
||||
@override
|
||||
State<TicketFormScreen> createState() => _TicketFormScreenState();
|
||||
@@ -36,7 +37,10 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Inizializziamo il Cubit
|
||||
context.read<TicketFormCubit>().initForm(widget.existingTicket);
|
||||
context.read<TicketFormCubit>().initForm(
|
||||
id: widget.ticketId,
|
||||
existingTicket: widget.existingTicket,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -150,7 +154,7 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
padding: const EdgeInsets.only(right: 16.0),
|
||||
child: Chip(
|
||||
label: Text(
|
||||
ticket.ticketStatus!.name.toUpperCase(),
|
||||
ticket.ticketStatus.name.toUpperCase(),
|
||||
style: const TextStyle(color: Colors.white, fontSize: 10),
|
||||
),
|
||||
backgroundColor: ticket.ticketStatus.color,
|
||||
@@ -239,7 +243,7 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<TicketType>(
|
||||
value: ticket.ticketType,
|
||||
initialValue: ticket.ticketType,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Tipo Lavorazione',
|
||||
),
|
||||
@@ -261,7 +265,7 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: DropdownButtonFormField<TicketStatus>(
|
||||
value: ticket.ticketStatus,
|
||||
initialValue: ticket.ticketStatus,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Stato Attuale',
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user