feat: update preferredLocations field to List<String> across staff-related entities and mutations
- Changed preferredLocations from AnyValue to List<String> in GetStaffByIdStaff, GetStaffByUserIdStaffs, ListStaffStaffs, and UpdateStaffVariablesBuilder classes. - Updated JSON serialization/deserialization for preferredLocations to handle List<String>. - Modified Staff entity to include preferredLocations as List<String>. - Adjusted ProfileSetupBloc and PersonalInfoBloc to accommodate changes in preferredLocations. - Updated PersonalInfoRepositoryImpl to handle preferredLocations as List<String>. - Refactored PersonalInfoContent and PersonalInfoForm to use locations instead of address. - Updated GraphQL mutations and schema to reflect the new List<String> type for preferredLocations.
This commit is contained in:
committed by
José Salazar
parent
c041796b38
commit
f345e715ad
@@ -102,7 +102,7 @@ class ProfileSetupBloc extends Bloc<ProfileSetupEvent, ProfileSetupState> {
|
||||
fullName: state.fullName,
|
||||
)
|
||||
.bio(state.bio.isEmpty ? null : state.bio)
|
||||
.preferredLocations(fdc.AnyValue(state.preferredLocations))
|
||||
.preferredLocations(state.preferredLocations)
|
||||
.maxDistanceMiles(state.maxDistanceMiles.toInt())
|
||||
.industries(fdc.AnyValue(state.industries))
|
||||
.skills(fdc.AnyValue(state.skills))
|
||||
|
||||
@@ -65,7 +65,10 @@ class PersonalInfoRepositoryImpl implements PersonalInfoRepositoryInterface {
|
||||
if (data.containsKey('avatar')) {
|
||||
updateBuilder = updateBuilder.photoUrl(data['avatar'] as String?);
|
||||
}
|
||||
// Add other fields as they become available in the schema and map
|
||||
if (data.containsKey('preferredLocations')) {
|
||||
// After schema update and SDK regeneration, preferredLocations accepts List<String>
|
||||
updateBuilder = updateBuilder.preferredLocations(data['preferredLocations'] as List<String>);
|
||||
}
|
||||
|
||||
// Execute the update
|
||||
final OperationResult<UpdateStaffData, UpdateStaffVariables> result =
|
||||
@@ -107,6 +110,8 @@ class PersonalInfoRepositoryImpl implements PersonalInfoRepositoryInterface {
|
||||
noShowCount: dto.noShowCount,
|
||||
cancellationCount: dto.cancellationCount,
|
||||
reliabilityScore: dto.reliabilityScore,
|
||||
// After schema update and SDK regeneration, preferredLocations is List<String>?
|
||||
preferredLocations: dto.preferredLocations,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,11 +42,14 @@ class PersonalInfoBloc extends Bloc<PersonalInfoEvent, PersonalInfoState>
|
||||
final Staff staff = await _getPersonalInfoUseCase();
|
||||
|
||||
// Initialize form values from staff entity
|
||||
// Note: Staff entity currently stores address as a string, but we want to map it to 'preferredLocations'
|
||||
final Map<String, dynamic> initialValues = {
|
||||
'name': staff.name,
|
||||
'email': staff.email,
|
||||
'phone': staff.phone,
|
||||
'address': staff.address,
|
||||
'preferredLocations': staff.address != null
|
||||
? [staff.address]
|
||||
: [], // TODO: Map correctly when Staff entity supports list
|
||||
'avatar': staff.avatar,
|
||||
};
|
||||
|
||||
@@ -94,7 +97,9 @@ class PersonalInfoBloc extends Bloc<PersonalInfoEvent, PersonalInfoState>
|
||||
'name': updatedStaff.name,
|
||||
'email': updatedStaff.email,
|
||||
'phone': updatedStaff.phone,
|
||||
'address': updatedStaff.address,
|
||||
'preferredLocations': updatedStaff.address != null
|
||||
? [updatedStaff.address]
|
||||
: [],
|
||||
'avatar': updatedStaff.avatar,
|
||||
};
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class PersonalInfoLoadRequested extends PersonalInfoEvent {
|
||||
/// Event to update a field value.
|
||||
class PersonalInfoFieldUpdated extends PersonalInfoEvent {
|
||||
final String field;
|
||||
final String value;
|
||||
final dynamic value;
|
||||
|
||||
const PersonalInfoFieldUpdated({
|
||||
required this.field,
|
||||
|
||||
@@ -33,23 +33,23 @@ class PersonalInfoContent extends StatefulWidget {
|
||||
|
||||
class _PersonalInfoContentState extends State<PersonalInfoContent> {
|
||||
late final TextEditingController _phoneController;
|
||||
late final TextEditingController _addressController;
|
||||
late final TextEditingController _locationsController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_phoneController = TextEditingController(text: widget.staff.phone ?? '');
|
||||
_addressController = TextEditingController(text: widget.staff.address ?? '');
|
||||
_locationsController = TextEditingController(text: widget.staff.preferredLocations?.join(', ')?? '');
|
||||
|
||||
// Listen to changes and update BLoC
|
||||
_phoneController.addListener(_onPhoneChanged);
|
||||
_addressController.addListener(_onAddressChanged);
|
||||
_locationsController.addListener(_onAddressChanged);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_phoneController.dispose();
|
||||
_addressController.dispose();
|
||||
_locationsController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -64,10 +64,18 @@ class _PersonalInfoContentState extends State<PersonalInfoContent> {
|
||||
}
|
||||
|
||||
void _onAddressChanged() {
|
||||
// Split the comma-separated string into a list for storage
|
||||
// The backend expects List<AnyValue> (JSON/List) for preferredLocations
|
||||
final List<String> locations = _locationsController.text
|
||||
.split(',')
|
||||
.map((e) => e.trim())
|
||||
.where((e) => e.isNotEmpty)
|
||||
.toList();
|
||||
|
||||
context.read<PersonalInfoBloc>().add(
|
||||
PersonalInfoFieldUpdated(
|
||||
field: 'address',
|
||||
value: _addressController.text,
|
||||
field: 'preferredLocations',
|
||||
value: locations,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -107,7 +115,7 @@ class _PersonalInfoContentState extends State<PersonalInfoContent> {
|
||||
fullName: widget.staff.name,
|
||||
email: widget.staff.email,
|
||||
phoneController: _phoneController,
|
||||
addressController: _addressController,
|
||||
locationsController: _locationsController,
|
||||
enabled: !isSaving,
|
||||
),
|
||||
const SizedBox(height: UiConstants.space16), // Space for bottom button
|
||||
|
||||
@@ -19,7 +19,7 @@ class PersonalInfoForm extends StatelessWidget {
|
||||
final TextEditingController phoneController;
|
||||
|
||||
/// Controller for the address field.
|
||||
final TextEditingController addressController;
|
||||
final TextEditingController locationsController;
|
||||
|
||||
/// Whether the form fields are enabled for editing.
|
||||
final bool enabled;
|
||||
@@ -30,7 +30,7 @@ class PersonalInfoForm extends StatelessWidget {
|
||||
required this.fullName,
|
||||
required this.email,
|
||||
required this.phoneController,
|
||||
required this.addressController,
|
||||
required this.locationsController,
|
||||
this.enabled = true,
|
||||
});
|
||||
|
||||
@@ -63,7 +63,7 @@ class PersonalInfoForm extends StatelessWidget {
|
||||
_FieldLabel(text: i18n.locations_label),
|
||||
const SizedBox(height: UiConstants.space2),
|
||||
_EditableField(
|
||||
controller: addressController,
|
||||
controller: locationsController,
|
||||
hint: i18n.locations_hint,
|
||||
enabled: enabled,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user