feat: Enhance attire verification status system with more granular states and update related UI and data handling.
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
// 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, implementation_imports
|
||||
import 'package:firebase_data_connect/firebase_data_connect.dart';
|
||||
import 'package:krow_data_connect/krow_data_connect.dart'
|
||||
hide AttireVerificationStatus;
|
||||
import 'package:krow_domain/krow_domain.dart';
|
||||
import 'package:firebase_data_connect/firebase_data_connect.dart';
|
||||
import 'package:krow_data_connect/krow_data_connect.dart' as dc;
|
||||
import 'package:krow_domain/krow_domain.dart' as domain;
|
||||
import '../../domain/repositories/staff_connector_repository.dart';
|
||||
|
||||
/// Implementation of [StaffConnectorRepository].
|
||||
///
|
||||
@@ -12,10 +11,10 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
||||
/// Creates a new [StaffConnectorRepositoryImpl].
|
||||
///
|
||||
/// Requires a [DataConnectService] instance for backend communication.
|
||||
StaffConnectorRepositoryImpl({DataConnectService? service})
|
||||
: _service = service ?? DataConnectService.instance;
|
||||
StaffConnectorRepositoryImpl({dc.DataConnectService? service})
|
||||
: _service = service ?? dc.DataConnectService.instance;
|
||||
|
||||
final DataConnectService _service;
|
||||
final dc.DataConnectService _service;
|
||||
|
||||
@override
|
||||
Future<bool> getProfileCompletion() async {
|
||||
@@ -23,17 +22,17 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
final QueryResult<
|
||||
GetStaffProfileCompletionData,
|
||||
GetStaffProfileCompletionVariables
|
||||
dc.GetStaffProfileCompletionData,
|
||||
dc.GetStaffProfileCompletionVariables
|
||||
>
|
||||
response = await _service.connector
|
||||
.getStaffProfileCompletion(id: staffId)
|
||||
.execute();
|
||||
|
||||
final GetStaffProfileCompletionStaff? staff = response.data.staff;
|
||||
final List<GetStaffProfileCompletionEmergencyContacts> emergencyContacts =
|
||||
response.data.emergencyContacts;
|
||||
final List<GetStaffProfileCompletionTaxForms> taxForms =
|
||||
final dc.GetStaffProfileCompletionStaff? staff = response.data.staff;
|
||||
final List<dc.GetStaffProfileCompletionEmergencyContacts>
|
||||
emergencyContacts = response.data.emergencyContacts;
|
||||
final List<dc.GetStaffProfileCompletionTaxForms> taxForms =
|
||||
response.data.taxForms;
|
||||
|
||||
return _isProfileComplete(staff, emergencyContacts, taxForms);
|
||||
@@ -46,15 +45,14 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
final QueryResult<
|
||||
GetStaffPersonalInfoCompletionData,
|
||||
GetStaffPersonalInfoCompletionVariables
|
||||
dc.GetStaffPersonalInfoCompletionData,
|
||||
dc.GetStaffPersonalInfoCompletionVariables
|
||||
>
|
||||
response = await _service.connector
|
||||
.getStaffPersonalInfoCompletion(id: staffId)
|
||||
.execute();
|
||||
|
||||
final GetStaffPersonalInfoCompletionStaff? staff = response.data.staff;
|
||||
|
||||
final dc.GetStaffPersonalInfoCompletionStaff? staff = response.data.staff;
|
||||
return _isPersonalInfoComplete(staff);
|
||||
});
|
||||
}
|
||||
@@ -65,8 +63,8 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
final QueryResult<
|
||||
GetStaffEmergencyProfileCompletionData,
|
||||
GetStaffEmergencyProfileCompletionVariables
|
||||
dc.GetStaffEmergencyProfileCompletionData,
|
||||
dc.GetStaffEmergencyProfileCompletionVariables
|
||||
>
|
||||
response = await _service.connector
|
||||
.getStaffEmergencyProfileCompletion(id: staffId)
|
||||
@@ -82,16 +80,15 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
final QueryResult<
|
||||
GetStaffExperienceProfileCompletionData,
|
||||
GetStaffExperienceProfileCompletionVariables
|
||||
dc.GetStaffExperienceProfileCompletionData,
|
||||
dc.GetStaffExperienceProfileCompletionVariables
|
||||
>
|
||||
response = await _service.connector
|
||||
.getStaffExperienceProfileCompletion(id: staffId)
|
||||
.execute();
|
||||
|
||||
final GetStaffExperienceProfileCompletionStaff? staff =
|
||||
final dc.GetStaffExperienceProfileCompletionStaff? staff =
|
||||
response.data.staff;
|
||||
|
||||
return _hasExperience(staff);
|
||||
});
|
||||
}
|
||||
@@ -102,8 +99,8 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
final QueryResult<
|
||||
GetStaffTaxFormsProfileCompletionData,
|
||||
GetStaffTaxFormsProfileCompletionVariables
|
||||
dc.GetStaffTaxFormsProfileCompletionData,
|
||||
dc.GetStaffTaxFormsProfileCompletionVariables
|
||||
>
|
||||
response = await _service.connector
|
||||
.getStaffTaxFormsProfileCompletion(id: staffId)
|
||||
@@ -114,150 +111,162 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
||||
}
|
||||
|
||||
/// Checks if personal info is complete.
|
||||
bool _isPersonalInfoComplete(GetStaffPersonalInfoCompletionStaff? staff) {
|
||||
bool _isPersonalInfoComplete(dc.GetStaffPersonalInfoCompletionStaff? staff) {
|
||||
if (staff == null) return false;
|
||||
final String fullName = staff.fullName;
|
||||
final String? email = staff.email;
|
||||
final String? phone = staff.phone;
|
||||
return (fullName.trim().isNotEmpty ?? false) &&
|
||||
return fullName.trim().isNotEmpty &&
|
||||
(email?.trim().isNotEmpty ?? false) &&
|
||||
(phone?.trim().isNotEmpty ?? false);
|
||||
}
|
||||
|
||||
/// Checks if staff has experience data (skills or industries).
|
||||
bool _hasExperience(GetStaffExperienceProfileCompletionStaff? staff) {
|
||||
bool _hasExperience(dc.GetStaffExperienceProfileCompletionStaff? staff) {
|
||||
if (staff == null) return false;
|
||||
final dynamic skills = staff.skills;
|
||||
final dynamic industries = staff.industries;
|
||||
return (skills is List && skills.isNotEmpty) ||
|
||||
(industries is List && industries.isNotEmpty);
|
||||
final List<String>? skills = staff.skills;
|
||||
final List<String>? industries = staff.industries;
|
||||
return (skills?.isNotEmpty ?? false) || (industries?.isNotEmpty ?? false);
|
||||
}
|
||||
|
||||
/// Determines if the profile is complete based on all sections.
|
||||
bool _isProfileComplete(
|
||||
GetStaffProfileCompletionStaff? staff,
|
||||
List<GetStaffProfileCompletionEmergencyContacts> emergencyContacts,
|
||||
List<GetStaffProfileCompletionTaxForms> taxForms,
|
||||
dc.GetStaffProfileCompletionStaff? staff,
|
||||
List<dc.GetStaffProfileCompletionEmergencyContacts> emergencyContacts,
|
||||
List<dc.GetStaffProfileCompletionTaxForms> taxForms,
|
||||
) {
|
||||
if (staff == null) return false;
|
||||
final dynamic skills = staff.skills;
|
||||
final dynamic industries = staff.industries;
|
||||
|
||||
final List<String>? skills = staff.skills;
|
||||
final List<String>? industries = staff.industries;
|
||||
final bool hasExperience =
|
||||
(skills is List && skills.isNotEmpty) ||
|
||||
(industries is List && industries.isNotEmpty);
|
||||
return emergencyContacts.isNotEmpty && taxForms.isNotEmpty && hasExperience;
|
||||
(skills?.isNotEmpty ?? false) || (industries?.isNotEmpty ?? false);
|
||||
|
||||
return (staff.fullName.trim().isNotEmpty) &&
|
||||
(staff.email?.trim().isNotEmpty ?? false) &&
|
||||
emergencyContacts.isNotEmpty &&
|
||||
taxForms.isNotEmpty &&
|
||||
hasExperience;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Staff> getStaffProfile() async {
|
||||
Future<domain.Staff> getStaffProfile() async {
|
||||
return _service.run(() async {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
final QueryResult<GetStaffByIdData, GetStaffByIdVariables> response =
|
||||
await _service.connector.getStaffById(id: staffId).execute();
|
||||
final QueryResult<dc.GetStaffByIdData, dc.GetStaffByIdVariables>
|
||||
response = await _service.connector.getStaffById(id: staffId).execute();
|
||||
|
||||
if (response.data.staff == null) {
|
||||
throw const ServerException(technicalMessage: 'Staff not found');
|
||||
final dc.GetStaffByIdStaff? staff = response.data.staff;
|
||||
|
||||
if (staff == null) {
|
||||
throw Exception('Staff not found');
|
||||
}
|
||||
|
||||
final GetStaffByIdStaff rawStaff = response.data.staff!;
|
||||
|
||||
// Map the raw data connect object to the Domain Entity
|
||||
return Staff(
|
||||
id: rawStaff.id,
|
||||
authProviderId: rawStaff.userId,
|
||||
name: rawStaff.fullName,
|
||||
email: rawStaff.email ?? '',
|
||||
phone: rawStaff.phone,
|
||||
avatar: rawStaff.photoUrl,
|
||||
status: StaffStatus.active,
|
||||
address: rawStaff.addres,
|
||||
totalShifts: rawStaff.totalShifts,
|
||||
averageRating: rawStaff.averageRating,
|
||||
onTimeRate: rawStaff.onTimeRate,
|
||||
noShowCount: rawStaff.noShowCount,
|
||||
cancellationCount: rawStaff.cancellationCount,
|
||||
reliabilityScore: rawStaff.reliabilityScore,
|
||||
return domain.Staff(
|
||||
id: staff.id,
|
||||
authProviderId: staff.userId,
|
||||
name: staff.fullName,
|
||||
email: staff.email ?? '',
|
||||
phone: staff.phone,
|
||||
avatar: staff.photoUrl,
|
||||
status: domain.StaffStatus.active,
|
||||
address: staff.addres,
|
||||
totalShifts: staff.totalShifts,
|
||||
averageRating: staff.averageRating,
|
||||
onTimeRate: staff.onTimeRate,
|
||||
noShowCount: staff.noShowCount,
|
||||
cancellationCount: staff.cancellationCount,
|
||||
reliabilityScore: staff.reliabilityScore,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<Benefit>> getBenefits() async {
|
||||
Future<List<domain.Benefit>> getBenefits() async {
|
||||
return _service.run(() async {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
final QueryResult<
|
||||
ListBenefitsDataByStaffIdData,
|
||||
ListBenefitsDataByStaffIdVariables
|
||||
dc.ListBenefitsDataByStaffIdData,
|
||||
dc.ListBenefitsDataByStaffIdVariables
|
||||
>
|
||||
response = await _service.connector
|
||||
.listBenefitsDataByStaffId(staffId: staffId)
|
||||
.execute();
|
||||
|
||||
return response.data.benefitsDatas.map((data) {
|
||||
final plan = data.vendorBenefitPlan;
|
||||
return Benefit(
|
||||
title: plan.title,
|
||||
entitlementHours: plan.total?.toDouble() ?? 0.0,
|
||||
usedHours: data.current.toDouble(),
|
||||
);
|
||||
}).toList();
|
||||
return response.data.benefitsDatas
|
||||
.map(
|
||||
(dc.ListBenefitsDataByStaffIdBenefitsDatas e) => domain.Benefit(
|
||||
title: e.vendorBenefitPlan.title,
|
||||
entitlementHours: e.vendorBenefitPlan.total?.toDouble() ?? 0,
|
||||
usedHours: e.current.toDouble(),
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<AttireItem>> getAttireOptions() async {
|
||||
Future<List<domain.AttireItem>> getAttireOptions() async {
|
||||
return _service.run(() async {
|
||||
final String staffId = await _service.getStaffId();
|
||||
|
||||
// Fetch all options
|
||||
final QueryResult<ListAttireOptionsData, void> optionsResponse =
|
||||
await _service.connector.listAttireOptions().execute();
|
||||
final List<QueryResult<Object, Object?>> results =
|
||||
await Future.wait<QueryResult<Object, Object?>>(
|
||||
<Future<QueryResult<Object, Object?>>>[
|
||||
_service.connector.listAttireOptions().execute(),
|
||||
_service.connector.getStaffAttire(staffId: staffId).execute(),
|
||||
],
|
||||
);
|
||||
|
||||
// Fetch user's attire status
|
||||
final QueryResult<GetStaffAttireData, GetStaffAttireVariables>
|
||||
attiresResponse = await _service.connector
|
||||
.getStaffAttire(staffId: staffId)
|
||||
.execute();
|
||||
final QueryResult<dc.ListAttireOptionsData, void> optionsRes =
|
||||
results[0] as QueryResult<dc.ListAttireOptionsData, void>;
|
||||
final QueryResult<dc.GetStaffAttireData, dc.GetStaffAttireVariables>
|
||||
staffAttireRes =
|
||||
results[1]
|
||||
as QueryResult<dc.GetStaffAttireData, dc.GetStaffAttireVariables>;
|
||||
|
||||
final Map<String, GetStaffAttireStaffAttires> attireMap = {
|
||||
for (final item in attiresResponse.data.staffAttires)
|
||||
item.attireOptionId: item,
|
||||
};
|
||||
final List<dc.GetStaffAttireStaffAttires> staffAttire =
|
||||
staffAttireRes.data.staffAttires;
|
||||
|
||||
return optionsResponse.data.attireOptions.map((e) {
|
||||
final GetStaffAttireStaffAttires? userAttire = attireMap[e.id];
|
||||
return AttireItem(
|
||||
id: e.id,
|
||||
code: e.itemId,
|
||||
label: e.label,
|
||||
description: e.description,
|
||||
imageUrl: e.imageUrl,
|
||||
isMandatory: e.isMandatory ?? false,
|
||||
verificationStatus: _mapAttireStatus(
|
||||
userAttire?.verificationStatus?.stringValue,
|
||||
),
|
||||
photoUrl: userAttire?.verificationPhotoUrl,
|
||||
verificationId: userAttire?.verificationId,
|
||||
return optionsRes.data.attireOptions.map((
|
||||
dc.ListAttireOptionsAttireOptions opt,
|
||||
) {
|
||||
final dc.GetStaffAttireStaffAttires currentAttire = staffAttire
|
||||
.firstWhere(
|
||||
(dc.GetStaffAttireStaffAttires a) => a.attireOptionId == opt.id,
|
||||
orElse: () => dc.GetStaffAttireStaffAttires(
|
||||
attireOptionId: opt.id,
|
||||
verificationPhotoUrl: null,
|
||||
verificationId: null,
|
||||
verificationStatus: null,
|
||||
),
|
||||
);
|
||||
|
||||
return domain.AttireItem(
|
||||
id: opt.id,
|
||||
code: opt.itemId,
|
||||
label: opt.label,
|
||||
description: opt.description,
|
||||
imageUrl: opt.imageUrl,
|
||||
isMandatory: opt.isMandatory ?? false,
|
||||
photoUrl: currentAttire.verificationPhotoUrl,
|
||||
verificationId: currentAttire.verificationId,
|
||||
verificationStatus: currentAttire.verificationStatus != null
|
||||
? _mapFromDCStatus(currentAttire.verificationStatus!)
|
||||
: null,
|
||||
);
|
||||
}).toList();
|
||||
});
|
||||
}
|
||||
|
||||
AttireVerificationStatus? _mapAttireStatus(String? status) {
|
||||
if (status == null) return null;
|
||||
return AttireVerificationStatus.values.firstWhere(
|
||||
(e) => e.name.toUpperCase() == status.toUpperCase(),
|
||||
orElse: () => AttireVerificationStatus.pending,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> upsertStaffAttire({
|
||||
required String attireOptionId,
|
||||
required String photoUrl,
|
||||
String? verificationId,
|
||||
domain.AttireVerificationStatus? verificationStatus,
|
||||
}) async {
|
||||
await _service.run(() async {
|
||||
final String staffId = await _service.getStaffId();
|
||||
@@ -266,6 +275,67 @@ class StaffConnectorRepositoryImpl implements StaffConnectorRepository {
|
||||
.upsertStaffAttire(staffId: staffId, attireOptionId: attireOptionId)
|
||||
.verificationPhotoUrl(photoUrl)
|
||||
.verificationId(verificationId)
|
||||
.verificationStatus(
|
||||
verificationStatus != null
|
||||
? dc.AttireVerificationStatus.values.firstWhere(
|
||||
(dc.AttireVerificationStatus e) =>
|
||||
e.name == verificationStatus.value.toUpperCase(),
|
||||
orElse: () => dc.AttireVerificationStatus.PENDING,
|
||||
)
|
||||
: null,
|
||||
)
|
||||
.execute();
|
||||
});
|
||||
}
|
||||
|
||||
domain.AttireVerificationStatus _mapFromDCStatus(
|
||||
dc.EnumValue<dc.AttireVerificationStatus> status,
|
||||
) {
|
||||
if (status is dc.Unknown) {
|
||||
return domain.AttireVerificationStatus.error;
|
||||
}
|
||||
final String name =
|
||||
(status as dc.Known<dc.AttireVerificationStatus>).value.name;
|
||||
switch (name) {
|
||||
case 'PENDING':
|
||||
return domain.AttireVerificationStatus.pending;
|
||||
case 'PROCESSING':
|
||||
return domain.AttireVerificationStatus.processing;
|
||||
case 'AUTO_PASS':
|
||||
return domain.AttireVerificationStatus.autoPass;
|
||||
case 'AUTO_FAIL':
|
||||
return domain.AttireVerificationStatus.autoFail;
|
||||
case 'NEEDS_REVIEW':
|
||||
return domain.AttireVerificationStatus.needsReview;
|
||||
case 'APPROVED':
|
||||
return domain.AttireVerificationStatus.approved;
|
||||
case 'REJECTED':
|
||||
return domain.AttireVerificationStatus.rejected;
|
||||
case 'ERROR':
|
||||
return domain.AttireVerificationStatus.error;
|
||||
default:
|
||||
return domain.AttireVerificationStatus.error;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> saveStaffProfile({
|
||||
String? firstName,
|
||||
String? lastName,
|
||||
String? bio,
|
||||
String? profilePictureUrl,
|
||||
}) async {
|
||||
await _service.run(() async {
|
||||
final String staffId = await _service.getStaffId();
|
||||
final String? fullName = (firstName != null || lastName != null)
|
||||
? '${firstName ?? ''} ${lastName ?? ''}'.trim()
|
||||
: null;
|
||||
|
||||
await _service.connector
|
||||
.updateStaff(id: staffId)
|
||||
.fullName(fullName)
|
||||
.bio(bio)
|
||||
.photoUrl(profilePictureUrl)
|
||||
.execute();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ abstract interface class StaffConnectorRepository {
|
||||
required String attireOptionId,
|
||||
required String photoUrl,
|
||||
String? verificationId,
|
||||
AttireVerificationStatus? verificationStatus,
|
||||
});
|
||||
|
||||
/// Signs out the current user.
|
||||
@@ -63,4 +64,12 @@ abstract interface class StaffConnectorRepository {
|
||||
///
|
||||
/// Throws an exception if the sign-out fails.
|
||||
Future<void> signOut();
|
||||
|
||||
/// Saves the staff profile information.
|
||||
Future<void> saveStaffProfile({
|
||||
String? firstName,
|
||||
String? lastName,
|
||||
String? bio,
|
||||
String? profilePictureUrl,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user