#537 (Cost Center)#539 (Hub Manager)

This commit is contained in:
2026-02-25 21:18:51 +05:30
parent af09cd40e7
commit b85a83b446
18 changed files with 285 additions and 79 deletions

View File

@@ -1,4 +1,4 @@
// ignore_for_file: always_specify_types, depend_on_referenced_packages, dead_code, dead_null_aware_expression, unused_local_variable, unused_import, sort_constructors_first, prefer_final_fields, prefer_const_constructors, deprecated_member_use, implicit_call_tearoffs
// ignore_for_file: always_specify_types, depend_on_referenced_packages, dead_code, dead_null_aware_expression, unused_local_variable, unused_import, sort_constructors_first, prefer_final_fields, prefer_const_constructors, deprecated_member_use, implicit_call_tearoffs
import 'package:krow_data_connect/krow_data_connect.dart' as dc;
import 'package:krow_domain/krow_domain.dart';
import '../../domain/repositories/hub_repository_interface.dart';
@@ -26,13 +26,20 @@ class HubRepositoryImpl implements HubRepositoryInterface {
@override
Future<List<CostCenter>> getCostCenters() async {
// Mocking cost centers for now since the backend is not yet ready.
return <CostCenter>[
const CostCenter(id: 'cc-001', name: 'Kitchen', code: '1001'),
const CostCenter(id: 'cc-002', name: 'Front Desk', code: '1002'),
const CostCenter(id: 'cc-003', name: 'Waitstaff', code: '1003'),
const CostCenter(id: 'cc-004', name: 'Management', code: '1004'),
];
return _service.run(() async {
final result = await _service.connector.listTeamHudDepartments().execute();
final Set<String> seen = <String>{};
final List<CostCenter> costCenters = <CostCenter>[];
for (final dc.ListTeamHudDepartmentsTeamHudDepartments dep
in result.data.teamHudDepartments) {
final String? cc = dep.costCenter;
if (cc != null && cc.isNotEmpty && !seen.contains(cc)) {
seen.add(cc);
costCenters.add(CostCenter(id: cc, name: dep.name, code: cc));
}
}
return costCenters;
});
}
@override
@@ -62,6 +69,7 @@ class HubRepositoryImpl implements HubRepositoryInterface {
street: street,
country: country,
zipCode: zipCode,
costCenterId: costCenterId,
);
}
@@ -107,6 +115,7 @@ class HubRepositoryImpl implements HubRepositoryInterface {
street: street,
country: country,
zipCode: zipCode,
costCenterId: costCenterId,
);
}
}

View File

@@ -72,7 +72,7 @@ class EditHubBloc extends Bloc<EditHubEvent, EditHubState>
emit(
state.copyWith(
status: EditHubStatus.success,
successMessage: 'Hub created successfully',
successKey: 'created',
),
);
},
@@ -109,7 +109,7 @@ class EditHubBloc extends Bloc<EditHubEvent, EditHubState>
emit(
state.copyWith(
status: EditHubStatus.success,
successMessage: 'Hub updated successfully',
successKey: 'updated',
),
);
},

View File

@@ -22,6 +22,7 @@ class EditHubState extends Equatable {
this.status = EditHubStatus.initial,
this.errorMessage,
this.successMessage,
this.successKey,
this.costCenters = const <CostCenter>[],
});
@@ -34,6 +35,9 @@ class EditHubState extends Equatable {
/// The success message if the operation succeeded.
final String? successMessage;
/// Localization key for success message: 'created' | 'updated'.
final String? successKey;
/// Available cost centers for selection.
final List<CostCenter> costCenters;
@@ -42,12 +46,14 @@ class EditHubState extends Equatable {
EditHubStatus? status,
String? errorMessage,
String? successMessage,
String? successKey,
List<CostCenter>? costCenters,
}) {
return EditHubState(
status: status ?? this.status,
errorMessage: errorMessage ?? this.errorMessage,
successMessage: successMessage ?? this.successMessage,
successKey: successKey ?? this.successKey,
costCenters: costCenters ?? this.costCenters,
);
}
@@ -57,6 +63,7 @@ class EditHubState extends Equatable {
status,
errorMessage,
successMessage,
successKey,
costCenters,
];
}

View File

