From 7b5700958604d582424e895947655e942c2fd3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Salazar?= <73718835+joshrs23@users.noreply.github.com> Date: Thu, 29 Jan 2026 16:18:02 -0500 Subject: [PATCH] update order with new hub --- .../presentation/widgets/view_order_card.dart | 146 ++++++++++++++++-- 1 file changed, 136 insertions(+), 10 deletions(-) diff --git a/apps/mobile/packages/features/client/view_orders/lib/src/presentation/widgets/view_order_card.dart b/apps/mobile/packages/features/client/view_orders/lib/src/presentation/widgets/view_order_card.dart index 41d505d2..59521da3 100644 --- a/apps/mobile/packages/features/client/view_orders/lib/src/presentation/widgets/view_order_card.dart +++ b/apps/mobile/packages/features/client/view_orders/lib/src/presentation/widgets/view_order_card.dart @@ -664,6 +664,8 @@ class _OrderEditSheetState extends State<_OrderEditSheet> { List _vendors = const []; Vendor? _selectedVendor; List<_RoleOption> _roles = const <_RoleOption>[]; + List _hubs = const []; + dc.ListTeamHubsByOwnerIdTeamHubs? _selectedHub; String? _shiftId; List<_ShiftRoleKey> _originalShiftRoles = const <_ShiftRoleKey>[]; @@ -725,6 +727,7 @@ class _OrderEditSheetState extends State<_OrderEditSheet> { final List shiftRoles = result.data.shiftRoles; if (shiftRoles.isEmpty) { + await _loadHubsAndSelect(); return; } @@ -771,6 +774,13 @@ class _OrderEditSheetState extends State<_OrderEditSheet> { .toList(); await _loadVendorsAndSelect(firstShift.order.vendorId); + final dc.ListShiftRolesByBusinessAndOrderShiftRolesShiftOrderTeamHub? + teamHub = firstShift.order.teamHub; + await _loadHubsAndSelect( + placeId: teamHub?.placeId, + hubName: teamHub?.hubName, + address: teamHub?.address, + ); if (mounted) { setState(() { @@ -783,6 +793,75 @@ class _OrderEditSheetState extends State<_OrderEditSheet> { } } + Future _loadHubsAndSelect({ + String? placeId, + String? hubName, + String? address, + }) async { + final String? businessId = + dc.ClientSessionStore.instance.session?.business?.id; + if (businessId == null || businessId.isEmpty) { + return; + } + + try { + final QueryResult< + dc.ListTeamHubsByOwnerIdData, + dc.ListTeamHubsByOwnerIdVariables> result = await _dataConnect + .listTeamHubsByOwnerId(ownerId: businessId) + .execute(); + + final List hubs = result.data.teamHubs; + dc.ListTeamHubsByOwnerIdTeamHubs? selected; + + if (placeId != null && placeId.isNotEmpty) { + for (final dc.ListTeamHubsByOwnerIdTeamHubs hub in hubs) { + if (hub.placeId == placeId) { + selected = hub; + break; + } + } + } + + if (selected == null && hubName != null && hubName.isNotEmpty) { + for (final dc.ListTeamHubsByOwnerIdTeamHubs hub in hubs) { + if (hub.hubName == hubName) { + selected = hub; + break; + } + } + } + + if (selected == null && address != null && address.isNotEmpty) { + for (final dc.ListTeamHubsByOwnerIdTeamHubs hub in hubs) { + if (hub.address == address) { + selected = hub; + break; + } + } + } + + selected ??= hubs.isNotEmpty ? hubs.first : null; + + if (mounted) { + setState(() { + _hubs = hubs; + _selectedHub = selected; + if (selected != null) { + _globalLocationController.text = selected.address; + } + }); + } + } catch (_) { + if (mounted) { + setState(() { + _hubs = const []; + _selectedHub = null; + }); + } + } + } + Future _loadVendorsAndSelect(String? selectedVendorId) async { try { final QueryResult result = @@ -985,7 +1064,10 @@ class _OrderEditSheetState extends State<_OrderEditSheet> { } final DateTime orderDate = _parseDate(_dateController.text); - final String location = _globalLocationController.text; + final dc.ListTeamHubsByOwnerIdTeamHubs? selectedHub = _selectedHub; + if (selectedHub == null) { + return; + } int totalWorkers = 0; double shiftCost = 0; @@ -1076,9 +1158,8 @@ class _OrderEditSheetState extends State<_OrderEditSheet> { ); await _dataConnect - .updateOrder(id: widget.order.orderId) + .updateOrder(id: widget.order.orderId, teamHubId: selectedHub.id) .vendorId(_selectedVendor?.id) - .location(location) .date(_toTimestamp(orderDateOnly)) .execute(); @@ -1086,8 +1167,15 @@ class _OrderEditSheetState extends State<_OrderEditSheet> { .updateShift(id: _shiftId!) .title('shift 1 ${DateFormat('yyyy-MM-dd').format(orderDate)}') .date(_toTimestamp(orderDateOnly)) - .location(location) - .locationAddress(location) + .location(selectedHub.hubName) + .locationAddress(selectedHub.address) + .latitude(selectedHub.latitude) + .longitude(selectedHub.longitude) + .placeId(selectedHub.placeId) + .city(selectedHub.city) + .state(selectedHub.state) + .street(selectedHub.street) + .country(selectedHub.country) .workersNeeded(totalWorkers) .cost(shiftCost) .durationDays(1) @@ -1189,11 +1277,49 @@ class _OrderEditSheetState extends State<_OrderEditSheet> { ), const SizedBox(height: UiConstants.space4), - _buildSectionHeader('LOCATION'), - UiTextField( - controller: _globalLocationController, - hintText: 'Business address', - prefixIcon: UiIcons.mapPin, + _buildSectionHeader('HUB'), + Container( + padding: const EdgeInsets.symmetric( + horizontal: UiConstants.space3, + ), + height: 48, + decoration: BoxDecoration( + color: UiColors.white, + borderRadius: UiConstants.radiusMd, + border: Border.all(color: UiColors.border), + ), + child: DropdownButtonHideUnderline( + child: DropdownButton( + isExpanded: true, + value: _selectedHub, + icon: const Icon( + UiIcons.chevronDown, + size: 18, + color: UiColors.iconSecondary, + ), + onChanged: + (dc.ListTeamHubsByOwnerIdTeamHubs? hub) { + if (hub != null) { + setState(() { + _selectedHub = hub; + _globalLocationController.text = hub.address; + }); + } + }, + items: _hubs.map( + (dc.ListTeamHubsByOwnerIdTeamHubs hub) { + return DropdownMenuItem< + dc.ListTeamHubsByOwnerIdTeamHubs>( + value: hub, + child: Text( + hub.hubName, + style: UiTypography.body2m.textPrimary, + ), + ); + }, + ).toList(), + ), + ), ), const SizedBox(height: UiConstants.space6),