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

View File

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