recipient saving
This commit is contained in:
@@ -2,17 +2,22 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'package:pshared/models/payment/methods/data.dart';
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/models/recipient/recipient.dart';
|
||||
import 'package:pshared/models/recipient/status.dart';
|
||||
import 'package:pshared/models/recipient/type.dart';
|
||||
import 'package:pshared/provider/organizations.dart';
|
||||
import 'package:pshared/provider/recipient/pmethods.dart';
|
||||
import 'package:pshared/provider/recipient/provider.dart';
|
||||
|
||||
import 'package:pweb/pages/address_book/form/view.dart';
|
||||
// import 'package:pweb/services/amplitude.dart';
|
||||
import 'package:pweb/utils/error/snackbar.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
import 'package:pweb/utils/payment/label.dart';
|
||||
import 'package:pweb/utils/snackbar.dart';
|
||||
|
||||
|
||||
class AdressBookRecipientForm extends StatefulWidget {
|
||||
@@ -31,7 +36,7 @@ class _AdressBookRecipientFormState extends State<AdressBookRecipientForm> {
|
||||
late TextEditingController _emailCtrl;
|
||||
RecipientType _type = RecipientType.internal;
|
||||
RecipientStatus _status = RecipientStatus.ready;
|
||||
final Map<PaymentType, Object?> _methods = {};
|
||||
final MethodMap _methods = {};
|
||||
late PaymentMethodsProvider _methodsProvider;
|
||||
|
||||
Future<void> _loadMethods() async {
|
||||
@@ -63,31 +68,43 @@ class _AdressBookRecipientFormState extends State<AdressBookRecipientForm> {
|
||||
_loadMethods();
|
||||
}
|
||||
|
||||
Future<Recipient?> _doSave() async {
|
||||
final recipients = context.read<RecipientsProvider>();
|
||||
final methods = context.read<PaymentMethodsProvider>();
|
||||
final recipient = await recipients.create(
|
||||
name: _nameCtrl.text,
|
||||
email: _emailCtrl.text,
|
||||
);
|
||||
if (methods.currentObject == null) return recipient;
|
||||
final data = methods.currentObject!;
|
||||
await methods.create(
|
||||
reacipientRef: recipient.id,
|
||||
name: getPaymentTypeLabel(context, data.type),
|
||||
data: data.data,
|
||||
);
|
||||
return recipient;
|
||||
}
|
||||
|
||||
//TODO: Change when registration is ready
|
||||
void _save() {
|
||||
Future<void> _save() async {
|
||||
if (!_formKey.currentState!.validate() || _methods.isEmpty) {
|
||||
// AmplitudeService.recipientAddCompleted(
|
||||
// _type,
|
||||
// _status,
|
||||
// _methods.keys.toSet(),
|
||||
// );
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.recipientFormRule),
|
||||
),
|
||||
);
|
||||
notifyUser(context, AppLocalizations.of(context)!.errorSaveRecipient);
|
||||
return;
|
||||
}
|
||||
|
||||
final recipient = newRecipient(
|
||||
name: _nameCtrl.text,
|
||||
email: _emailCtrl.text,
|
||||
type: _type,
|
||||
status: _status,
|
||||
avatarUrl: null,
|
||||
organizationRef: context.read<OrganizationsProvider>().current.id
|
||||
// AmplitudeService.recipientAddCompleted(
|
||||
// _type,
|
||||
// _status,
|
||||
// _methods.keys.toSet(),
|
||||
// );
|
||||
final recipient = await executeActionWithNotification(
|
||||
context: context,
|
||||
action: _doSave,
|
||||
errorMessage: AppLocalizations.of(context)!.errorSaveRecipient,
|
||||
successMessage: AppLocalizations.of(context)!.recipientFormRule,
|
||||
);
|
||||
|
||||
|
||||
widget.onSaved?.call(recipient);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user