@@ -36,7 +36,7 @@ class HubDetailsBloc extends Bloc<HubDetailsEvent, HubDetailsState>
emit(
state.copyWith(
status: HubDetailsStatus.deleted,
successMessage: 'Hub deleted successfully',
successKey: 'deleted',
),
);
},

View File

@@ -24,6 +24,7 @@ class HubDetailsState extends Equatable {
this.status = HubDetailsStatus.initial,
this.errorMessage,
this.successMessage,
this.successKey,
});
/// The status of the operation.
@@ -35,19 +36,24 @@ class HubDetailsState extends Equatable {
/// The success message if the operation succeeded.
final String? successMessage;
/// Localization key for success message: 'deleted'.
final String? successKey;
/// Create a copy of this state with the given fields replaced.
HubDetailsState copyWith({
HubDetailsStatus? status,
String? errorMessage,
String? successMessage,
String? successKey,
}) {
return HubDetailsState(
status: status ?? this.status,
errorMessage: errorMessage ?? this.errorMessage,
successMessage: successMessage ?? this.successMessage,
successKey: successKey ?? this.successKey,
);
}
@override
List<Object?> get props => <Object?>[status, errorMessage, successMessage];
List<Object?> get props => <Object?>[status, errorMessage, successMessage, successKey];
}

View File

