feat: Allow pre-filling order creation forms with reorder data and update reorder navigation to directly open relevant order pages.

This commit is contained in:
Achintha Isuru
2026-02-22 01:37:49 -05:00
parent 036920377e
commit 3aab5bfc26
11 changed files with 272 additions and 119 deletions

View File

@@ -137,36 +137,36 @@ extension ClientNavigator on IModularNavigator {
/// Pushes the order creation flow entry page. /// Pushes the order creation flow entry page.
/// ///
/// This is the starting point for all order creation flows. /// This is the starting point for all order creation flows.
void toCreateOrder() { void toCreateOrder({Object? arguments}) {
pushNamed(ClientPaths.createOrder); pushNamed(ClientPaths.createOrder, arguments: arguments);
} }
/// Pushes the rapid order creation flow. /// Pushes the rapid order creation flow.
/// ///
/// Quick shift creation with simplified inputs for urgent needs. /// Quick shift creation with simplified inputs for urgent needs.
void toCreateOrderRapid() { void toCreateOrderRapid({Object? arguments}) {
pushNamed(ClientPaths.createOrderRapid); pushNamed(ClientPaths.createOrderRapid, arguments: arguments);
} }
/// Pushes the one-time order creation flow. /// Pushes the one-time order creation flow.
/// ///
/// Create a shift that occurs once at a specific date and time. /// Create a shift that occurs once at a specific date and time.
void toCreateOrderOneTime() { void toCreateOrderOneTime({Object? arguments}) {
pushNamed(ClientPaths.createOrderOneTime); pushNamed(ClientPaths.createOrderOneTime, arguments: arguments);
} }
/// Pushes the recurring order creation flow. /// Pushes the recurring order creation flow.
/// ///
/// Create shifts that repeat on a defined schedule (daily, weekly, etc.). /// Create shifts that repeat on a defined schedule (daily, weekly, etc.).
void toCreateOrderRecurring() { void toCreateOrderRecurring({Object? arguments}) {
pushNamed(ClientPaths.createOrderRecurring); pushNamed(ClientPaths.createOrderRecurring, arguments: arguments);
} }
/// Pushes the permanent order creation flow. /// Pushes the permanent order creation flow.
/// ///
/// Create a long-term or permanent staffing position. /// Create a long-term or permanent staffing position.
void toCreateOrderPermanent() { void toCreateOrderPermanent({Object? arguments}) {
pushNamed(ClientPaths.createOrderPermanent); pushNamed(ClientPaths.createOrderPermanent, arguments: arguments);
} }
// ========================================================================== // ==========================================================================

View File

@@ -5,8 +5,6 @@ import 'package:flutter_modular/flutter_modular.dart';
import 'package:krow_core/core.dart'; import 'package:krow_core/core.dart';
import 'package:krow_domain/krow_domain.dart'; import 'package:krow_domain/krow_domain.dart';
import 'client_home_sheets.dart';
/// A widget that allows clients to reorder recent shifts. /// A widget that allows clients to reorder recent shifts.
class ReorderWidget extends StatelessWidget { class ReorderWidget extends StatelessWidget {
/// Creates a [ReorderWidget]. /// Creates a [ReorderWidget].
@@ -173,29 +171,28 @@ class ReorderWidget extends StatelessWidget {
} }
void _handleReorderPressed(BuildContext context, Map<String, dynamic> data) { void _handleReorderPressed(BuildContext context, Map<String, dynamic> data) {
ClientHomeSheets.showOrderFormSheet( // Override start date with today's date as requested
context, final Map<String, dynamic> populatedData = Map<String, dynamic>.from(data)
data, ..['startDate'] = DateTime.now();
onSubmit: (Map<String, dynamic> submittedData) {
final String? typeStr = submittedData['type']?.toString(); final String? typeStr = populatedData['type']?.toString();
if (typeStr == null || typeStr.isEmpty) { if (typeStr == null || typeStr.isEmpty) {
return; return;
} }
final OrderType orderType = OrderType.fromString(typeStr);
switch (orderType) { final OrderType orderType = OrderType.fromString(typeStr);
case OrderType.recurring: switch (orderType) {
Modular.to.toCreateOrderRecurring(); case OrderType.recurring:
break; Modular.to.toCreateOrderRecurring(arguments: populatedData);
case OrderType.permanent: break;
Modular.to.toCreateOrderPermanent(); case OrderType.permanent:
break; Modular.to.toCreateOrderPermanent(arguments: populatedData);
case OrderType.oneTime: break;
default: case OrderType.oneTime:
Modular.to.toCreateOrderOneTime(); default:
break; Modular.to.toCreateOrderOneTime(arguments: populatedData);
} break;
}, }
);
} }
} }

