feat: Refactor document upload flow to support selected file path management
This commit is contained in:
@@ -50,21 +50,11 @@ class DocumentsRepositoryImpl implements DocumentsRepository {
|
|||||||
);
|
);
|
||||||
final String description = (currentDoc.description ?? '').toLowerCase();
|
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: verificationType,
|
type: 'government_id',
|
||||||
subjectType: 'worker',
|
subjectType: 'worker',
|
||||||
subjectId: staffId,
|
subjectId: staffId,
|
||||||
rules: <String, dynamic>{
|
rules: <String, dynamic>{
|
||||||
@@ -75,7 +65,7 @@ class DocumentsRepositoryImpl implements DocumentsRepository {
|
|||||||
// 4. Update/Create StaffDocument in Data Connect
|
// 4. Update/Create StaffDocument in Data Connect
|
||||||
await _service.getStaffRepository().upsertStaffDocument(
|
await _service.getStaffRepository().upsertStaffDocument(
|
||||||
documentId: documentId,
|
documentId: documentId,
|
||||||
documentUrl: uploadRes.fileUri,
|
documentUrl: signedUrlRes.signedUrl,
|
||||||
status: domain.DocumentStatus.pending,
|
status: domain.DocumentStatus.pending,
|
||||||
verificationId: verificationRes.verificationId,
|
verificationId: verificationRes.verificationId,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ class DocumentUploadCubit extends Cubit<DocumentUploadState> {
|
|||||||
emit(state.copyWith(isAttested: value));
|
emit(state.copyWith(isAttested: value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the selected file path for the document.
|
||||||
|
void setSelectedFilePath(String filePath) {
|
||||||
|
emit(state.copyWith(selectedFilePath: filePath));
|
||||||
|
}
|
||||||
|
|
||||||
/// Uploads the selected document if the user has attested.
|
/// Uploads the selected document if the user has attested.
|
||||||
///
|
///
|
||||||
/// Requires [state.isAttested] to be true before proceeding.
|
/// Requires [state.isAttested] to be true before proceeding.
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ class DocumentUploadState extends Equatable {
|
|||||||
const DocumentUploadState({
|
const DocumentUploadState({
|
||||||
this.status = DocumentUploadStatus.initial,
|
this.status = DocumentUploadStatus.initial,
|
||||||
this.isAttested = false,
|
this.isAttested = false,
|
||||||
|
this.selectedFilePath,
|
||||||
this.documentUrl,
|
this.documentUrl,
|
||||||
this.updatedDocument,
|
this.updatedDocument,
|
||||||
this.errorMessage,
|
this.errorMessage,
|
||||||
@@ -14,6 +15,7 @@ class DocumentUploadState extends Equatable {
|
|||||||
|
|
||||||
final DocumentUploadStatus status;
|
final DocumentUploadStatus status;
|
||||||
final bool isAttested;
|
final bool isAttested;
|
||||||
|
final String? selectedFilePath;
|
||||||
final String? documentUrl;
|
final String? documentUrl;
|
||||||
final StaffDocument? updatedDocument;
|
final StaffDocument? updatedDocument;
|
||||||
final String? errorMessage;
|
final String? errorMessage;
|
||||||
@@ -21,6 +23,7 @@ class DocumentUploadState extends Equatable {
|
|||||||
DocumentUploadState copyWith({
|
DocumentUploadState copyWith({
|
||||||
DocumentUploadStatus? status,
|
DocumentUploadStatus? status,
|
||||||
bool? isAttested,
|
bool? isAttested,
|
||||||
|
String? selectedFilePath,
|
||||||
String? documentUrl,
|
String? documentUrl,
|
||||||
StaffDocument? updatedDocument,
|
StaffDocument? updatedDocument,
|
||||||
String? errorMessage,
|
String? errorMessage,
|
||||||
@@ -28,6 +31,7 @@ class DocumentUploadState extends Equatable {
|
|||||||
return DocumentUploadState(
|
return DocumentUploadState(
|
||||||
status: status ?? this.status,
|
status: status ?? this.status,
|
||||||
isAttested: isAttested ?? this.isAttested,
|
isAttested: isAttested ?? this.isAttested,
|
||||||
|
selectedFilePath: selectedFilePath ?? this.selectedFilePath,
|
||||||
documentUrl: documentUrl ?? this.documentUrl,
|
documentUrl: documentUrl ?? this.documentUrl,
|
||||||
updatedDocument: updatedDocument ?? this.updatedDocument,
|
updatedDocument: updatedDocument ?? this.updatedDocument,
|
||||||
errorMessage: errorMessage ?? this.errorMessage,
|
errorMessage: errorMessage ?? this.errorMessage,
|
||||||
@@ -38,6 +42,7 @@ class DocumentUploadState extends Equatable {
|
|||||||
List<Object?> get props => <Object?>[
|
List<Object?> get props => <Object?>[
|
||||||
status,
|
status,
|
||||||
isAttested,
|
isAttested,
|
||||||
|
selectedFilePath,
|
||||||
documentUrl,
|
documentUrl,
|
||||||
updatedDocument,
|
updatedDocument,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import '../widgets/document_upload/pdf_file_types_banner.dart';
|
|||||||
///
|
///
|
||||||
/// Mirrors the pattern used in [AttireCapturePage] for a consistent upload flow:
|
/// Mirrors the pattern used in [AttireCapturePage] for a consistent upload flow:
|
||||||
/// file selection → attestation → submit → poll for result.
|
/// file selection → attestation → submit → poll for result.
|
||||||
class DocumentUploadPage extends StatefulWidget {
|
class DocumentUploadPage extends StatelessWidget {
|
||||||
const DocumentUploadPage({
|
const DocumentUploadPage({
|
||||||
super.key,
|
super.key,
|
||||||
required this.document,
|
required this.document,
|
||||||
@@ -30,20 +30,17 @@ class DocumentUploadPage extends StatefulWidget {
|
|||||||
/// Optional URL of an already-uploaded document.
|
/// Optional URL of an already-uploaded document.
|
||||||
final String? initialUrl;
|
final String? initialUrl;
|
||||||
|
|
||||||
@override
|
|
||||||
State<DocumentUploadPage> createState() => _DocumentUploadPageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _DocumentUploadPageState extends State<DocumentUploadPage> {
|
|
||||||
String? _selectedFilePath;
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (widget.initialUrl != null) {
|
|
||||||
_selectedFilePath = widget.initialUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return BlocProvider<DocumentUploadCubit>(
|
return BlocProvider<DocumentUploadCubit>(
|
||||||
create: (BuildContext _) => Modular.get<DocumentUploadCubit>(),
|
create: (BuildContext _) {
|
||||||
|
final DocumentUploadCubit cubit =
|
||||||
|
Modular.get<DocumentUploadCubit>();
|
||||||
|
if (initialUrl != null) {
|
||||||
|
cubit.setSelectedFilePath(initialUrl!);
|
||||||
|
}
|
||||||
|
return cubit;
|
||||||
|
},
|
||||||
child: BlocConsumer<DocumentUploadCubit, DocumentUploadState>(
|
child: BlocConsumer<DocumentUploadCubit, DocumentUploadState>(
|
||||||
listener: (BuildContext context, DocumentUploadState state) {
|
listener: (BuildContext context, DocumentUploadState state) {
|
||||||
if (state.status == DocumentUploadStatus.success) {
|
if (state.status == DocumentUploadStatus.success) {
|
||||||
@@ -64,8 +61,8 @@ class _DocumentUploadPageState extends State<DocumentUploadPage> {
|
|||||||
builder: (BuildContext context, DocumentUploadState state) {
|
builder: (BuildContext context, DocumentUploadState state) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: UiAppBar(
|
appBar: UiAppBar(
|
||||||
title: widget.document.name,
|
title: document.name,
|
||||||
subtitle: widget.document.description,
|
subtitle: document.description,
|
||||||
onLeadingPressed: () => Modular.to.toDocuments(),
|
onLeadingPressed: () => Modular.to.toDocuments(),
|
||||||
),
|
),
|
||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
@@ -78,11 +75,10 @@ class _DocumentUploadPageState extends State<DocumentUploadPage> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: UiConstants.space6),
|
const SizedBox(height: UiConstants.space6),
|
||||||
DocumentFileSelector(
|
DocumentFileSelector(
|
||||||
selectedFilePath: _selectedFilePath,
|
selectedFilePath: state.selectedFilePath,
|
||||||
onFileSelected: (String path) {
|
onFileSelected: (String path) {
|
||||||
setState(() {
|
BlocProvider.of<DocumentUploadCubit>(context)
|
||||||
_selectedFilePath = path;
|
.setSelectedFilePath(path);
|
||||||
});
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -109,14 +105,12 @@ class _DocumentUploadPageState extends State<DocumentUploadPage> {
|
|||||||
DocumentUploadFooter(
|
DocumentUploadFooter(
|
||||||
isUploading:
|
isUploading:
|
||||||
state.status == DocumentUploadStatus.uploading,
|
state.status == DocumentUploadStatus.uploading,
|
||||||
canSubmit: _selectedFilePath != null && state.isAttested,
|
canSubmit: state.selectedFilePath != null && state.isAttested,
|
||||||
onSubmit: () {
|
onSubmit: () {
|
||||||
|
BlocProvider.of<DocumentUploadCubit>(context)
|
||||||
BlocProvider.of<DocumentUploadCubit>(
|
.uploadDocument(
|
||||||
context,
|
document.documentId,
|
||||||
).uploadDocument(
|
state.selectedFilePath!,
|
||||||
widget.document.documentId,
|
|
||||||
_selectedFilePath!,
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user