Refactor code structure for improved readability and maintainability

This commit is contained in:
Achintha Isuru
2026-01-28 12:56:35 -05:00
parent f2382fba3d
commit 710421a832
10 changed files with 17786 additions and 17732 deletions

View File

@@ -6,7 +6,7 @@
/// Locales: 2
/// Strings: 1038 (519 per locale)
///
/// Built on 2026-01-27 at 19:37 UTC
/// Built on 2026-01-28 at 16:34 UTC
// coverage:ignore-file
// ignore_for_file: type=lint, unused_import

View File

@@ -1,16 +1,16 @@
# Basic Usage
```dart
ExampleConnector.instance.createTaxForm(createTaxFormVariables).execute();
ExampleConnector.instance.updateTaxForm(updateTaxFormVariables).execute();
ExampleConnector.instance.deleteTaxForm(deleteTaxFormVariables).execute();
ExampleConnector.instance.listClientFeedbacks(listClientFeedbacksVariables).execute();
ExampleConnector.instance.getClientFeedbackById(getClientFeedbackByIdVariables).execute();
ExampleConnector.instance.listClientFeedbacksByBusinessId(listClientFeedbacksByBusinessIdVariables).execute();
ExampleConnector.instance.listClientFeedbacksByVendorId(listClientFeedbacksByVendorIdVariables).execute();
ExampleConnector.instance.listClientFeedbacksByBusinessAndVendor(listClientFeedbacksByBusinessAndVendorVariables).execute();
ExampleConnector.instance.filterClientFeedbacks(filterClientFeedbacksVariables).execute();
ExampleConnector.instance.listClientFeedbackRatingsByVendorId(listClientFeedbackRatingsByVendorIdVariables).execute();
ExampleConnector.instance.CreateAssignment(createAssignmentVariables).execute();
ExampleConnector.instance.UpdateAssignment(updateAssignmentVariables).execute();
ExampleConnector.instance.DeleteAssignment(deleteAssignmentVariables).execute();
ExampleConnector.instance.listBenefitsData(listBenefitsDataVariables).execute();
ExampleConnector.instance.getBenefitsDataByKey(getBenefitsDataByKeyVariables).execute();
ExampleConnector.instance.listBenefitsDataByStaffId(listBenefitsDataByStaffIdVariables).execute();
ExampleConnector.instance.listBenefitsDataByVendorBenefitPlanId(listBenefitsDataByVendorBenefitPlanIdVariables).execute();
ExampleConnector.instance.listBenefitsDataByVendorBenefitPlanIds(listBenefitsDataByVendorBenefitPlanIdsVariables).execute();
ExampleConnector.instance.getStaffDocumentByKey(getStaffDocumentByKeyVariables).execute();
ExampleConnector.instance.listStaffDocumentsByStaffId(listStaffDocumentsByStaffIdVariables).execute();
```
@@ -23,8 +23,8 @@ Optional fields can be discovered based on classes that have `Optional` object t
This is an example of a mutation with an optional field:
```dart
await ExampleConnector.instance.filterFaqDatas({ ... })
.category(...)
await ExampleConnector.instance.filterStaffAvailabilityStats({ ... })
.needWorkIndexMin(...)
.execute();
```

View File

