address book complete
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
|
||||
import 'package:pweb/pages/payment_methods/form.dart';
|
||||
|
||||
@@ -72,13 +72,16 @@ class _AdressBookRecipientFormState extends State<AdressBookRecipientForm> {
|
||||
|
||||
Future<Recipient?> _doSave() async {
|
||||
final recipients = context.read<RecipientsProvider>();
|
||||
final methods = context.read<PaymentMethodsProvider>();
|
||||
final methods = PaymentMethodsProvider();
|
||||
final recipient = widget.recipient == null
|
||||
? await recipients.create(
|
||||
name: _nameCtrl.text,
|
||||
email: _emailCtrl.text,
|
||||
)
|
||||
: widget.recipient!;
|
||||
recipients.setCurrentObject(recipient.id);
|
||||
//TODO : redesign work with recipients / payment methods
|
||||
await methods.loadMethods(context.read<OrganizationsProvider>(), recipient.id);
|
||||
for (final type in _methods.keys) {
|
||||
final data = _methods[type]!;
|
||||
final exising = methods.methods.firstWhereOrNull((m) => m.type == type);
|
||||
@@ -91,11 +94,6 @@ class _AdressBookRecipientFormState extends State<AdressBookRecipientForm> {
|
||||
data: data,
|
||||
);
|
||||
}
|
||||
await methods.create(
|
||||
reacipientRef: recipient.id,
|
||||
name: getPaymentTypeLabel(context, data.type),
|
||||
data: data,
|
||||
);
|
||||
}
|
||||
return recipient;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/models/permissions/action.dart' as perm;
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
import 'package:pshared/models/resources.dart';
|
||||
import 'package:pshared/provider/permissions.dart';
|
||||
|
||||
import 'package:pweb/pages/address_book/page/recipient/item.dart';
|
||||
|
||||
@@ -19,9 +24,16 @@ class RecipientAddressBookList extends StatelessWidget {
|
||||
this.onDelete,
|
||||
});
|
||||
|
||||
bool _checkPermissions(BuildContext context, Recipient recipient, perm.Action action) {
|
||||
return context.read<PermissionsProvider>().canAccessResource(
|
||||
ResourceType.recipients,
|
||||
action: action,
|
||||
objectRef: recipient.id,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
Widget build(BuildContext context) => ListView.builder(
|
||||
itemCount: filteredRecipients.length,
|
||||
itemBuilder: (context, index) {
|
||||
final recipient = filteredRecipients[index];
|
||||
@@ -30,11 +42,14 @@ Widget build(BuildContext context) {
|
||||
child: RecipientAddressBookItem(
|
||||
recipient: recipient,
|
||||
onTap: () => onSelected?.call(recipient),
|
||||
onEdit: () => onEdit?.call(recipient),
|
||||
onDelete: () => onDelete?.call(recipient),
|
||||
onEdit: _checkPermissions(context, recipient, perm.Action.update)
|
||||
? () => onEdit?.call(recipient)
|
||||
: null,
|
||||
onDelete: _checkPermissions(context, recipient, perm.Action.delete)
|
||||
? () => onDelete?.call(recipient)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,12 +18,14 @@ class RecipientAddressBookPage extends StatefulWidget {
|
||||
final ValueChanged<Recipient> onRecipientSelected;
|
||||
final VoidCallback onAddRecipient;
|
||||
final ValueChanged<Recipient>? onEditRecipient;
|
||||
final ValueChanged<Recipient>? onDeleteRecipient;
|
||||
|
||||
const RecipientAddressBookPage({
|
||||
super.key,
|
||||
required this.onRecipientSelected,
|
||||
required this.onAddRecipient,
|
||||
this.onEditRecipient,
|
||||
this.onDeleteRecipient,
|
||||
});
|
||||
|
||||
static const double _expandedHeight = 550;
|
||||
@@ -125,6 +127,7 @@ class _RecipientAddressBookPageState extends State<RecipientAddressBookPage> {
|
||||
child: RecipientAddressBookList(
|
||||
filteredRecipients: provider.filteredRecipients,
|
||||
onEdit: (recipient) => widget.onEditRecipient?.call(recipient),
|
||||
onDelete: (recipient) => widget.onDeleteRecipient?.call(recipient),
|
||||
onSelected: widget.onRecipientSelected,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -2,18 +2,22 @@ import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
class RecipientActions extends StatelessWidget {
|
||||
final VoidCallback onEdit;
|
||||
final VoidCallback onDelete;
|
||||
final VoidCallback? onEdit;
|
||||
final VoidCallback? onDelete;
|
||||
|
||||
const RecipientActions({super.key, required this.onEdit, required this.onDelete});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
children: [
|
||||
IconButton(icon: Icon(Icons.edit, color: Theme.of(context).colorScheme.primary), onPressed: onEdit),
|
||||
IconButton(icon: Icon(Icons.delete, color: Theme.of(context).colorScheme.error), onPressed: onDelete),
|
||||
],
|
||||
);
|
||||
}
|
||||
Widget build(BuildContext context) => Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.edit, color: Theme.of(context).colorScheme.primary),
|
||||
onPressed: onEdit,
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete, color: Theme.of(context).colorScheme.error),
|
||||
onPressed: onDelete,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ import 'package:pweb/pages/dashboard/payouts/single/adress_book/avatar.dart';
|
||||
class RecipientAddressBookItem extends StatefulWidget {
|
||||
final Recipient recipient;
|
||||
final VoidCallback onTap;
|
||||
final VoidCallback onEdit;
|
||||
final VoidCallback onDelete;
|
||||
final VoidCallback? onEdit;
|
||||
final VoidCallback? onDelete;
|
||||
|
||||
final double borderRadius;
|
||||
final double elevation;
|
||||
@@ -82,7 +82,9 @@ class _RecipientAddressBookItemState extends State<RecipientAddressBookItem> {
|
||||
),
|
||||
if (_isHovered)
|
||||
RecipientActions(
|
||||
onEdit: widget.onEdit, onDelete: widget.onDelete),
|
||||
onEdit: widget.onEdit,
|
||||
onDelete: widget.onDelete,
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: widget.spacingBottom),
|
||||
|
||||
Reference in New Issue
Block a user