Files
sendico/frontend/pweb/lib/widgets/sidebar/page.dart
2025-12-05 01:32:41 +01:00

140 lines
4.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:pshared/models/resources.dart';
import 'package:pshared/provider/permissions.dart';
import 'package:pweb/pages/address_book/form/page.dart';
import 'package:pweb/pages/address_book/page/page.dart';
import 'package:pweb/pages/loader.dart';
import 'package:pweb/pages/payment_methods/page.dart';
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/pages/dashboard/dashboard.dart';
import 'package:pweb/providers/page_selector.dart';
import 'package:pweb/utils/logout.dart';
import 'package:pweb/widgets/appbar/app_bar.dart';
import 'package:pweb/widgets/sidebar/destinations.dart';
import 'package:pweb/widgets/sidebar/sidebar.dart';
import 'package:pweb/generated/i18n/app_localizations.dart';
class PageSelector extends StatelessWidget {
const PageSelector({super.key});
@override
Widget build(BuildContext context) => PageViewLoader(
child: Builder(builder: (BuildContext context) {
final permissions = context.watch<PermissionsProvider>();
if (!permissions.isReady) return Center(child: CircularProgressIndicator());
final provider = context.watch<PageSelectorProvider>();
final loc = AppLocalizations.of(context)!;
final bool restrictedAccess = !permissions.canRead(ResourceType.chainWallets);
final allowedDestinations = restrictedAccess
? <PayoutDestination>{
PayoutDestination.settings,
PayoutDestination.methods,
PayoutDestination.editwallet,
}
: PayoutDestination.values.toSet();
final selected = allowedDestinations.contains(provider.selected)
? provider.selected
: (restrictedAccess ? PayoutDestination.settings : PayoutDestination.dashboard);
if (selected != provider.selected) {
WidgetsBinding.instance.addPostFrameCallback((_) => provider.selectPage(selected));
}
Widget content;
switch (selected) {
case PayoutDestination.dashboard:
content = DashboardPage(
onRecipientSelected: (recipient) => provider.selectRecipient(recipient),
onGoToPaymentWithoutRecipient: provider.startPaymentWithoutRecipient,
);
break;
case PayoutDestination.recipients:
content = RecipientAddressBookPage(
onRecipientSelected: (recipient) =>
provider.selectRecipient(recipient, fromList: true),
onAddRecipient: provider.goToAddRecipient,
onEditRecipient: provider.editRecipient,
);
break;
case PayoutDestination.addrecipient:
final recipient = provider.recipientProvider.currentObject;
content = AdressBookRecipientForm(
recipient: recipient,
onSaved: (_) => provider.selectPage(PayoutDestination.recipients),
);
break;
case PayoutDestination.payment:
content = PaymentPage(
onBack: (_) => provider.goBackFromPayment(),
);
break;
case PayoutDestination.settings:
content = ProfileSettingsPage();
break;
case PayoutDestination.reports:
content = OperationHistoryPage();
break;
case PayoutDestination.methods:
content = PaymentConfigPage(
onWalletTap: provider.selectWallet,
);
break;
case PayoutDestination.editwallet:
final wallet = provider.walletsProvider.selectedWallet;
content = wallet != null
? WalletEditPage(
onBack: provider.goBackFromWalletEdit,
)
: Center(child: Text(loc.noWalletSelected));
break;
default:
content = Text(selected.name);
}
return Scaffold(
appBar: PayoutAppBar(
title: Text(selected.localizedLabel(context)),
onAddFundsPressed: () {},
onLogout: () => logoutUtil(context),
),
body: Padding(
padding: const EdgeInsets.only(left: 200, top: 40, right: 200),
child: Row(
spacing: 40,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
PayoutSidebar(
selected: selected,
onSelected: provider.selectPage,
onLogout: () => logoutUtil(context),
),
Expanded(child: content),
],
),
),
);
},
));
}