View File

@@ -11,7 +11,9 @@ import 'one_time_order_state.dart';
/// BLoC for managing the multi-step one-time order creation form. /// BLoC for managing the multi-step one-time order creation form.
class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState> class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
with BlocErrorHandler<OneTimeOrderState>, SafeBloc<OneTimeOrderEvent, OneTimeOrderState> { with
BlocErrorHandler<OneTimeOrderState>,
SafeBloc<OneTimeOrderEvent, OneTimeOrderState> {
OneTimeOrderBloc(this._createOneTimeOrderUseCase, this._service) OneTimeOrderBloc(this._createOneTimeOrderUseCase, this._service)
: super(OneTimeOrderState.initial()) { : super(OneTimeOrderState.initial()) {
on<OneTimeOrderVendorsLoaded>(_onVendorsLoaded); on<OneTimeOrderVendorsLoaded>(_onVendorsLoaded);
@@ -24,6 +26,7 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
on<OneTimeOrderPositionRemoved>(_onPositionRemoved); on<OneTimeOrderPositionRemoved>(_onPositionRemoved);
on<OneTimeOrderPositionUpdated>(_onPositionUpdated); on<OneTimeOrderPositionUpdated>(_onPositionUpdated);
on<OneTimeOrderSubmitted>(_onSubmitted); on<OneTimeOrderSubmitted>(_onSubmitted);
on<OneTimeOrderInitialized>(_onInitialized);
_loadVendors(); _loadVendors();
_loadHubs(); _loadHubs();
@@ -34,8 +37,10 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
Future<void> _loadVendors() async { Future<void> _loadVendors() async {
final List<Vendor>? vendors = await handleErrorWithResult( final List<Vendor>? vendors = await handleErrorWithResult(
action: () async { action: () async {
final QueryResult<dc.ListVendorsData, void> result = final QueryResult<dc.ListVendorsData, void> result = await _service
await _service.connector.listVendors().execute(); .connector
.listVendors()
.execute();
return result.data.vendors return result.data.vendors
.map( .map(
(dc.ListVendorsVendors vendor) => Vendor( (dc.ListVendorsVendors vendor) => Vendor(
@@ -54,11 +59,19 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
} }
} }
Future<void> _loadRolesForVendor(String vendorId, Emitter<OneTimeOrderState> emit) async { Future<void> _loadRolesForVendor(
String vendorId,
Emitter<OneTimeOrderState> emit,
) async {
final List<OneTimeOrderRoleOption>? roles = await handleErrorWithResult( final List<OneTimeOrderRoleOption>? roles = await handleErrorWithResult(
action: () async { action: () async {
final QueryResult<dc.ListRolesByVendorIdData, dc.ListRolesByVendorIdVariables> final QueryResult<
result = await _service.connector.listRolesByVendorId(vendorId: vendorId).execute(); dc.ListRolesByVendorIdData,
dc.ListRolesByVendorIdVariables
>
result = await _service.connector
.listRolesByVendorId(vendorId: vendorId)
.execute();
return result.data.roles return result.data.roles
.map( .map(
(dc.ListRolesByVendorIdRoles role) => OneTimeOrderRoleOption( (dc.ListRolesByVendorIdRoles role) => OneTimeOrderRoleOption(
@@ -69,7 +82,8 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
) )
.toList(); .toList();
}, },
onError: (_) => emit(state.copyWith(roles: const <OneTimeOrderRoleOption>[])), onError: (_) =>
emit(state.copyWith(roles: const <OneTimeOrderRoleOption>[])),
); );
if (roles != null) { if (roles != null) {
@@ -81,7 +95,10 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
final List<OneTimeOrderHubOption>? hubs = await handleErrorWithResult( final List<OneTimeOrderHubOption>? hubs = await handleErrorWithResult(
action: () async { action: () async {
final String businessId = await _service.getBusinessId(); final String businessId = await _service.getBusinessId();
final QueryResult<dc.ListTeamHubsByOwnerIdData, dc.ListTeamHubsByOwnerIdVariables> final QueryResult<
dc.ListTeamHubsByOwnerIdData,
dc.ListTeamHubsByOwnerIdVariables
>
result = await _service.connector result = await _service.connector
.listTeamHubsByOwnerId(ownerId: businessId) .listTeamHubsByOwnerId(ownerId: businessId)
.execute(); .execute();
@@ -103,7 +120,8 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
) )
.toList(); .toList();
}, },
onError: (_) => add(const OneTimeOrderHubsLoaded(<OneTimeOrderHubOption>[])), onError: (_) =>
add(const OneTimeOrderHubsLoaded(<OneTimeOrderHubOption>[])),
); );
if (hubs != null) { if (hubs != null) {
@@ -115,13 +133,11 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
OneTimeOrderVendorsLoaded event, OneTimeOrderVendorsLoaded event,
Emitter<OneTimeOrderState> emit, Emitter<OneTimeOrderState> emit,
) async { ) async {
final Vendor? selectedVendor = final Vendor? selectedVendor = event.vendors.isNotEmpty
event.vendors.isNotEmpty ? event.vendors.first : null; ? event.vendors.first
: null;
emit( emit(
state.copyWith( state.copyWith(vendors: event.vendors, selectedVendor: selectedVendor),
vendors: event.vendors,
selectedVendor: selectedVendor,
),
); );
if (selectedVendor != null) { if (selectedVendor != null) {
await _loadRolesForVendor(selectedVendor.id, emit); await _loadRolesForVendor(selectedVendor.id, emit);
@@ -140,8 +156,9 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
OneTimeOrderHubsLoaded event, OneTimeOrderHubsLoaded event,
Emitter<OneTimeOrderState> emit, Emitter<OneTimeOrderState> emit,
) { ) {
final OneTimeOrderHubOption? selectedHub = final OneTimeOrderHubOption? selectedHub = event.hubs.isNotEmpty
event.hubs.isNotEmpty ? event.hubs.first : null; ? event.hubs.first
: null;
emit( emit(
state.copyWith( state.copyWith(
hubs: event.hubs, hubs: event.hubs,
@@ -155,12 +172,7 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
OneTimeOrderHubChanged event, OneTimeOrderHubChanged event,
Emitter<OneTimeOrderState> emit, Emitter<OneTimeOrderState> emit,
) { ) {
emit( emit(state.copyWith(selectedHub: event.hub, location: event.hub.name));
state.copyWith(
selectedHub: event.hub,
location: event.hub.name,
),
);
} }
void _onEventNameChanged( void _onEventNameChanged(
@@ -261,4 +273,29 @@ class OneTimeOrderBloc extends Bloc<OneTimeOrderEvent, OneTimeOrderState>
), ),
); );
} }
void _onInitialized(
OneTimeOrderInitialized event,
Emitter<OneTimeOrderState> emit,
) {
final Map<String, dynamic> data = event.data;
final String title = data['title']?.toString() ?? '';
final int workers = (data['workers'] as int?) ?? 1;
final DateTime? startDate = data['startDate'] as DateTime?;
emit(
state.copyWith(
eventName: title,
date: startDate ?? DateTime.now(),
positions: <OneTimeOrderPosition>[
OneTimeOrderPosition(
role: data['roleName']?.toString() ?? '',
count: workers,
startTime: data['startTime']?.toString() ?? '09:00',
endTime: data['endTime']?.toString() ?? '17:00',
),
],
),
);
}
} }

View File

@@ -81,3 +81,11 @@ class OneTimeOrderPositionUpdated extends OneTimeOrderEvent {
class OneTimeOrderSubmitted extends OneTimeOrderEvent { class OneTimeOrderSubmitted extends OneTimeOrderEvent {
const OneTimeOrderSubmitted(); const OneTimeOrderSubmitted();
} }
class OneTimeOrderInitialized extends OneTimeOrderEvent {
const OneTimeOrderInitialized(this.data);
final Map<String, dynamic> data;
@override
List<Object?> get props => <Object?>[data];
}

View File

@@ -10,9 +10,11 @@ import 'permanent_order_state.dart';
/// BLoC for managing the permanent order creation form. /// BLoC for managing the permanent order creation form.
class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState> class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
with BlocErrorHandler<PermanentOrderState>, SafeBloc<PermanentOrderEvent, PermanentOrderState> { with
BlocErrorHandler<PermanentOrderState>,
SafeBloc<PermanentOrderEvent, PermanentOrderState> {
PermanentOrderBloc(this._createPermanentOrderUseCase, this._service) PermanentOrderBloc(this._createPermanentOrderUseCase, this._service)
: super(PermanentOrderState.initial()) { : super(PermanentOrderState.initial()) {
on<PermanentOrderVendorsLoaded>(_onVendorsLoaded); on<PermanentOrderVendorsLoaded>(_onVendorsLoaded);
on<PermanentOrderVendorChanged>(_onVendorChanged); on<PermanentOrderVendorChanged>(_onVendorChanged);
on<PermanentOrderHubsLoaded>(_onHubsLoaded); on<PermanentOrderHubsLoaded>(_onHubsLoaded);
@@ -24,6 +26,7 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
on<PermanentOrderPositionRemoved>(_onPositionRemoved); on<PermanentOrderPositionRemoved>(_onPositionRemoved);
on<PermanentOrderPositionUpdated>(_onPositionUpdated); on<PermanentOrderPositionUpdated>(_onPositionUpdated);
on<PermanentOrderSubmitted>(_onSubmitted); on<PermanentOrderSubmitted>(_onSubmitted);
on<PermanentOrderInitialized>(_onInitialized);
_loadVendors(); _loadVendors();
_loadHubs(); _loadHubs();
@@ -45,8 +48,10 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
Future<void> _loadVendors() async { Future<void> _loadVendors() async {
final List<domain.Vendor>? vendors = await handleErrorWithResult( final List<domain.Vendor>? vendors = await handleErrorWithResult(
action: () async { action: () async {
final QueryResult<dc.ListVendorsData, void> result = final QueryResult<dc.ListVendorsData, void> result = await _service
await _service.connector.listVendors().execute(); .connector
.listVendors()
.execute();
return result.data.vendors return result.data.vendors
.map( .map(
(dc.ListVendorsVendors vendor) => domain.Vendor( (dc.ListVendorsVendors vendor) => domain.Vendor(
@@ -71,10 +76,13 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
) async { ) async {
final List<PermanentOrderRoleOption>? roles = await handleErrorWithResult( final List<PermanentOrderRoleOption>? roles = await handleErrorWithResult(
action: () async { action: () async {
final QueryResult<dc.ListRolesByVendorIdData, dc.ListRolesByVendorIdVariables> final QueryResult<
result = await _service.connector dc.ListRolesByVendorIdData,
.listRolesByVendorId(vendorId: vendorId) dc.ListRolesByVendorIdVariables
.execute(); >
result = await _service.connector
.listRolesByVendorId(vendorId: vendorId)
.execute();
return result.data.roles return result.data.roles
.map( .map(
(dc.ListRolesByVendorIdRoles role) => PermanentOrderRoleOption( (dc.ListRolesByVendorIdRoles role) => PermanentOrderRoleOption(
@@ -85,7 +93,8 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
) )
.toList(); .toList();
}, },
onError: (_) => emit(state.copyWith(roles: const <PermanentOrderRoleOption>[])), onError: (_) =>
emit(state.copyWith(roles: const <PermanentOrderRoleOption>[])),
); );
if (roles != null) { if (roles != null) {
@@ -97,10 +106,13 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
final List<PermanentOrderHubOption>? hubs = await handleErrorWithResult( final List<PermanentOrderHubOption>? hubs = await handleErrorWithResult(
action: () async { action: () async {
final String businessId = await _service.getBusinessId(); final String businessId = await _service.getBusinessId();
final QueryResult<dc.ListTeamHubsByOwnerIdData, dc.ListTeamHubsByOwnerIdVariables> final QueryResult<
result = await _service.connector dc.ListTeamHubsByOwnerIdData,
.listTeamHubsByOwnerId(ownerId: businessId) dc.ListTeamHubsByOwnerIdVariables
.execute(); >
result = await _service.connector
.listTeamHubsByOwnerId(ownerId: businessId)
.execute();
return result.data.teamHubs return result.data.teamHubs
.map( .map(
(dc.ListTeamHubsByOwnerIdTeamHubs hub) => PermanentOrderHubOption( (dc.ListTeamHubsByOwnerIdTeamHubs hub) => PermanentOrderHubOption(
@@ -119,7 +131,8 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
) )
.toList(); .toList();
}, },
onError: (_) => add(const PermanentOrderHubsLoaded(<PermanentOrderHubOption>[])), onError: (_) =>
add(const PermanentOrderHubsLoaded(<PermanentOrderHubOption>[])),
); );
if (hubs != null) { if (hubs != null) {
@@ -131,13 +144,11 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
PermanentOrderVendorsLoaded event, PermanentOrderVendorsLoaded event,
Emitter<PermanentOrderState> emit, Emitter<PermanentOrderState> emit,
) async { ) async {
final domain.Vendor? selectedVendor = final domain.Vendor? selectedVendor = event.vendors.isNotEmpty
event.vendors.isNotEmpty ? event.vendors.first : null; ? event.vendors.first
: null;
emit( emit(
state.copyWith( state.copyWith(vendors: event.vendors, selectedVendor: selectedVendor),
vendors: event.vendors,
selectedVendor: selectedVendor,
),
); );
if (selectedVendor != null) { if (selectedVendor != null) {
await _loadRolesForVendor(selectedVendor.id, emit); await _loadRolesForVendor(selectedVendor.id, emit);
@@ -156,8 +167,9 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
PermanentOrderHubsLoaded event, PermanentOrderHubsLoaded event,
Emitter<PermanentOrderState> emit, Emitter<PermanentOrderState> emit,
) { ) {
final PermanentOrderHubOption? selectedHub = final PermanentOrderHubOption? selectedHub = event.hubs.isNotEmpty
event.hubs.isNotEmpty ? event.hubs.first : null; ? event.hubs.first
: null;
emit( emit(
state.copyWith( state.copyWith(
hubs: event.hubs, hubs: event.hubs,
@@ -171,12 +183,7 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
PermanentOrderHubChanged event, PermanentOrderHubChanged event,
Emitter<PermanentOrderState> emit, Emitter<PermanentOrderState> emit,
) { ) {
emit( emit(state.copyWith(selectedHub: event.hub, location: event.hub.name));
state.copyWith(
selectedHub: event.hub,
location: event.hub.name,
),
);
} }
void _onEventNameChanged( void _onEventNameChanged(
@@ -226,7 +233,12 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
} else { } else {
days.add(label); days.add(label);
} }
emit(state.copyWith(permanentDays: _sortDays(days), autoSelectedDayIndex: autoIndex)); emit(
state.copyWith(
permanentDays: _sortDays(days),
autoSelectedDayIndex: autoIndex,
),
);
} }
void _onPositionAdded( void _onPositionAdded(
@@ -325,6 +337,31 @@ class PermanentOrderBloc extends Bloc<PermanentOrderEvent, PermanentOrderState>
); );
} }
void _onInitialized(
PermanentOrderInitialized event,
Emitter<PermanentOrderState> emit,
) {
final Map<String, dynamic> data = event.data;
final String title = data['title']?.toString() ?? '';
final int workers = (data['workers'] as int?) ?? 1;
final DateTime? startDate = data['startDate'] as DateTime?;
emit(
state.copyWith(
eventName: title,
startDate: startDate ?? DateTime.now(),
positions: <PermanentOrderPosition>[
PermanentOrderPosition(
role: data['roleName']?.toString() ?? '',
count: workers,
startTime: data['startTime']?.toString() ?? '09:00',
endTime: data['endTime']?.toString() ?? '17:00',
),
],
),
);
}
static List<String> _sortDays(List<String> days) { static List<String> _sortDays(List<String> days) {
days.sort( days.sort(
(String a, String b) => (String a, String b) =>

View File

@@ -98,3 +98,11 @@ class PermanentOrderPositionUpdated extends PermanentOrderEvent {
class PermanentOrderSubmitted extends PermanentOrderEvent { class PermanentOrderSubmitted extends PermanentOrderEvent {
const PermanentOrderSubmitted(); const PermanentOrderSubmitted();
} }
class PermanentOrderInitialized extends PermanentOrderEvent {
const PermanentOrderInitialized(this.data);
final Map<String, dynamic> data;
@override
List<Object?> get props => <Object?>[data];
}

View File

@@ -10,9 +10,11 @@ import 'recurring_order_state.dart';
/// BLoC for managing the recurring order creation form. /// BLoC for managing the recurring order creation form.
class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState> class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
with BlocErrorHandler<RecurringOrderState>, SafeBloc<RecurringOrderEvent, RecurringOrderState> { with
BlocErrorHandler<RecurringOrderState>,
SafeBloc<RecurringOrderEvent, RecurringOrderState> {
RecurringOrderBloc(this._createRecurringOrderUseCase, this._service) RecurringOrderBloc(this._createRecurringOrderUseCase, this._service)
: super(RecurringOrderState.initial()) { : super(RecurringOrderState.initial()) {
on<RecurringOrderVendorsLoaded>(_onVendorsLoaded); on<RecurringOrderVendorsLoaded>(_onVendorsLoaded);
on<RecurringOrderVendorChanged>(_onVendorChanged); on<RecurringOrderVendorChanged>(_onVendorChanged);
on<RecurringOrderHubsLoaded>(_onHubsLoaded); on<RecurringOrderHubsLoaded>(_onHubsLoaded);
@@ -25,6 +27,7 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
on<RecurringOrderPositionRemoved>(_onPositionRemoved); on<RecurringOrderPositionRemoved>(_onPositionRemoved);
on<RecurringOrderPositionUpdated>(_onPositionUpdated); on<RecurringOrderPositionUpdated>(_onPositionUpdated);
on<RecurringOrderSubmitted>(_onSubmitted); on<RecurringOrderSubmitted>(_onSubmitted);
on<RecurringOrderInitialized>(_onInitialized);
_loadVendors(); _loadVendors();
_loadHubs(); _loadHubs();
@@ -46,8 +49,10 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
Future<void> _loadVendors() async { Future<void> _loadVendors() async {
final List<domain.Vendor>? vendors = await handleErrorWithResult( final List<domain.Vendor>? vendors = await handleErrorWithResult(
action: () async { action: () async {
final QueryResult<dc.ListVendorsData, void> result = final QueryResult<dc.ListVendorsData, void> result = await _service
await _service.connector.listVendors().execute(); .connector
.listVendors()
.execute();
return result.data.vendors return result.data.vendors
.map( .map(
(dc.ListVendorsVendors vendor) => domain.Vendor( (dc.ListVendorsVendors vendor) => domain.Vendor(
@@ -72,10 +77,13 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
) async { ) async {
final List<RecurringOrderRoleOption>? roles = await handleErrorWithResult( final List<RecurringOrderRoleOption>? roles = await handleErrorWithResult(
action: () async { action: () async {
final QueryResult<dc.ListRolesByVendorIdData, dc.ListRolesByVendorIdVariables> final QueryResult<
result = await _service.connector dc.ListRolesByVendorIdData,
.listRolesByVendorId(vendorId: vendorId) dc.ListRolesByVendorIdVariables
.execute(); >
result = await _service.connector
.listRolesByVendorId(vendorId: vendorId)
.execute();
return result.data.roles return result.data.roles
.map( .map(
(dc.ListRolesByVendorIdRoles role) => RecurringOrderRoleOption( (dc.ListRolesByVendorIdRoles role) => RecurringOrderRoleOption(
@@ -86,7 +94,8 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
) )
.toList(); .toList();
}, },
onError: (_) => emit(state.copyWith(roles: const <RecurringOrderRoleOption>[])), onError: (_) =>
emit(state.copyWith(roles: const <RecurringOrderRoleOption>[])),
); );
if (roles != null) { if (roles != null) {
@@ -98,10 +107,13 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
final List<RecurringOrderHubOption>? hubs = await handleErrorWithResult( final List<RecurringOrderHubOption>? hubs = await handleErrorWithResult(
action: () async { action: () async {
final String businessId = await _service.getBusinessId(); final String businessId = await _service.getBusinessId();
final QueryResult<dc.ListTeamHubsByOwnerIdData, dc.ListTeamHubsByOwnerIdVariables> final QueryResult<
result = await _service.connector dc.ListTeamHubsByOwnerIdData,
.listTeamHubsByOwnerId(ownerId: businessId) dc.ListTeamHubsByOwnerIdVariables
.execute(); >
result = await _service.connector
.listTeamHubsByOwnerId(ownerId: businessId)
.execute();
return result.data.teamHubs return result.data.teamHubs
.map( .map(
(dc.ListTeamHubsByOwnerIdTeamHubs hub) => RecurringOrderHubOption( (dc.ListTeamHubsByOwnerIdTeamHubs hub) => RecurringOrderHubOption(
@@ -120,7 +132,8 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
) )
.toList(); .toList();
}, },
onError: (_) => add(const RecurringOrderHubsLoaded(<RecurringOrderHubOption>[])), onError: (_) =>
add(const RecurringOrderHubsLoaded(<RecurringOrderHubOption>[])),
); );
if (hubs != null) { if (hubs != null) {
@@ -132,13 +145,11 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
RecurringOrderVendorsLoaded event, RecurringOrderVendorsLoaded event,
Emitter<RecurringOrderState> emit, Emitter<RecurringOrderState> emit,
) async { ) async {
final domain.Vendor? selectedVendor = final domain.Vendor? selectedVendor = event.vendors.isNotEmpty
event.vendors.isNotEmpty ? event.vendors.first : null; ? event.vendors.first
: null;
emit( emit(
state.copyWith( state.copyWith(vendors: event.vendors, selectedVendor: selectedVendor),
vendors: event.vendors,
selectedVendor: selectedVendor,
),
); );
if (selectedVendor != null) { if (selectedVendor != null) {
await _loadRolesForVendor(selectedVendor.id, emit); await _loadRolesForVendor(selectedVendor.id, emit);
@@ -157,8 +168,9 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
RecurringOrderHubsLoaded event, RecurringOrderHubsLoaded event,
Emitter<RecurringOrderState> emit, Emitter<RecurringOrderState> emit,
) { ) {
final RecurringOrderHubOption? selectedHub = final RecurringOrderHubOption? selectedHub = event.hubs.isNotEmpty
event.hubs.isNotEmpty ? event.hubs.first : null; ? event.hubs.first
: null;
emit( emit(
state.copyWith( state.copyWith(
hubs: event.hubs, hubs: event.hubs,
@@ -172,12 +184,7 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
RecurringOrderHubChanged event, RecurringOrderHubChanged event,
Emitter<RecurringOrderState> emit, Emitter<RecurringOrderState> emit,
) { ) {
emit( emit(state.copyWith(selectedHub: event.hub, location: event.hub.name));
state.copyWith(
selectedHub: event.hub,
location: event.hub.name,
),
);
} }
void _onEventNameChanged( void _onEventNameChanged(
@@ -243,7 +250,12 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
} else { } else {
days.add(label); days.add(label);
} }
emit(state.copyWith(recurringDays: _sortDays(days), autoSelectedDayIndex: autoIndex)); emit(
state.copyWith(
recurringDays: _sortDays(days),
autoSelectedDayIndex: autoIndex,
),
);
} }
void _onPositionAdded( void _onPositionAdded(
@@ -344,6 +356,31 @@ class RecurringOrderBloc extends Bloc<RecurringOrderEvent, RecurringOrderState>
); );
} }
void _onInitialized(
RecurringOrderInitialized event,
Emitter<RecurringOrderState> emit,
) {
final Map<String, dynamic> data = event.data;
final String title = data['title']?.toString() ?? '';
final int workers = (data['workers'] as int?) ?? 1;
final DateTime? startDate = data['startDate'] as DateTime?;
emit(
state.copyWith(
eventName: title,
startDate: startDate ?? DateTime.now(),
positions: <RecurringOrderPosition>[
RecurringOrderPosition(
role: data['roleName']?.toString() ?? '',
count: workers,
startTime: data['startTime']?.toString() ?? '09:00',
endTime: data['endTime']?.toString() ?? '17:00',
),
],
),
);
}
static List<String> _sortDays(List<String> days) { static List<String> _sortDays(List<String> days) {
days.sort( days.sort(
(String a, String b) => (String a, String b) =>

View File

@@ -107,3 +107,11 @@ class RecurringOrderPositionUpdated extends RecurringOrderEvent {
class RecurringOrderSubmitted extends RecurringOrderEvent { class RecurringOrderSubmitted extends RecurringOrderEvent {
const RecurringOrderSubmitted(); const RecurringOrderSubmitted();
} }
class RecurringOrderInitialized extends RecurringOrderEvent {
const RecurringOrderInitialized(this.data);
final Map<String, dynamic> data;
@override
List<Object?> get props => <Object?>[data];
}

View File

@@ -21,7 +21,14 @@ class OneTimeOrderPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider<OneTimeOrderBloc>( return BlocProvider<OneTimeOrderBloc>(
create: (BuildContext context) => Modular.get<OneTimeOrderBloc>(), create: (BuildContext context) {
final OneTimeOrderBloc bloc = Modular.get<OneTimeOrderBloc>();
final dynamic args = Modular.args.data;
if (args is Map<String, dynamic>) {
bloc.add(OneTimeOrderInitialized(args));
}
return bloc;
},
child: BlocBuilder<OneTimeOrderBloc, OneTimeOrderState>( child: BlocBuilder<OneTimeOrderBloc, OneTimeOrderState>(
builder: (BuildContext context, OneTimeOrderState state) { builder: (BuildContext context, OneTimeOrderState state) {
final OneTimeOrderBloc bloc = BlocProvider.of<OneTimeOrderBloc>( final OneTimeOrderBloc bloc = BlocProvider.of<OneTimeOrderBloc>(

View File

@@ -16,7 +16,14 @@ class PermanentOrderPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider<PermanentOrderBloc>( return BlocProvider<PermanentOrderBloc>(
create: (BuildContext context) => Modular.get<PermanentOrderBloc>(), create: (BuildContext context) {
final PermanentOrderBloc bloc = Modular.get<PermanentOrderBloc>();
final dynamic args = Modular.args.data;
if (args is Map<String, dynamic>) {
bloc.add(PermanentOrderInitialized(args));
}
return bloc;
},
child: BlocBuilder<PermanentOrderBloc, PermanentOrderState>( child: BlocBuilder<PermanentOrderBloc, PermanentOrderState>(
builder: (BuildContext context, PermanentOrderState state) { builder: (BuildContext context, PermanentOrderState state) {
final PermanentOrderBloc bloc = BlocProvider.of<PermanentOrderBloc>( final PermanentOrderBloc bloc = BlocProvider.of<PermanentOrderBloc>(

View File

@@ -16,7 +16,14 @@ class RecurringOrderPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocProvider<RecurringOrderBloc>( return BlocProvider<RecurringOrderBloc>(
create: (BuildContext context) => Modular.get<RecurringOrderBloc>(), create: (BuildContext context) {
final RecurringOrderBloc bloc = Modular.get<RecurringOrderBloc>();
final dynamic args = Modular.args.data;
if (args is Map<String, dynamic>) {
bloc.add(RecurringOrderInitialized(args));
}
return bloc;
},
child: BlocBuilder<RecurringOrderBloc, RecurringOrderState>( child: BlocBuilder<RecurringOrderBloc, RecurringOrderState>(
builder: (BuildContext context, RecurringOrderState state) { builder: (BuildContext context, RecurringOrderState state) {
final RecurringOrderBloc bloc = BlocProvider.of<RecurringOrderBloc>( final RecurringOrderBloc bloc = BlocProvider.of<RecurringOrderBloc>(