feat: Improve document verification and rejection loading states; update permission checks for button visibility
This commit is contained in:
parent
5c923bb48b
commit
be908a5251
@ -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;
|
||||
}
|
||||
documentDetails.value = response;
|
||||
} 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 {
|
||||
final result =
|
||||
await ApiService.verifyDocumentApi(id: documentId, isVerify: true);
|
||||
if (result) {
|
||||
await fetchDocumentDetails(documentId); // refresh details
|
||||
try {
|
||||
isVerifyLoading.value = true;
|
||||
final result =
|
||||
await ApiService.verifyDocumentApi(id: documentId, isVerify: true);
|
||||
if (result) await fetchDocumentDetails(documentId);
|
||||
return result;
|
||||
} finally {
|
||||
isVerifyLoading.value = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Reject document
|
||||
Future<bool> rejectDocument(String documentId) async {
|
||||
final result =
|
||||
await ApiService.verifyDocumentApi(id: documentId, isVerify: false);
|
||||
if (result) {
|
||||
await fetchDocumentDetails(documentId); // refresh details
|
||||
try {
|
||||
isRejectLoading.value = true;
|
||||
final result =
|
||||
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
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user