@@ -33,11 +33,11 @@ class TaxFormsRepositoryImpl implements TaxFormsRepository {
@override
Future<List<TaxForm>> getTaxForms() async {
final String staffId = _getStaffId();
final QueryResult<dc.GetTaxFormsBystaffIdData, dc.GetTaxFormsBystaffIdVariables>
final QueryResult<dc.GetTaxFormsByStaffIdData, dc.GetTaxFormsByStaffIdVariables>
result =
await dataConnect.getTaxFormsBystaffId(staffId: staffId).execute();
await dataConnect.getTaxFormsByStaffId(staffId: staffId).execute();
final List<TaxForm> forms = result.data.taxForms.map((dc.GetTaxFormsBystaffIdTaxForms e) => _mapToEntity(e)).toList();
final List<TaxForm> forms = result.data.taxForms.map((dc.GetTaxFormsByStaffIdTaxForms e) => _mapToEntity(e)).toList();
// Check if required forms exist, create if not.
final Set<TaxFormType> typesPresent = forms.map((TaxForm f) => f.type).toSet();
@@ -53,21 +53,142 @@ class TaxFormsRepositoryImpl implements TaxFormsRepository {
}
if (createdNew) {
final QueryResult<dc.GetTaxFormsBystaffIdData, dc.GetTaxFormsBystaffIdVariables>
final QueryResult<dc.GetTaxFormsByStaffIdData, dc.GetTaxFormsByStaffIdVariables>
result2 =
await dataConnect.getTaxFormsBystaffId(staffId: staffId).execute();
return result2.data.taxForms.map((dc.GetTaxFormsBystaffIdTaxForms e) => _mapToEntity(e)).toList();
await dataConnect.getTaxFormsByStaffId(staffId: staffId).execute();
return result2.data.taxForms.map((dc.GetTaxFormsByStaffIdTaxForms e) => _mapToEntity(e)).toList();
}
return forms;
}
Future<void> _createInitialForm(String staffId, TaxFormType type) async {
await dataConnect
.createTaxForm(
staffId: staffId,
formType:
dc.TaxFormType.values.byName(TaxFormAdapter.typeToString(type)),
firstName: '',
lastName: '',
socialSN: 0,
address: '',
status: dc.TaxFormStatus.NOT_STARTED,
)
.execute();
}
@override
Future<void> submitForm(TaxFormType type, Map<String, dynamic> data) async {
final String staffId = _getStaffId();
final QueryResult<dc.GetTaxFormsByStaffIdData, dc.GetTaxFormsByStaffIdVariables>
result =
await dataConnect.getTaxFormsByStaffId(staffId: staffId).execute();
final String targetTypeString = TaxFormAdapter.typeToString(type);
final dc.GetTaxFormsByStaffIdTaxForms form =
result.data.taxForms.firstWhere(
(dc.GetTaxFormsByStaffIdTaxForms e) =>
e.formType.stringValue == targetTypeString,
orElse: () => throw Exception('Form not found for submission'),
);
final builder = dataConnect.updateTaxForm(id: form.id);
// Map input fields to DataConnect variables
if (data.containsKey('firstName')) {
builder.firstName(data['firstName'] as String);
}
if (data.containsKey('lastName')) {
builder.lastName(data['lastName'] as String);
}
if (data.containsKey('middleInitial')) {
builder.mInitial(data['middleInitial'] as String);
}
if (data.containsKey('otherLastNames')) {
builder.oLastName(data['otherLastNames'] as String);
}
if (data.containsKey('ssn') && data['ssn'] != null) {
builder.socialSN(int.tryParse(data['ssn'].toString()) ?? 0);
}
if (data.containsKey('email')) {
builder.email(data['email'] as String);
}
if (data.containsKey('phone')) {
builder.phone(data['phone'] as String);
}
if (data.containsKey('address')) {
builder.address(data['address'] as String);
}
if (data.containsKey('aptNumber')) {
builder.apt(data['aptNumber'] as String);
}
if (data.containsKey('city')) {
builder.city(data['city'] as String);
}
if (data.containsKey('state')) {
builder.state(data['state'] as String);
}
if (data.containsKey('zipCode')) {
builder.zipCode(data['zipCode'] as String);
}
// Citizenship / Marital / Bool fields would go here.
// For now, mapping the core identity fields visible in the form logic.
// Assuming UI keys match these:
if (data.containsKey('citizenshipStatus')) {
// Need mapping for enum
}
await builder.status(dc.TaxFormStatus.SUBMITTED).execute();
}
@override
Future<void> updateFormStatus(TaxFormType type, TaxFormStatus status) async {
final String staffId = _getStaffId();
final QueryResult<dc.GetTaxFormsByStaffIdData, dc.GetTaxFormsByStaffIdVariables>
result =
await dataConnect.getTaxFormsByStaffId(staffId: staffId).execute();
final String targetTypeString = TaxFormAdapter.typeToString(type);
final dc.GetTaxFormsByStaffIdTaxForms form =
result.data.taxForms.firstWhere(
(dc.GetTaxFormsByStaffIdTaxForms e) =>
e.formType.stringValue == targetTypeString,
orElse: () => throw Exception('Form not found for update'),
);
await dataConnect
.updateTaxForm(
id: form.id,
)
.status(dc.TaxFormStatus.values
.byName(TaxFormAdapter.statusToString(status)))
.execute();
}
TaxForm _mapToEntity(dc.GetTaxFormsByStaffIdTaxForms form) {
// Construct the legacy map for the entity
final Map<String, dynamic> formData = {
'firstName': form.firstName,
'lastName': form.lastName,
'middleInitial': form.mInitial,
'otherLastNames': form.oLastName,
'ssn': form.socialSN.toString(),
'email': form.email,
'phone': form.phone,
'address': form.address,
'aptNumber': form.apt,
'city': form.city,
'state': form.state,
'zipCode': form.zipCode,
// Add other fields as they become available in the UI
};
String title = '';
String subtitle = '';
String description = '';
if (type == TaxFormType.i9) {
if (form.formType == dc.TaxFormType.I9) {
title = 'Form I-9';
subtitle = 'Employment Eligibility Verification';
description = 'Required for all new hires to verify identity.';
@@ -77,72 +198,15 @@ class TaxFormsRepositoryImpl implements TaxFormsRepository {
description = 'Determines federal income tax withholding.';
}
await dataConnect
.createTaxForm(
staffId: staffId,
formType: dc.TaxFormType.values.byName(TaxFormAdapter.typeToString(type)),
title: title,
)
.subtitle(subtitle)
.description(description)
.status(dc.TaxFormStatus.NOT_STARTED)
.execute();
}
@override
Future<void> submitForm(TaxFormType type, Map<String, dynamic> data) async {
final String staffId = _getStaffId();
final QueryResult<dc.GetTaxFormsBystaffIdData, dc.GetTaxFormsBystaffIdVariables>
result =
await dataConnect.getTaxFormsBystaffId(staffId: staffId).execute();
final String targetTypeString = TaxFormAdapter.typeToString(type);
final dc.GetTaxFormsBystaffIdTaxForms form = result.data.taxForms.firstWhere(
(dc.GetTaxFormsBystaffIdTaxForms e) => e.formType.stringValue == targetTypeString,
orElse: () => throw Exception('Form not found for submission'),
);
// AnyValue expects a scalar, list, or map.
await dataConnect
.updateTaxForm(
id: form.id,
)
.formData(AnyValue.fromJson(data))
.status(dc.TaxFormStatus.SUBMITTED)
.execute();
}
@override
Future<void> updateFormStatus(TaxFormType type, TaxFormStatus status) async {
final String staffId = _getStaffId();
final QueryResult<dc.GetTaxFormsBystaffIdData, dc.GetTaxFormsBystaffIdVariables>
result =
await dataConnect.getTaxFormsBystaffId(staffId: staffId).execute();
final String targetTypeString = TaxFormAdapter.typeToString(type);
final dc.GetTaxFormsBystaffIdTaxForms form = result.data.taxForms.firstWhere(
(dc.GetTaxFormsBystaffIdTaxForms e) => e.formType.stringValue == targetTypeString,
orElse: () => throw Exception('Form not found for update'),
);
await dataConnect
.updateTaxForm(
id: form.id,
)
.status(dc.TaxFormStatus.values.byName(TaxFormAdapter.statusToString(status)))
.execute();
}
TaxForm _mapToEntity(dc.GetTaxFormsBystaffIdTaxForms form) {
return TaxFormAdapter.fromPrimitives(
id: form.id,
type: form.formType.stringValue,
title: form.title,
subtitle: form.subtitle,
description: form.description,
title: title,
subtitle: subtitle,
description: description,
status: form.status.stringValue,
staffId: form.staffId,
formData: form.formData, // Adapter expects dynamic
formData: formData,
updatedAt: form.updatedAt?.toDateTime(),
);
}

View File

@@ -25,11 +25,13 @@ class PersonalInfoBloc extends Bloc<PersonalInfoEvent, PersonalInfoState>
required UpdatePersonalInfoUseCase updatePersonalInfoUseCase,
}) : _getPersonalInfoUseCase = getPersonalInfoUseCase,
_updatePersonalInfoUseCase = updatePersonalInfoUseCase,
super(const PersonalInfoState()) {
super(const PersonalInfoState.initial()) {
on<PersonalInfoLoadRequested>(_onLoadRequested);
on<PersonalInfoFieldUpdated>(_onFieldUpdated);
on<PersonalInfoSaveRequested>(_onSaveRequested);
on<PersonalInfoPhotoUploadRequested>(_onPhotoUploadRequested);
on<PersonalInfoFieldChanged>(_onFieldChanged);
on<PersonalInfoAddressSelected>(_onAddressSelected);
on<PersonalInfoFormSubmitted>(_onSubmitted);
add(const PersonalInfoLoadRequested());
}
/// Handles loading staff profile information.
@@ -67,8 +69,8 @@ class PersonalInfoBloc extends Bloc<PersonalInfoEvent, PersonalInfoState>
}
/// Handles updating a field value in the current staff profile.
void _onFieldUpdated(
PersonalInfoFieldUpdated event,
void _onFieldChanged(
PersonalInfoFieldChanged event,
Emitter<PersonalInfoState> emit,
) {
final Map<String, dynamic> updatedValues = Map.from(state.formValues);
@@ -77,8 +79,8 @@ class PersonalInfoBloc extends Bloc<PersonalInfoEvent, PersonalInfoState>
}
/// Handles saving staff profile information.
Future<void> _onSaveRequested(
PersonalInfoSaveRequested event,
Future<void> _onSubmitted(
PersonalInfoFormSubmitted event,
Emitter<PersonalInfoState> emit,
) async {
if (state.staff == null) return;
@@ -116,33 +118,16 @@ class PersonalInfoBloc extends Bloc<PersonalInfoEvent, PersonalInfoState>
}
}
/// Handles uploading a profile photo.
Future<void> _onPhotoUploadRequested(
PersonalInfoPhotoUploadRequested event,
void _onAddressSelected(
PersonalInfoAddressSelected event,
Emitter<PersonalInfoState> emit,
) async {
if (state.staff == null) return;
emit(state.copyWith(status: PersonalInfoStatus.uploadingPhoto));
try {
// TODO: Implement photo upload when repository method is available
// final photoUrl = await _repository.uploadProfilePhoto(event.filePath);
// final updatedStaff = Staff(...);
// emit(state.copyWith(
// status: PersonalInfoStatus.loaded,
// staff: updatedStaff,
// ));
// For now, just return to loaded state
emit(state.copyWith(status: PersonalInfoStatus.loaded));
} catch (e) {
emit(state.copyWith(
status: PersonalInfoStatus.error,
errorMessage: e.toString(),
));
}
) {
// TODO: Implement Google Places logic if needed
}
/// With _onPhotoUploadRequested and _onSaveRequested removed or renamed,
/// there are no errors pointing to them here.
@override
void dispose() {
close();

View File

@@ -14,11 +14,11 @@ class PersonalInfoLoadRequested extends PersonalInfoEvent {
}
/// Event to update a field value.
class PersonalInfoFieldUpdated extends PersonalInfoEvent {
class PersonalInfoFieldChanged extends PersonalInfoEvent {
final String field;
final dynamic value;
const PersonalInfoFieldUpdated({
const PersonalInfoFieldChanged({
required this.field,
required this.value,
});
@@ -27,17 +27,16 @@ class PersonalInfoFieldUpdated extends PersonalInfoEvent {
List<Object?> get props => [field, value];
}
/// Event to save personal information.
class PersonalInfoSaveRequested extends PersonalInfoEvent {
const PersonalInfoSaveRequested();
/// Event to submit the form.
class PersonalInfoFormSubmitted extends PersonalInfoEvent {
const PersonalInfoFormSubmitted();
}
/// Event to upload a profile photo.
class PersonalInfoPhotoUploadRequested extends PersonalInfoEvent {
final String filePath;
const PersonalInfoPhotoUploadRequested({required this.filePath});
/// Event when an address is selected from autocomplete.
class PersonalInfoAddressSelected extends PersonalInfoEvent {
final String address;
const PersonalInfoAddressSelected(this.address);
@override
List<Object?> get props => [filePath];
List<Object?> get props => [address];
}

View File

@@ -49,6 +49,13 @@ class PersonalInfoState extends Equatable {
this.errorMessage,
});
/// Initial state.
const PersonalInfoState.initial()
: status = PersonalInfoStatus.initial,
staff = null,
formValues = const {},
errorMessage = null;
/// Creates a copy of this state with the given fields replaced.
PersonalInfoState copyWith({
PersonalInfoStatus? status,

View File

@@ -26,8 +26,7 @@ class PersonalInfoPage extends StatelessWidget {
Widget build(BuildContext context) {
final TranslationsStaffOnboardingPersonalInfoEn i18n = t.staff.onboarding.personal_info;
return BlocProvider<PersonalInfoBloc>(
create: (BuildContext context) => Modular.get<PersonalInfoBloc>()
..add(const PersonalInfoLoadRequested()),
create: (BuildContext context) => Modular.get<PersonalInfoBloc>(),
child: BlocListener<PersonalInfoBloc, PersonalInfoState>(
listener: (BuildContext context, PersonalInfoState state) {
if (state.status == PersonalInfoStatus.saved) {

View File

@@ -56,7 +56,7 @@ class _PersonalInfoContentState extends State<PersonalInfoContent> {
void _onPhoneChanged() {
context.read<PersonalInfoBloc>().add(
PersonalInfoFieldUpdated(
PersonalInfoFieldChanged(
field: 'phone',
value: _phoneController.text,
),
@@ -73,7 +73,7 @@ class _PersonalInfoContentState extends State<PersonalInfoContent> {
.toList();
context.read<PersonalInfoBloc>().add(
PersonalInfoFieldUpdated(
PersonalInfoFieldChanged(
field: 'preferredLocations',
value: locations,
),
@@ -81,7 +81,7 @@ class _PersonalInfoContentState extends State<PersonalInfoContent> {
}
void _handleSave() {
context.read<PersonalInfoBloc>().add(const PersonalInfoSaveRequested());
context.read<PersonalInfoBloc>().add(const PersonalInfoFormSubmitted());
}
void _handlePhotoTap() {