update order with new hub
This commit is contained in:
@@ -664,6 +664,8 @@ class _OrderEditSheetState extends State<_OrderEditSheet> {
|
|||||||
List<Vendor> _vendors = const <Vendor>[];
|
List<Vendor> _vendors = const <Vendor>[];
|
||||||
Vendor? _selectedVendor;
|
Vendor? _selectedVendor;
|
||||||
List<_RoleOption> _roles = const <_RoleOption>[];
|
List<_RoleOption> _roles = const <_RoleOption>[];
|
||||||
|
List<dc.ListTeamHubsByOwnerIdTeamHubs> _hubs = const <dc.ListTeamHubsByOwnerIdTeamHubs>[];
|
||||||
|
dc.ListTeamHubsByOwnerIdTeamHubs? _selectedHub;
|
||||||
|
|
||||||
String? _shiftId;
|
String? _shiftId;
|
||||||
List<_ShiftRoleKey> _originalShiftRoles = const <_ShiftRoleKey>[];
|
List<_ShiftRoleKey> _originalShiftRoles = const <_ShiftRoleKey>[];
|
||||||
@@ -725,6 +727,7 @@ class _OrderEditSheetState extends State<_OrderEditSheet> {
|
|||||||
final List<dc.ListShiftRolesByBusinessAndOrderShiftRoles> shiftRoles =
|
final List<dc.ListShiftRolesByBusinessAndOrderShiftRoles> shiftRoles =
|
||||||
result.data.shiftRoles;
|
result.data.shiftRoles;
|
||||||
if (shiftRoles.isEmpty) {
|
if (shiftRoles.isEmpty) {
|
||||||
|
await _loadHubsAndSelect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -771,6 +774,13 @@ class _OrderEditSheetState extends State<_OrderEditSheet> {
|
|||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
await _loadVendorsAndSelect(firstShift.order.vendorId);
|
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) {
|
if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -783,6 +793,75 @@ class _OrderEditSheetState extends State<_OrderEditSheet> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _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<dc.ListTeamHubsByOwnerIdTeamHubs> 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 <dc.ListTeamHubsByOwnerIdTeamHubs>[];
|
||||||
|
_selectedHub = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _loadVendorsAndSelect(String? selectedVendorId) async {
|
Future<void> _loadVendorsAndSelect(String? selectedVendorId) async {
|
||||||
try {
|
try {
|
||||||
final QueryResult<dc.ListVendorsData, void> result =
|
final QueryResult<dc.ListVendorsData, void> result =
|
||||||
@@ -985,7 +1064,10 @@ class _OrderEditSheetState extends State<_OrderEditSheet> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final DateTime orderDate = _parseDate(_dateController.text);
|
final DateTime orderDate = _parseDate(_dateController.text);
|
||||||
final String location = _globalLocationController.text;
|
final dc.ListTeamHubsByOwnerIdTeamHubs? selectedHub = _selectedHub;
|
||||||
|
if (selectedHub == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int totalWorkers = 0;
|
int totalWorkers = 0;
|
||||||
double shiftCost = 0;
|
double shiftCost = 0;
|
||||||
@@ -1076,9 +1158,8 @@ class _OrderEditSheetState extends State<_OrderEditSheet> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await _dataConnect
|
await _dataConnect
|
||||||
.updateOrder(id: widget.order.orderId)
|
.updateOrder(id: widget.order.orderId, teamHubId: selectedHub.id)
|
||||||
.vendorId(_selectedVendor?.id)
|
.vendorId(_selectedVendor?.id)
|
||||||
.location(location)
|
|
||||||
.date(_toTimestamp(orderDateOnly))
|
.date(_toTimestamp(orderDateOnly))
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
@@ -1086,8 +1167,15 @@ class _OrderEditSheetState extends State<_OrderEditSheet> {
|
|||||||
.updateShift(id: _shiftId!)
|
.updateShift(id: _shiftId!)
|
||||||
.title('shift 1 ${DateFormat('yyyy-MM-dd').format(orderDate)}')
|
.title('shift 1 ${DateFormat('yyyy-MM-dd').format(orderDate)}')
|
||||||
.date(_toTimestamp(orderDateOnly))
|
.date(_toTimestamp(orderDateOnly))
|
||||||
.location(location)
|
.location(selectedHub.hubName)
|
||||||
.locationAddress(location)
|
.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)
|
.workersNeeded(totalWorkers)
|
||||||
.cost(shiftCost)
|
.cost(shiftCost)
|
||||||
.durationDays(1)
|
.durationDays(1)
|
||||||
@@ -1189,11 +1277,49 @@ class _OrderEditSheetState extends State<_OrderEditSheet> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: UiConstants.space4),
|
const SizedBox(height: UiConstants.space4),
|
||||||
|
|
||||||
_buildSectionHeader('LOCATION'),
|
_buildSectionHeader('HUB'),
|
||||||
UiTextField(
|
Container(
|
||||||
controller: _globalLocationController,
|
padding: const EdgeInsets.symmetric(
|
||||||
hintText: 'Business address',
|
horizontal: UiConstants.space3,
|
||||||
prefixIcon: UiIcons.mapPin,
|
),
|
||||||
|
height: 48,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: UiColors.white,
|
||||||
|
borderRadius: UiConstants.radiusMd,
|
||||||
|
border: Border.all(color: UiColors.border),
|
||||||
|
),
|
||||||
|
child: DropdownButtonHideUnderline(
|
||||||
|
child: DropdownButton<dc.ListTeamHubsByOwnerIdTeamHubs>(
|
||||||
|
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),
|
const SizedBox(height: UiConstants.space6),
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user