feat: Dynamically determine document verification type based on document description and add widget mounted checks for safety.
This commit is contained in:
@@ -44,13 +44,32 @@ class DocumentsRepositoryImpl implements DocumentsRepository {
|
|||||||
.createSignedUrl(fileUri: uploadRes.fileUri);
|
.createSignedUrl(fileUri: uploadRes.fileUri);
|
||||||
|
|
||||||
// 3. Initiate verification
|
// 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 String staffId = await _service.getStaffId();
|
||||||
final VerificationResponse verificationRes = await _verificationService
|
final VerificationResponse verificationRes = await _verificationService
|
||||||
.createVerification(
|
.createVerification(
|
||||||
fileUri: uploadRes.fileUri,
|
fileUri: uploadRes.fileUri,
|
||||||
type: documentId, // Assuming documentId aligns with type
|
type: verificationType,
|
||||||
subjectType: 'STAFF',
|
subjectType: 'worker',
|
||||||
subjectId: staffId,
|
subjectId: staffId,
|
||||||
|
rules: <String, dynamic>{
|
||||||
|
'documentDescription': currentDoc.description,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// 4. Update/Create StaffDocument in Data Connect
|
// 4. Update/Create StaffDocument in Data Connect
|
||||||
|
|||||||
@@ -46,9 +46,13 @@ class _DocumentUploadPageState extends State<DocumentUploadPage> {
|
|||||||
allowedExtensions: <String>['pdf'],
|
allowedExtensions: <String>['pdf'],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!mounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
final String? error = _validatePdfFile(context, path);
|
final String? error = _validatePdfFile(context, path);
|
||||||
if (error != null && mounted) {
|
if (error != null) {
|
||||||
UiSnackbar.show(
|
UiSnackbar.show(
|
||||||
context,
|
context,
|
||||||
message: error,
|
message: error,
|
||||||
@@ -164,7 +168,7 @@ class _DocumentUploadPageState extends State<DocumentUploadPage> {
|
|||||||
BlocProvider.of<DocumentUploadCubit>(
|
BlocProvider.of<DocumentUploadCubit>(
|
||||||
context,
|
context,
|
||||||
).uploadDocument(
|
).uploadDocument(
|
||||||
widget.document.id,
|
widget.document.documentId,
|
||||||
_selectedFilePath!,
|
_selectedFilePath!,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user