feat: Improve document verification and rejection loading states; update permission checks for button visibility

This commit is contained in:
Vaibhav Surve 2025-09-11 19:07:56 +05:30
parent 5c923bb48b
commit be908a5251
2 changed files with 24 additions and 19 deletions

View File

@ -11,17 +11,16 @@ class DocumentDetailsController extends GetxController {
var versions = <DocumentVersionItem>[].obs; var versions = <DocumentVersionItem>[].obs;
var isVersionsLoading = false.obs; var isVersionsLoading = false.obs;
// Loading states for buttons
var isVerifyLoading = false.obs;
var isRejectLoading = false.obs;
/// Fetch document details by id /// Fetch document details by id
Future<void> fetchDocumentDetails(String documentId) async { Future<void> fetchDocumentDetails(String documentId) async {
try { try {
isLoading.value = true; isLoading.value = true;
final response = await ApiService.getDocumentDetailsApi(documentId); final response = await ApiService.getDocumentDetailsApi(documentId);
documentDetails.value = response;
if (response != null) {
documentDetails.value = response;
} else {
documentDetails.value = null;
}
} finally { } finally {
isLoading.value = false; isLoading.value = false;
} }
@ -34,7 +33,6 @@ class DocumentDetailsController extends GetxController {
final response = await ApiService.getDocumentVersionsApi( final response = await ApiService.getDocumentVersionsApi(
parentAttachmentId: parentAttachmentId, parentAttachmentId: parentAttachmentId,
); );
if (response != null) { if (response != null) {
versions.assignAll(response.data.data); versions.assignAll(response.data.data);
} else { } else {
@ -47,22 +45,28 @@ class DocumentDetailsController extends GetxController {
/// Verify document /// Verify document
Future<bool> verifyDocument(String documentId) async { Future<bool> verifyDocument(String documentId) async {
final result = try {
await ApiService.verifyDocumentApi(id: documentId, isVerify: true); isVerifyLoading.value = true;
if (result) { final result =
await fetchDocumentDetails(documentId); // refresh details await ApiService.verifyDocumentApi(id: documentId, isVerify: true);
if (result) await fetchDocumentDetails(documentId);
return result;
} finally {
isVerifyLoading.value = false;
} }
return result;
} }
/// Reject document /// Reject document
Future<bool> rejectDocument(String documentId) async { Future<bool> rejectDocument(String documentId) async {
final result = try {
await ApiService.verifyDocumentApi(id: documentId, isVerify: false); isRejectLoading.value = true;
if (result) { final result =
await fetchDocumentDetails(documentId); // refresh details await ApiService.verifyDocumentApi(id: documentId, isVerify: false);
if (result) await fetchDocumentDetails(documentId);
return result;
} finally {
isRejectLoading.value = false;
} }
return result;
} }
/// Fetch Pre-Signed URL for a given version /// Fetch Pre-Signed URL for a given version

View File

@ -230,8 +230,9 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
if (doc.updatedAt != null) if (doc.updatedAt != null)
_buildDetailRow("Last Updated On", updateDate), _buildDetailRow("Last Updated On", updateDate),
MySpacing.height(12), MySpacing.height(12),
if (permissionController // Show buttons only if user has permission AND document is not verified yet
.hasPermission(Permissions.verifyDocument)) ...[ if (permissionController.hasPermission(Permissions.verifyDocument) &&
doc.isVerified == null) ...[
Row( Row(
children: [ children: [
Expanded( Expanded(