address book complete #28
@@ -433,6 +433,14 @@
|
|||||||
"@errorSaveRecipient": {
|
"@errorSaveRecipient": {
|
||||||
"description": "Error message displayed when saving a recipient fails"
|
"description": "Error message displayed when saving a recipient fails"
|
||||||
},
|
},
|
||||||
|
"recipientDeletedSuccessfully": "Recipient deleted successfully",
|
||||||
|
"@recipientDeletedSuccessfully": {
|
||||||
|
"description": "Success message displayed when a recipient is deleted"
|
||||||
|
},
|
||||||
|
"errorDeleteRecipient": "Failed to delete recipient",
|
||||||
|
"@errorDeleteRecipient": {
|
||||||
|
"description": "Error message displayed when deleting a recipient fails"
|
||||||
|
},
|
||||||
|
|
||||||
"errorSignUp": "Error occured while signing up, try again later",
|
"errorSignUp": "Error occured while signing up, try again later",
|
||||||
"companyDescription": "Company Description",
|
"companyDescription": "Company Description",
|
||||||
|
|||||||
@@ -433,6 +433,14 @@
|
|||||||
"@errorSaveRecipient": {
|
"@errorSaveRecipient": {
|
||||||
"description": "Сообщение об ошибке при неудачном сохранении получателя"
|
"description": "Сообщение об ошибке при неудачном сохранении получателя"
|
||||||
},
|
},
|
||||||
|
"recipientDeletedSuccessfully": "Получатель успешно удален",
|
||||||
|
"@recipientDeletedSuccessfully": {
|
||||||
|
"description": "Сообщение об успешном удалении получателя"
|
||||||
|
},
|
||||||
|
"errorDeleteRecipient": "Не удалось удалить получателя",
|
||||||
|
"@errorDeleteRecipient": {
|
||||||
|
"description": "Сообщение об ошибке при неудачном удалении получателя"
|
||||||
|
},
|
||||||
|
|
||||||
"errorSignUp": "Произошла ошибка при регистрации, попробуйте позже",
|
"errorSignUp": "Произошла ошибка при регистрации, попробуйте позже",
|
||||||
"companyDescription": "Описание компании",
|
"companyDescription": "Описание компании",
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import 'package:pweb/providers/upload_history.dart';
|
|||||||
import 'package:pweb/providers/wallets.dart';
|
import 'package:pweb/providers/wallets.dart';
|
||||||
import 'package:pweb/providers/wallet_transactions.dart';
|
import 'package:pweb/providers/wallet_transactions.dart';
|
||||||
// import 'package:pweb/services/amplitude.dart';
|
// import 'package:pweb/services/amplitude.dart';
|
||||||
// import 'package:pweb/services/amplitude.dart';
|
|
||||||
import 'package:pweb/services/operations.dart';
|
import 'package:pweb/services/operations.dart';
|
||||||
import 'package:pweb/services/payments/history.dart';
|
import 'package:pweb/services/payments/history.dart';
|
||||||
import 'package:pweb/services/wallet_transactions.dart';
|
import 'package:pweb/services/wallet_transactions.dart';
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
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:pshared/models/payment/type.dart';
|
||||||
|
|
||||||
import 'package:pweb/pages/payment_methods/form.dart';
|
import 'package:pweb/pages/payment_methods/form.dart';
|
||||||
|
|||||||
@@ -72,13 +72,16 @@ class _AdressBookRecipientFormState extends State<AdressBookRecipientForm> {
|
|||||||
|
|
||||||
Future<Recipient?> _doSave() async {
|
Future<Recipient?> _doSave() async {
|
||||||
final recipients = context.read<RecipientsProvider>();
|
final recipients = context.read<RecipientsProvider>();
|
||||||
final methods = context.read<PaymentMethodsProvider>();
|
final methods = PaymentMethodsProvider();
|
||||||
final recipient = widget.recipient == null
|
final recipient = widget.recipient == null
|
||||||
? await recipients.create(
|
? await recipients.create(
|
||||||
name: _nameCtrl.text,
|
name: _nameCtrl.text,
|
||||||
email: _emailCtrl.text,
|
email: _emailCtrl.text,
|
||||||
)
|
)
|
||||||
: widget.recipient!;
|
: 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) {
|
for (final type in _methods.keys) {
|
||||||
final data = _methods[type]!;
|
final data = _methods[type]!;
|
||||||
final exising = methods.methods.firstWhereOrNull((m) => m.type == type);
|
final exising = methods.methods.firstWhereOrNull((m) => m.type == type);
|
||||||
@@ -91,11 +94,6 @@ class _AdressBookRecipientFormState extends State<AdressBookRecipientForm> {
|
|||||||
data: data,
|
data: data,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
await methods.create(
|
|
||||||
reacipientRef: recipient.id,
|
|
||||||
name: getPaymentTypeLabel(context, data.type),
|
|
||||||
data: data,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return recipient;
|
return recipient;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
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/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';
|
import 'package:pweb/pages/address_book/page/recipient/item.dart';
|
||||||
|
|
||||||
@@ -19,9 +24,16 @@ class RecipientAddressBookList extends StatelessWidget {
|
|||||||
this.onDelete,
|
this.onDelete,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
bool _checkPermissions(BuildContext context, Recipient recipient, perm.Action action) {
|
||||||
|
return context.read<PermissionsProvider>().canAccessResource(
|
||||||
|
ResourceType.recipients,
|
||||||
|
action: action,
|
||||||
|
objectRef: recipient.id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => ListView.builder(
|
||||||
return ListView.builder(
|
|
||||||
itemCount: filteredRecipients.length,
|
itemCount: filteredRecipients.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final recipient = filteredRecipients[index];
|
final recipient = filteredRecipients[index];
|
||||||
@@ -30,11 +42,14 @@ Widget build(BuildContext context) {
|
|||||||
child: RecipientAddressBookItem(
|
child: RecipientAddressBookItem(
|
||||||
recipient: recipient,
|
recipient: recipient,
|
||||||
onTap: () => onSelected?.call(recipient),
|
onTap: () => onSelected?.call(recipient),
|
||||||
onEdit: () => onEdit?.call(recipient),
|
onEdit: _checkPermissions(context, recipient, perm.Action.update)
|
||||||
onDelete: () => onDelete?.call(recipient),
|
? () => 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 ValueChanged<Recipient> onRecipientSelected;
|
||||||
final VoidCallback onAddRecipient;
|
final VoidCallback onAddRecipient;
|
||||||
final ValueChanged<Recipient>? onEditRecipient;
|
final ValueChanged<Recipient>? onEditRecipient;
|
||||||
|
final ValueChanged<Recipient>? onDeleteRecipient;
|
||||||
|
|
||||||
const RecipientAddressBookPage({
|
const RecipientAddressBookPage({
|
||||||
super.key,
|
super.key,
|
||||||
required this.onRecipientSelected,
|
required this.onRecipientSelected,
|
||||||
required this.onAddRecipient,
|
required this.onAddRecipient,
|
||||||
this.onEditRecipient,
|
this.onEditRecipient,
|
||||||
|
this.onDeleteRecipient,
|
||||||
});
|
});
|
||||||
|
|
||||||
static const double _expandedHeight = 550;
|
static const double _expandedHeight = 550;
|
||||||
@@ -125,6 +127,7 @@ class _RecipientAddressBookPageState extends State<RecipientAddressBookPage> {
|
|||||||
child: RecipientAddressBookList(
|
child: RecipientAddressBookList(
|
||||||
filteredRecipients: provider.filteredRecipients,
|
filteredRecipients: provider.filteredRecipients,
|
||||||
onEdit: (recipient) => widget.onEditRecipient?.call(recipient),
|
onEdit: (recipient) => widget.onEditRecipient?.call(recipient),
|
||||||
|
onDelete: (recipient) => widget.onDeleteRecipient?.call(recipient),
|
||||||
onSelected: widget.onRecipientSelected,
|
onSelected: widget.onRecipientSelected,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -2,18 +2,22 @@ import 'package:flutter/material.dart';
|
|||||||
|
|
||||||
|
|
||||||
class RecipientActions extends StatelessWidget {
|
class RecipientActions extends StatelessWidget {
|
||||||
final VoidCallback onEdit;
|
final VoidCallback? onEdit;
|
||||||
final VoidCallback onDelete;
|
final VoidCallback? onDelete;
|
||||||
|
|
||||||
const RecipientActions({super.key, required this.onEdit, required this.onDelete});
|
const RecipientActions({super.key, required this.onEdit, required this.onDelete});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) => Row(
|
||||||
return Row(
|
children: [
|
||||||
children: [
|
IconButton(
|
||||||
IconButton(icon: Icon(Icons.edit, color: Theme.of(context).colorScheme.primary), onPressed: onEdit),
|
icon: Icon(Icons.edit, color: Theme.of(context).colorScheme.primary),
|
||||||
IconButton(icon: Icon(Icons.delete, color: Theme.of(context).colorScheme.error), onPressed: onDelete),
|
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 {
|
class RecipientAddressBookItem extends StatefulWidget {
|
||||||
final Recipient recipient;
|
final Recipient recipient;
|
||||||
final VoidCallback onTap;
|
final VoidCallback onTap;
|
||||||
final VoidCallback onEdit;
|
final VoidCallback? onEdit;
|
||||||
final VoidCallback onDelete;
|
final VoidCallback? onDelete;
|
||||||
|
|
||||||
final double borderRadius;
|
final double borderRadius;
|
||||||
final double elevation;
|
final double elevation;
|
||||||
@@ -82,7 +82,9 @@ class _RecipientAddressBookItemState extends State<RecipientAddressBookItem> {
|
|||||||
),
|
),
|
||||||
if (_isHovered)
|
if (_isHovered)
|
||||||
RecipientActions(
|
RecipientActions(
|
||||||
onEdit: widget.onEdit, onDelete: widget.onDelete),
|
onEdit: widget.onEdit,
|
||||||
|
onDelete: widget.onDelete,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
SizedBox(height: widget.spacingBottom),
|
SizedBox(height: widget.spacingBottom),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import 'package:provider/provider.dart';
|
|||||||
|
|
||||||
import 'package:pshared/models/resources.dart';
|
import 'package:pshared/models/resources.dart';
|
||||||
import 'package:pshared/provider/permissions.dart';
|
import 'package:pshared/provider/permissions.dart';
|
||||||
|
import 'package:pshared/provider/recipient/provider.dart';
|
||||||
|
|
||||||
import 'package:pweb/pages/address_book/form/page.dart';
|
import 'package:pweb/pages/address_book/form/page.dart';
|
||||||
import 'package:pweb/pages/address_book/page/page.dart';
|
import 'package:pweb/pages/address_book/page/page.dart';
|
||||||
@@ -17,6 +18,7 @@ import 'package:pweb/pages/dashboard/dashboard.dart';
|
|||||||
import 'package:pweb/providers/page_selector.dart';
|
import 'package:pweb/providers/page_selector.dart';
|
||||||
import 'package:pweb/utils/logout.dart';
|
import 'package:pweb/utils/logout.dart';
|
||||||
import 'package:pweb/widgets/appbar/app_bar.dart';
|
import 'package:pweb/widgets/appbar/app_bar.dart';
|
||||||
|
import 'package:pweb/widgets/error/snackbar.dart';
|
||||||
import 'package:pweb/widgets/sidebar/destinations.dart';
|
import 'package:pweb/widgets/sidebar/destinations.dart';
|
||||||
import 'package:pweb/widgets/sidebar/sidebar.dart';
|
import 'package:pweb/widgets/sidebar/sidebar.dart';
|
||||||
|
|
||||||
@@ -29,7 +31,7 @@ class PageSelector extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) => PageViewLoader(
|
Widget build(BuildContext context) => PageViewLoader(
|
||||||
child: Builder(builder: (BuildContext context) {
|
child: Builder(builder: (BuildContext context) {
|
||||||
final permissions = context.watch<PermissionsProvider>();
|
final permissions = context.read<PermissionsProvider>();
|
||||||
if (!permissions.isReady) return Center(child: CircularProgressIndicator());
|
if (!permissions.isReady) return Center(child: CircularProgressIndicator());
|
||||||
|
|
||||||
final provider = context.watch<PageSelectorProvider>();
|
final provider = context.watch<PageSelectorProvider>();
|
||||||
@@ -68,6 +70,12 @@ class PageSelector extends StatelessWidget {
|
|||||||
provider.selectRecipient(recipient, fromList: true),
|
provider.selectRecipient(recipient, fromList: true),
|
||||||
onAddRecipient: provider.goToAddRecipient,
|
onAddRecipient: provider.goToAddRecipient,
|
||||||
onEditRecipient: provider.editRecipient,
|
onEditRecipient: provider.editRecipient,
|
||||||
|
onDeleteRecipient: (recipient) => executeActionWithNotification(
|
||||||
|
context: context,
|
||||||
|
action: () async => context.read<RecipientsProvider>().delete(recipient.id),
|
||||||
|
successMessage: loc.recipientDeletedSuccessfully,
|
||||||
|
errorMessage: loc.errorDeleteRecipient,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user