@@ -1,3 +1,4 @@
import 'package:core_localization/core_localization.dart';
import 'package:design_system/design_system.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -34,14 +35,16 @@ class _EditHubPageState extends State<EditHubPage> {
value: widget.bloc,
child: BlocListener<EditHubBloc, EditHubState>(
listenWhen: (EditHubState prev, EditHubState curr) =>
prev.status != curr.status ||
prev.successMessage != curr.successMessage,
prev.status != curr.status || prev.successKey != curr.successKey,
listener: (BuildContext context, EditHubState state) {
if (state.status == EditHubStatus.success &&
state.successMessage != null) {
state.successKey != null) {
final String message = state.successKey == 'created'
? t.client_hubs.edit_hub.created_success
: t.client_hubs.edit_hub.updated_success;
UiSnackbar.show(
context,
message: state.successMessage!,
message: message,
type: UiSnackbarType.success,
);
Modular.to.pop(true);

View File

@@ -29,9 +29,12 @@ class HubDetailsPage extends StatelessWidget {
child: BlocListener<HubDetailsBloc, HubDetailsState>(
listener: (BuildContext context, HubDetailsState state) {
if (state.status == HubDetailsStatus.deleted) {
final String message = state.successKey == 'deleted'
? t.client_hubs.hub_details.deleted_success
: (state.successMessage ?? t.client_hubs.hub_details.deleted_success);
UiSnackbar.show(
context,
message: state.successMessage ?? 'Hub deleted successfully',
message: message,
type: UiSnackbarType.success,
);
Modular.to.pop(true); // Return true to indicate change

View File

@@ -51,7 +51,7 @@ class EditHubFormSection extends StatelessWidget {
textInputAction: TextInputAction.next,
validator: (String? value) {
if (value == null || value.trim().isEmpty) {
return 'Name is required';
return t.client_hubs.edit_hub.name_required;
}
return null;
},
@@ -181,11 +181,11 @@ class EditHubFormSection extends StatelessWidget {
width: double.maxFinite,
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 400),
child: costCenters.isEmpty
? const Padding(
padding: EdgeInsets.symmetric(horizontal: 24),
child: Text('No cost centers available'),
)
child : costCenters.isEmpty
? Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Text(t.client_hubs.edit_hub.cost_centers_empty),
)
: ListView.builder(
shrinkWrap: true,
itemCount: costCenters.length,

View File

@@ -318,9 +318,9 @@ class _HubFormDialogState extends State<HubFormDialog> {
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 400),
child: widget.costCenters.isEmpty
? const Padding(
padding: EdgeInsets.symmetric(horizontal: 24),
child: Text('No cost centers available'),
? Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Text(t.client_hubs.add_hub_dialog.cost_centers_empty),
)
: ListView.builder(
shrinkWrap: true,

View File

@@ -11,6 +11,8 @@ class HubManagerSelector extends StatelessWidget {
required this.hintText,
required this.label,
this.description,
this.noManagersText,
this.noneText,
super.key,
});
@@ -20,6 +22,8 @@ class HubManagerSelector extends StatelessWidget {
final String hintText;
final String label;
final String? description;
final String? noManagersText;
final String? noneText;
@override
Widget build(BuildContext context) {
@@ -107,18 +111,20 @@ class HubManagerSelector extends StatelessWidget {
shrinkWrap: true,
itemCount: managers.isEmpty ? 2 : managers.length + 1,
itemBuilder: (BuildContext context, int index) {
final String emptyText = noManagersText ?? 'No hub managers available';
final String noneLabel = noneText ?? 'None';
if (managers.isEmpty) {
if (index == 0) {
return const Padding(
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 8),
child: Text('No hub managers available'),
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
child: Text(emptyText),
);
}
return ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
title: Text('None', style: UiTypography.body1m.textSecondary),
title: Text(noneLabel, style: UiTypography.body1m.textSecondary),
onTap: () => Navigator.of(context).pop(
const OrderManagerUiModel(id: 'NONE', name: 'None'),
OrderManagerUiModel(id: 'NONE', name: noneLabel),
),
);
}
@@ -126,9 +132,9 @@ class HubManagerSelector extends StatelessWidget {
if (index == managers.length) {
return ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
title: Text('None', style: UiTypography.body1m.textSecondary),
title: Text(noneLabel, style: UiTypography.body1m.textSecondary),
onTap: () => Navigator.of(context).pop(
const OrderManagerUiModel(id: 'NONE', name: 'None'),
OrderManagerUiModel(id: 'NONE', name: noneLabel),
),
);
}

View File

@@ -332,6 +332,8 @@ class _OneTimeOrderForm extends StatelessWidget {
label: labels.hub_manager_label,
description: labels.hub_manager_desc,
hintText: labels.hub_manager_hint,
noManagersText: labels.hub_manager_empty,
noneText: labels.hub_manager_none,
managers: hubManagers,
selectedManager: selectedHubManager,
onChanged: onHubManagerChanged,

View File

@@ -354,6 +354,8 @@ class _PermanentOrderForm extends StatelessWidget {
label: oneTimeLabels.hub_manager_label,
description: oneTimeLabels.hub_manager_desc,
hintText: oneTimeLabels.hub_manager_hint,
noManagersText: oneTimeLabels.hub_manager_empty,
noneText: oneTimeLabels.hub_manager_none,
managers: hubManagers,
selectedManager: selectedHubManager,
onChanged: onHubManagerChanged,

View File

@@ -375,6 +375,8 @@ class _RecurringOrderForm extends StatelessWidget {
label: oneTimeLabels.hub_manager_label,
description: oneTimeLabels.hub_manager_desc,
hintText: oneTimeLabels.hub_manager_hint,
noManagersText: oneTimeLabels.hub_manager_empty,
noneText: oneTimeLabels.hub_manager_none,
managers: hubManagers,
selectedManager: selectedHubManager,
onChanged: onHubManagerChanged,

View File

@@ -1,3 +1,4 @@
import 'package:core_localization/core_localization.dart';
import 'package:design_system/design_system.dart';
import 'package:firebase_auth/firebase_auth.dart' as firebase;
import 'package:firebase_data_connect/firebase_data_connect.dart';
@@ -686,7 +687,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
padding: const EdgeInsets.all(UiConstants.space5),
children: <Widget>[
Text(
'Edit Your Order',
t.client_view_orders.order_edit_sheet.title,
style: UiTypography.headline3m.textPrimary,
),
const SizedBox(height: UiConstants.space4),
@@ -744,7 +745,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
_buildSectionHeader('ORDER NAME'),
UiTextField(
controller: _orderNameController,
hintText: 'Order name',
hintText: t.client_view_orders.order_edit_sheet.order_name_hint,
prefixIcon: UiIcons.briefcase,
),
const SizedBox(height: UiConstants.space4),
@@ -801,7 +802,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'POSITIONS',
t.client_view_orders.order_edit_sheet.positions_section,
style: UiTypography.headline4m.textPrimary,
),
TextButton(
@@ -821,7 +822,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
color: UiColors.primary,
),
Text(
'Add Position',
t.client_view_orders.order_edit_sheet.add_position,
style: UiTypography.body2m.primary,
),
],
@@ -842,7 +843,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
),
),
_buildBottomAction(
label: 'Review ${_positions.length} Positions',
label: t.client_view_orders.order_edit_sheet.review_positions(count: _positions.length.toString()),
onPressed: () => setState(() => _showReview = true),
),
const Padding(
@@ -859,11 +860,13 @@ class OrderEditSheetState extends State<OrderEditSheet> {
}
Widget _buildHubManagerSelector() {
final TranslationsClientViewOrdersOrderEditSheetEn oes =
t.client_view_orders.order_edit_sheet;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_buildSectionHeader('SHIFT CONTACT'),
Text('On-site manager or supervisor for this shift', style: UiTypography.body2r.textSecondary),
_buildSectionHeader(oes.shift_contact_section),
Text(oes.shift_contact_desc, style: UiTypography.body2r.textSecondary),
const SizedBox(height: UiConstants.space2),
InkWell(
onTap: () => _showHubManagerSelector(),
@@ -895,7 +898,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
),
const SizedBox(width: UiConstants.space3),
Text(
_selectedManager?.user.fullName ?? 'Select Contact',
_selectedManager?.user.fullName ?? oes.select_contact,
style: _selectedManager != null
? UiTypography.body1r.textPrimary
: UiTypography.body2r.textPlaceholder,
@@ -925,7 +928,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
borderRadius: BorderRadius.circular(UiConstants.radiusBase),
),
title: Text(
'Shift Contact',
t.client_view_orders.order_edit_sheet.shift_contact_section,
style: UiTypography.headline3m.textPrimary,
),
contentPadding: const EdgeInsets.symmetric(vertical: 16),
@@ -939,14 +942,14 @@ class OrderEditSheetState extends State<OrderEditSheet> {
itemBuilder: (BuildContext context, int index) {
if (_managers.isEmpty) {
if (index == 0) {
return const Padding(
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 8),
child: Text('No hub managers available'),
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
child: Text(t.client_view_orders.order_edit_sheet.no_hub_managers),
);
}
return ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
title: Text('None', style: UiTypography.body1m.textSecondary),
title: Text(t.client_view_orders.order_edit_sheet.none, style: UiTypography.body1m.textSecondary),
onTap: () => Navigator.of(context).pop(null),
);
}
@@ -954,7 +957,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
if (index == _managers.length) {
return ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
title: Text('None', style: UiTypography.body1m.textSecondary),
title: Text(t.client_view_orders.order_edit_sheet.none, style: UiTypography.body1m.textSecondary),
onTap: () => Navigator.of(context).pop(null),
);
}
@@ -1014,11 +1017,11 @@ class OrderEditSheetState extends State<OrderEditSheet> {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'One-Time Order',
t.client_view_orders.order_edit_sheet.one_time_order_title,
style: UiTypography.headline3m.copyWith(color: UiColors.white),
),
Text(
'Refine your staffing needs',
t.client_view_orders.order_edit_sheet.refine_subtitle,
style: UiTypography.footnote2r.copyWith(
color: UiColors.white.withValues(alpha: 0.8),
),
@@ -1060,7 +1063,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
GestureDetector(
onTap: () => _removePosition(index),
child: Text(
'Remove',
t.client_view_orders.order_edit_sheet.remove,
style: UiTypography.footnote1m.copyWith(
color: UiColors.destructive,
),
@@ -1071,7 +1074,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
const SizedBox(height: UiConstants.space3),
_buildDropdownField(
hint: 'Select role',
hint: t.client_view_orders.order_edit_sheet.select_role_hint,
value: pos['roleId'],
items: <String>[
..._roles.map((_RoleOption role) => role.id),
@@ -1106,7 +1109,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
children: <Widget>[
Expanded(
child: _buildInlineTimeInput(
label: 'Start',
label: t.client_view_orders.order_edit_sheet.start_label,
value: pos['start_time'],
onTap: () async {
final TimeOfDay? picked = await showTimePicker(
@@ -1126,7 +1129,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
const SizedBox(width: UiConstants.space2),
Expanded(
child: _buildInlineTimeInput(
label: 'End',
label: t.client_view_orders.order_edit_sheet.end_label,
value: pos['end_time'],
onTap: () async {
final TimeOfDay? picked = await showTimePicker(
@@ -1149,7 +1152,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Workers',
t.client_view_orders.order_edit_sheet.workers_label,
style: UiTypography.footnote2r.textSecondary,
),
const SizedBox(height: UiConstants.space1),
@@ -1204,7 +1207,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
const Icon(UiIcons.mapPin, size: 14, color: UiColors.primary),
const SizedBox(width: UiConstants.space1),
Text(
'Use different location for this position',
t.client_view_orders.order_edit_sheet.different_location,
style: UiTypography.footnote1m.copyWith(
color: UiColors.primary,
),
@@ -1228,7 +1231,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
),
const SizedBox(width: UiConstants.space1),
Text(
'Different Location',
t.client_view_orders.order_edit_sheet.different_location_title,
style: UiTypography.footnote1m.textSecondary,
),
],
@@ -1246,7 +1249,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
const SizedBox(height: UiConstants.space2),
UiTextField(
controller: TextEditingController(text: pos['location']),
hintText: 'Enter different address',
hintText: t.client_view_orders.order_edit_sheet.enter_address_hint,
onChanged: (String val) =>
_updatePosition(index, 'location', val),
),
@@ -1257,7 +1260,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
_buildSectionHeader('LUNCH BREAK'),
_buildDropdownField(
hint: 'No Break',
hint: t.client_view_orders.order_edit_sheet.no_break,
value: pos['lunch_break'],
items: <String>[
'NO_BREAK',
@@ -1280,7 +1283,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
case 'MIN_60':
return '60 min (Unpaid)';
default:
return 'No Break';
return t.client_view_orders.order_edit_sheet.no_break;
}
},
onChanged: (dynamic val) =>
@@ -1438,11 +1441,11 @@ class OrderEditSheetState extends State<OrderEditSheet> {
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
_buildSummaryItem('${_positions.length}', 'Positions'),
_buildSummaryItem('$totalWorkers', 'Workers'),
_buildSummaryItem('${_positions.length}', t.client_view_orders.order_edit_sheet.positions),
_buildSummaryItem('$totalWorkers', t.client_view_orders.order_edit_sheet.workers),
_buildSummaryItem(
'\$${totalCost.round()}',
'Est. Cost',
t.client_view_orders.order_edit_sheet.est_cost,
),
],
),
@@ -1501,7 +1504,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
const SizedBox(height: 24),
Text(
'Positions Breakdown',
t.client_view_orders.order_edit_sheet.positions_breakdown,
style: UiTypography.body2b.textPrimary,
),
const SizedBox(height: 12),
@@ -1532,14 +1535,14 @@ class OrderEditSheetState extends State<OrderEditSheet> {
children: <Widget>[
Expanded(
child: UiButton.secondary(
text: 'Edit',
text: t.client_view_orders.order_edit_sheet.edit_button,
onPressed: () => setState(() => _showReview = false),
),
),
const SizedBox(width: 12),
Expanded(
child: UiButton.primary(
text: 'Confirm & Save',
text: t.client_view_orders.order_edit_sheet.confirm_save,
onPressed: () async {
setState(() => _isLoading = true);
await _saveOrderChanges();
@@ -1601,7 +1604,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
children: <Widget>[
Text(
(role?.name ?? pos['roleName']?.toString() ?? '').isEmpty
? 'Position'
? t.client_view_orders.order_edit_sheet.position_singular
: (role?.name ?? pos['roleName']?.toString() ?? ''),
style: UiTypography.body2b.textPrimary,
),
@@ -1667,14 +1670,14 @@ class OrderEditSheetState extends State<OrderEditSheet> {
),
const SizedBox(height: 24),
Text(
'Order Updated!',
t.client_view_orders.order_edit_sheet.order_updated_title,
style: UiTypography.headline1m.copyWith(color: UiColors.white),
),
const SizedBox(height: 12),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 40),
child: Text(
'Your shift has been updated successfully.',
t.client_view_orders.order_edit_sheet.order_updated_message,
textAlign: TextAlign.center,
style: UiTypography.body1r.copyWith(
color: UiColors.white.withValues(alpha: 0.7),
@@ -1685,7 +1688,7 @@ class OrderEditSheetState extends State<OrderEditSheet> {
Padding(
padding: const EdgeInsets.symmetric(horizontal: 40),
child: UiButton.secondary(
text: 'Back to Orders',
text: t.client_view_orders.order_edit_sheet.back_to_orders,
fullWidth: true,
style: OutlinedButton.styleFrom(
backgroundColor: UiColors.white,