feat: update profile setup and bank account management; enhance API integration and data handling
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:krow_core/core.dart';
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
|
||||
@@ -20,18 +21,32 @@ class ProfileSetupRepositoryImpl implements ProfileSetupRepository {
|
||||
@override
|
||||
Future<void> submitProfile({
|
||||
required String fullName,
|
||||
required String phoneNumber,
|
||||
String? bio,
|
||||
required List<String> preferredLocations,
|
||||
required double maxDistanceMiles,
|
||||
required List<String> industries,
|
||||
required List<String> skills,
|
||||
}) async {
|
||||
// Convert location label strings to the object shape the V2 API expects.
|
||||
// The backend zod schema requires: { label, city?, state?, ... }.
|
||||
final List<Map<String, String>> locationObjects = preferredLocations
|
||||
.map((String label) => <String, String>{'label': label})
|
||||
.toList();
|
||||
|
||||
// Resolve the phone number: prefer the explicit parameter, but fall back
|
||||
// to the Firebase Auth current user's phone if the caller passed empty.
|
||||
final String resolvedPhone = phoneNumber.isNotEmpty
|
||||
? phoneNumber
|
||||
: (FirebaseAuth.instance.currentUser?.phoneNumber ?? '');
|
||||
|
||||
final ApiResponse response = await _apiService.post(
|
||||
StaffEndpoints.profileSetup,
|
||||
data: <String, dynamic>{
|
||||
'fullName': fullName,
|
||||
'phoneNumber': resolvedPhone,
|
||||
if (bio != null && bio.isNotEmpty) 'bio': bio,
|
||||
'preferredLocations': preferredLocations,
|
||||
'preferredLocations': locationObjects,
|
||||
'maxDistanceMiles': maxDistanceMiles.toInt(),
|
||||
'industries': industries,
|
||||
'skills': skills,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
|
||||
/// Interface for the staff profile setup repository.
|
||||
abstract class ProfileSetupRepository {
|
||||
/// Submits the staff profile setup data to the backend.
|
||||
Future<void> submitProfile({
|
||||
required String fullName,
|
||||
required String phoneNumber,
|
||||
String? bio,
|
||||
required List<String> preferredLocations,
|
||||
required double maxDistanceMiles,
|
||||
|
||||
@@ -13,6 +13,7 @@ class SubmitProfileSetup {
|
||||
/// Submits the profile setup with the given data.
|
||||
Future<void> call({
|
||||
required String fullName,
|
||||
required String phoneNumber,
|
||||
String? bio,
|
||||
required List<String> preferredLocations,
|
||||
required double maxDistanceMiles,
|
||||
@@ -21,6 +22,7 @@ class SubmitProfileSetup {
|
||||
}) {
|
||||
return repository.submitProfile(
|
||||
fullName: fullName,
|
||||
phoneNumber: phoneNumber,
|
||||
bio: bio,
|
||||
preferredLocations: preferredLocations,
|
||||
maxDistanceMiles: maxDistanceMiles,
|
||||
|
||||
@@ -12,11 +12,16 @@ export 'package:staff_authentication/src/presentation/blocs/profile_setup/profil
|
||||
class ProfileSetupBloc extends Bloc<ProfileSetupEvent, ProfileSetupState>
|
||||
with BlocErrorHandler<ProfileSetupState> {
|
||||
/// Creates a [ProfileSetupBloc].
|
||||
///
|
||||
/// [phoneNumber] is the authenticated user's phone from the sign-up flow,
|
||||
/// required by the V2 profile-setup endpoint.
|
||||
ProfileSetupBloc({
|
||||
required SubmitProfileSetup submitProfileSetup,
|
||||
required SearchCitiesUseCase searchCities,
|
||||
required String phoneNumber,
|
||||
}) : _submitProfileSetup = submitProfileSetup,
|
||||
_searchCities = searchCities,
|
||||
_phoneNumber = phoneNumber,
|
||||
super(const ProfileSetupState()) {
|
||||
on<ProfileSetupFullNameChanged>(_onFullNameChanged);
|
||||
on<ProfileSetupBioChanged>(_onBioChanged);
|
||||
@@ -35,6 +40,9 @@ class ProfileSetupBloc extends Bloc<ProfileSetupEvent, ProfileSetupState>
|
||||
/// The use case for searching cities.
|
||||
final SearchCitiesUseCase _searchCities;
|
||||
|
||||
/// The user's phone number from the sign-up flow.
|
||||
final String _phoneNumber;
|
||||
|
||||
/// Handles the [ProfileSetupFullNameChanged] event.
|
||||
void _onFullNameChanged(
|
||||
ProfileSetupFullNameChanged event,
|
||||
@@ -95,6 +103,7 @@ class ProfileSetupBloc extends Bloc<ProfileSetupEvent, ProfileSetupState>
|
||||
action: () async {
|
||||
await _submitProfileSetup(
|
||||
fullName: state.fullName,
|
||||
phoneNumber: _phoneNumber,
|
||||
bio: state.bio.isEmpty ? null : state.bio,
|
||||
preferredLocations: state.preferredLocations,
|
||||
maxDistanceMiles: state.maxDistanceMiles,
|
||||
|
||||
@@ -56,6 +56,7 @@ class StaffAuthenticationModule extends Module {
|
||||
() => ProfileSetupBloc(
|
||||
submitProfileSetup: i.get<SubmitProfileSetup>(),
|
||||
searchCities: i.get<SearchCitiesUseCase>(),
|
||||
phoneNumber: i.get<AuthBloc>().state.phoneNumber,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user