Added account permissions and ui for recipient
This commit is contained in:
@@ -9,7 +9,10 @@ import 'package:pweb/pages/payout_page/page.dart';
|
||||
import 'package:pweb/pages/payout_page/wallet/edit/page.dart';
|
||||
import 'package:pweb/pages/report/page.dart';
|
||||
import 'package:pweb/pages/settings/profile/page.dart';
|
||||
import 'package:pweb/providers/account.dart';
|
||||
import 'package:pweb/providers/page_selector.dart';
|
||||
import 'package:pweb/providers/permissions.dart';
|
||||
import 'package:pweb/app/router/pages.dart';
|
||||
import 'package:pweb/widgets/appbar/app_bar.dart';
|
||||
import 'package:pweb/pages/dashboard/dashboard.dart';
|
||||
import 'package:pweb/widgets/sidebar/destinations.dart';
|
||||
@@ -21,13 +24,37 @@ import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
class PageSelector extends StatelessWidget {
|
||||
const PageSelector({super.key});
|
||||
|
||||
void _handleLogout(BuildContext context) {
|
||||
context.read<AccountProvider>().logout();
|
||||
context.read<PermissionsProvider>().clear();
|
||||
navigateAndReplace(context, Pages.login);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<PageSelectorProvider>();
|
||||
final permissions = context.watch<PermissionsProvider>();
|
||||
final account = context.watch<AccountProvider>().account;
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
|
||||
final allowedDestinations = permissions.isRecipient
|
||||
? <PayoutDestination>{
|
||||
PayoutDestination.settings,
|
||||
PayoutDestination.methods,
|
||||
PayoutDestination.editwallet,
|
||||
}
|
||||
: PayoutDestination.values.toSet();
|
||||
|
||||
final selected = allowedDestinations.contains(provider.selected)
|
||||
? provider.selected
|
||||
: (permissions.isRecipient ? PayoutDestination.settings : PayoutDestination.dashboard);
|
||||
|
||||
if (selected != provider.selected) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => provider.selectPage(selected));
|
||||
}
|
||||
|
||||
Widget content;
|
||||
switch (provider.selected) {
|
||||
switch (selected) {
|
||||
case PayoutDestination.dashboard:
|
||||
content = DashboardPage(
|
||||
onRecipientSelected: (recipient) =>
|
||||
@@ -83,14 +110,14 @@ class PageSelector extends StatelessWidget {
|
||||
break;
|
||||
|
||||
default:
|
||||
content = Text(provider.selected.name);
|
||||
content = Text(selected.name);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: PayoutAppBar(
|
||||
title: Text(provider.selected.localizedLabel(context)),
|
||||
title: Text(selected.localizedLabel(context)),
|
||||
onAddFundsPressed: () {},
|
||||
onLogout: () => debugPrint('Logout clicked'),
|
||||
onLogout: () => _handleLogout(context),
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.only(left: 200, top: 40, right: 200),
|
||||
@@ -99,9 +126,13 @@ class PageSelector extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
PayoutSidebar(
|
||||
selected: provider.selected,
|
||||
selected: selected,
|
||||
onSelected: provider.selectPage,
|
||||
onLogout: () => debugPrint('Logout clicked'),
|
||||
onLogout: () => _handleLogout(context),
|
||||
userName: account?.name,
|
||||
items: permissions.isRecipient
|
||||
? const [PayoutDestination.settings, PayoutDestination.methods]
|
||||
: null,
|
||||
),
|
||||
Expanded(child: content),
|
||||
],
|
||||
|
||||
@@ -13,6 +13,7 @@ class PayoutSidebar extends StatelessWidget {
|
||||
this.onLogout,
|
||||
this.userName,
|
||||
this.avatarUrl,
|
||||
this.items,
|
||||
});
|
||||
|
||||
final PayoutDestination selected;
|
||||
@@ -21,11 +22,13 @@ class PayoutSidebar extends StatelessWidget {
|
||||
|
||||
final String? userName;
|
||||
final String? avatarUrl;
|
||||
final List<PayoutDestination>? items;
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final items = [
|
||||
final menuItems = items ??
|
||||
<PayoutDestination>[
|
||||
PayoutDestination.dashboard,
|
||||
PayoutDestination.recipients,
|
||||
PayoutDestination.methods,
|
||||
@@ -49,11 +52,11 @@ class PayoutSidebar extends StatelessWidget {
|
||||
theme: theme,
|
||||
avatarUrl: avatarUrl,
|
||||
userName: userName,
|
||||
items: items,
|
||||
items: menuItems,
|
||||
selected: selected,
|
||||
onSelected: onSelected,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user