feat: Dynamically determine document verification type based on document description and add widget mounted checks for safety.

This commit is contained in:
Achintha Isuru
2026-02-27 14:01:08 -05:00
parent 28cc0e3574
commit 7875506e86
2 changed files with 27 additions and 4 deletions

View File

@@ -44,13 +44,32 @@ class DocumentsRepositoryImpl implements DocumentsRepository {
.createSignedUrl(fileUri: uploadRes.fileUri);
// 3. Initiate verification
final List<domain.StaffDocument> allDocs = await getDocuments();
final domain.StaffDocument currentDoc = allDocs.firstWhere(
(domain.StaffDocument d) => d.documentId == documentId,
);
final String description = (currentDoc.description ?? '').toLowerCase();
String verificationType = 'government_id';
if (description.contains('permit')) {
verificationType = 'work_permit';
} else if (description.contains('passport')) {
verificationType = 'passport';
} else if (description.contains('ssn') ||
description.contains('social security')) {
verificationType = 'ssn';
}
final String staffId = await _service.getStaffId();
final VerificationResponse verificationRes = await _verificationService
.createVerification(
fileUri: uploadRes.fileUri,
type: documentId, // Assuming documentId aligns with type
subjectType: 'STAFF',
type: verificationType,
subjectType: 'worker',
subjectId: staffId,
rules: <String, dynamic>{
'documentDescription': currentDoc.description,
},
);
// 4. Update/Create StaffDocument in Data Connect

View File

@@ -46,9 +46,13 @@ class _DocumentUploadPageState extends State<DocumentUploadPage> {
allowedExtensions: <String>['pdf'],
);
if (!mounted) {
return;
}
if (path != null) {
final String? error = _validatePdfFile(context, path);
if (error != null && mounted) {
if (error != null) {
UiSnackbar.show(
context,
message: error,
@@ -164,7 +168,7 @@ class _DocumentUploadPageState extends State<DocumentUploadPage> {
BlocProvider.of<DocumentUploadCubit>(
context,
).uploadDocument(
widget.document.id,
widget.document.documentId,
_selectedFilePath!,
);
},