From 9793ba8348b6e531f4855bb4aa8b05d1ee2342bd Mon Sep 17 00:00:00 2001 From: mark-cachy Date: Thu, 7 May 2026 19:29:39 +0200 Subject: [PATCH] a --- lib/core/routes/app_router.dart | 59 ++++--------------- .../blocs/operation_form_cubit.dart | 0 .../blocs/operation_form_state.dart | 39 ++++++++++++ 3 files changed, 49 insertions(+), 49 deletions(-) create mode 100644 lib/features/operations/blocs/operation_form_cubit.dart create mode 100644 lib/features/operations/blocs/operation_form_state.dart diff --git a/lib/core/routes/app_router.dart b/lib/core/routes/app_router.dart index 85c3502..f57a553 100644 --- a/lib/core/routes/app_router.dart +++ b/lib/core/routes/app_router.dart @@ -194,6 +194,8 @@ class AppRouter { GetIt.I.get().state.currentStore!.id!, ); context.read().loadCustomers(); + context.read().loadModels(); + context.read().loadBrands(); return MultiBlocProvider( providers: [ @@ -230,28 +232,15 @@ class AppRouter { ); }, ), - /* GoRoute( - path: '/customer/:id/upload', - builder: (context, state) { - final customerId = state.pathParameters['id']!; - final customerName = state.uri.queryParameters['name'] ?? 'Cliente'; - return BlocProvider( - create: (context) => AttachmentsBloc( - parentType: AttachmentParentType.customer, - parentId: customerId, - ), - child: SharedMobileUploadScreen( - title: 'Aggiungi allegati al cliente $customerName', - ), - ); - }, - ), */ + GoRoute( - path: '/operation-form', + path: '/operations/form/:id', name: 'operation-form', builder: (context, state) { - final existingOperation = state.extra as OperationModel?; - final operationId = state.uri.queryParameters['operationId']; + final String pathId = state.pathParameters['id'] ?? 'new'; + final OperationModel? operationFromExtra = + state.extra as OperationModel?; + final String? realOperationId = pathId == 'new' ? null : pathId; final currentStoreId = GetIt.I .get() .state @@ -267,7 +256,7 @@ class AppRouter { return BlocProvider( create: (context) => AttachmentsBloc( - parentId: operationId ?? existingOperation?.id, + parentId: realOperationId, parentType: AttachmentParentType.operation, ), child: OperationFormScreen( @@ -277,35 +266,7 @@ class AppRouter { ); }, ), - /* GoRoute( - path: '/operation/:id/upload', - builder: (context, state) { - final operationId = state.pathParameters['id']!; - final operationName = - state.uri.queryParameters['name'] ?? 'Pratica'; - final currentStoreId = GetIt.I - .get() - .state - .currentStore! - .id!; - context.read().loadCustomers(); - context.read().loadActiveProvidersForStore( - currentStoreId, - ); - context.read().loadModels(); - context.read().loadBrands(); - context.read().loadStaffForStore(currentStoreId); - return BlocProvider( - create: (context) => AttachmentsBloc( - parentId: operationId, - parentType: AttachmentParentType.operation, - ), - child: SharedMobileUploadScreen( - title: 'Aggiungi allegati alla pratica $operationName', - ), - ); - }, - ), */ + GoRoute( path: '/upload/:type/:id', builder: (context, state) { diff --git a/lib/features/operations/blocs/operation_form_cubit.dart b/lib/features/operations/blocs/operation_form_cubit.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/features/operations/blocs/operation_form_state.dart b/lib/features/operations/blocs/operation_form_state.dart new file mode 100644 index 0000000..f15709e --- /dev/null +++ b/lib/features/operations/blocs/operation_form_state.dart @@ -0,0 +1,39 @@ +import 'package:equatable/equatable.dart'; +import 'package:flux/features/operations/models/operation_model.dart'; + +enum OperationFormStatus { + initial, + ready, + loading, + saving, + success, + successAndAddAnother, + failure, +} + +class OperationFormState extends Equatable { + final OperationModel operation; + final OperationFormStatus status; + final String? errorMessage; + + const OperationFormState({ + required this.operation, + this.status = OperationFormStatus.initial, + this.errorMessage, + }); + + @override + List get props => [operation, status, errorMessage]; + + OperationFormState copyWith({ + OperationModel? operation, + OperationFormStatus? status, + String? errorMessage, + }) { + return OperationFormState( + operation: operation ?? this.operation, + status: status ?? this.status, + errorMessage: errorMessage, + ); + } +}