From 7875506e869a2eb4da99db5f51cb4a23ffa9efdc Mon Sep 17 00:00:00 2001 From: Achintha Isuru Date: Fri, 27 Feb 2026 14:01:08 -0500 Subject: [PATCH] feat: Dynamically determine document verification type based on document description and add widget mounted checks for safety. --- .../documents_repository_impl.dart | 23 +++++++++++++++++-- .../pages/document_upload_page.dart | 8 +++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/apps/mobile/packages/features/staff/profile_sections/compliance/documents/lib/src/data/repositories_impl/documents_repository_impl.dart b/apps/mobile/packages/features/staff/profile_sections/compliance/documents/lib/src/data/repositories_impl/documents_repository_impl.dart index c32e3e88..de03b8aa 100644 --- a/apps/mobile/packages/features/staff/profile_sections/compliance/documents/lib/src/data/repositories_impl/documents_repository_impl.dart +++ b/apps/mobile/packages/features/staff/profile_sections/compliance/documents/lib/src/data/repositories_impl/documents_repository_impl.dart @@ -44,13 +44,32 @@ class DocumentsRepositoryImpl implements DocumentsRepository { .createSignedUrl(fileUri: uploadRes.fileUri); // 3. Initiate verification + final List 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: { + 'documentDescription': currentDoc.description, + }, ); // 4. Update/Create StaffDocument in Data Connect diff --git a/apps/mobile/packages/features/staff/profile_sections/compliance/documents/lib/src/presentation/pages/document_upload_page.dart b/apps/mobile/packages/features/staff/profile_sections/compliance/documents/lib/src/presentation/pages/document_upload_page.dart index e53c33f6..6d962b99 100644 --- a/apps/mobile/packages/features/staff/profile_sections/compliance/documents/lib/src/presentation/pages/document_upload_page.dart +++ b/apps/mobile/packages/features/staff/profile_sections/compliance/documents/lib/src/presentation/pages/document_upload_page.dart @@ -46,9 +46,13 @@ class _DocumentUploadPageState extends State { allowedExtensions: ['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 { BlocProvider.of( context, ).uploadDocument( - widget.document.id, + widget.document.documentId, _selectedFilePath!, ); },