feat: Conditionally display Create Bucket option based on user permissions
This commit is contained in:
parent
229531c5bf
commit
bd6f175ca7
@ -16,6 +16,7 @@ import 'package:marco/model/directory/create_bucket_bottom_sheet.dart';
|
|||||||
import 'package:marco/view/directory/contact_detail_screen.dart';
|
import 'package:marco/view/directory/contact_detail_screen.dart';
|
||||||
import 'package:marco/view/directory/manage_bucket_screen.dart';
|
import 'package:marco/view/directory/manage_bucket_screen.dart';
|
||||||
import 'package:marco/controller/permission_controller.dart';
|
import 'package:marco/controller/permission_controller.dart';
|
||||||
|
import 'package:marco/helpers/utils/permission_constants.dart';
|
||||||
|
|
||||||
class DirectoryView extends StatefulWidget {
|
class DirectoryView extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
@ -288,35 +289,44 @@ class _DirectoryViewState extends State<DirectoryView> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create Bucket option
|
// ✅ Conditionally show Create Bucket option
|
||||||
menuItems.add(
|
if (permissionController
|
||||||
PopupMenuItem<int>(
|
.hasPermission(Permissions.directoryAdmin) ||
|
||||||
value: 2,
|
permissionController
|
||||||
child: Row(
|
.hasPermission(Permissions.directoryManager) ||
|
||||||
children: const [
|
permissionController
|
||||||
Icon(Icons.add_box_outlined,
|
.hasPermission(Permissions.directoryUser)) {
|
||||||
size: 20, color: Colors.black87),
|
menuItems.add(
|
||||||
SizedBox(width: 10),
|
PopupMenuItem<int>(
|
||||||
Expanded(child: Text("Create Bucket")),
|
value: 2,
|
||||||
Icon(Icons.chevron_right,
|
child: Row(
|
||||||
size: 20, color: Colors.red),
|
children: const [
|
||||||
],
|
Icon(Icons.add_box_outlined,
|
||||||
|
size: 20, color: Colors.black87),
|
||||||
|
SizedBox(width: 10),
|
||||||
|
Expanded(child: Text("Create Bucket")),
|
||||||
|
Icon(Icons.chevron_right,
|
||||||
|
size: 20, color: Colors.red),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
onTap: () {
|
||||||
|
Future.delayed(Duration.zero, () async {
|
||||||
|
final created =
|
||||||
|
await showModalBottomSheet<bool>(
|
||||||
|
context: context,
|
||||||
|
isScrollControlled: true,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
builder: (_) =>
|
||||||
|
const CreateBucketBottomSheet(),
|
||||||
|
);
|
||||||
|
if (created == true) {
|
||||||
|
await controller.fetchBuckets();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
),
|
),
|
||||||
onTap: () {
|
);
|
||||||
Future.delayed(Duration.zero, () async {
|
}
|
||||||
final created = await showModalBottomSheet<bool>(
|
|
||||||
context: context,
|
|
||||||
isScrollControlled: true,
|
|
||||||
backgroundColor: Colors.transparent,
|
|
||||||
builder: (_) => const CreateBucketBottomSheet(),
|
|
||||||
);
|
|
||||||
if (created == true) {
|
|
||||||
await controller.fetchBuckets();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Manage Buckets option
|
// Manage Buckets option
|
||||||
menuItems.add(
|
menuItems.add(
|
||||||
@ -355,7 +365,7 @@ class _DirectoryViewState extends State<DirectoryView> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Show Inactive switch
|
// Show Inactive toggle
|
||||||
menuItems.add(
|
menuItems.add(
|
||||||
PopupMenuItem<int>(
|
PopupMenuItem<int>(
|
||||||
value: 0,
|
value: 0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user