Frontend first draft
This commit is contained in:
90
frontend/pweb/lib/pages/address_book/form/method_tile.dart
Normal file
90
frontend/pweb/lib/pages/address_book/form/method_tile.dart
Normal file
@@ -0,0 +1,90 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
|
||||
import 'package:pweb/pages/payment_methods/form.dart';
|
||||
import 'package:pweb/pages/payment_methods/icon.dart';
|
||||
|
||||
|
||||
class AdressBookPaymentMethodTile extends StatefulWidget {
|
||||
final PaymentType type;
|
||||
final String title;
|
||||
final Map<PaymentType, Object?> methods;
|
||||
final ValueChanged<Object?> onChanged;
|
||||
|
||||
final double spacingM;
|
||||
final double spacingS;
|
||||
final double sizeM;
|
||||
final TextStyle? titleTextStyle;
|
||||
|
||||
const AdressBookPaymentMethodTile({
|
||||
super.key,
|
||||
required this.type,
|
||||
required this.title,
|
||||
required this.methods,
|
||||
required this.onChanged,
|
||||
this.spacingM = 12,
|
||||
this.spacingS = 8,
|
||||
this.sizeM = 20,
|
||||
this.titleTextStyle,
|
||||
});
|
||||
|
||||
@override
|
||||
State<AdressBookPaymentMethodTile> createState() => _AdressBookPaymentMethodTileState();
|
||||
}
|
||||
|
||||
class _AdressBookPaymentMethodTileState extends State<AdressBookPaymentMethodTile> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final isAdded = widget.methods.containsKey(widget.type);
|
||||
|
||||
return ExpansionTile(
|
||||
title: Row(
|
||||
children: [
|
||||
Icon(
|
||||
iconForPaymentType(widget.type),
|
||||
size: widget.sizeM,
|
||||
color: isAdded
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.onSurface,
|
||||
),
|
||||
SizedBox(width: widget.spacingS),
|
||||
Text(
|
||||
widget.title,
|
||||
style: widget.titleTextStyle ??
|
||||
theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isAdded ? theme.colorScheme.primary : null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (isAdded)
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete, color: theme.colorScheme.error),
|
||||
onPressed: () {
|
||||
widget.onChanged(null);
|
||||
},
|
||||
),
|
||||
Icon(
|
||||
isAdded ? Icons.check_circle : Icons.add_circle_outline,
|
||||
color: isAdded ? theme.colorScheme.primary : null,
|
||||
),
|
||||
],
|
||||
),
|
||||
children: [
|
||||
PaymentMethodForm(
|
||||
key: ValueKey(widget.type),
|
||||
selectedType: widget.type,
|
||||
initialData: widget.methods[widget.type],
|
||||
onChanged: widget.onChanged,
|
||||
),
|
||||
SizedBox(height: widget.spacingM),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
109
frontend/pweb/lib/pages/address_book/form/page.dart
Normal file
109
frontend/pweb/lib/pages/address_book/form/page.dart
Normal file
@@ -0,0 +1,109 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/methods/card.dart';
|
||||
import 'package:pshared/models/payment/methods/iban.dart';
|
||||
import 'package:pshared/models/payment/methods/russian_bank.dart';
|
||||
import 'package:pshared/models/payment/methods/wallet.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:pweb/pages/address_book/form/view.dart';
|
||||
import 'package:pweb/services/amplitude.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class AdressBookRecipientForm extends StatefulWidget {
|
||||
final Recipient? recipient;
|
||||
final ValueChanged<Recipient?>? onSaved;
|
||||
|
||||
const AdressBookRecipientForm({super.key, this.recipient, this.onSaved});
|
||||
|
||||
@override
|
||||
State<AdressBookRecipientForm> createState() => _AdressBookRecipientFormState();
|
||||
}
|
||||
|
||||
class _AdressBookRecipientFormState extends State<AdressBookRecipientForm> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
late TextEditingController _nameCtrl;
|
||||
late TextEditingController _emailCtrl;
|
||||
RecipientType _type = RecipientType.internal;
|
||||
RecipientStatus _status = RecipientStatus.ready;
|
||||
final Map<PaymentType, Object?> _methods = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final r = widget.recipient;
|
||||
_nameCtrl = TextEditingController(text: r?.name ?? "");
|
||||
_emailCtrl = TextEditingController(text: r?.email ?? "");
|
||||
_type = r?.type ?? RecipientType.internal;
|
||||
_status = r?.status ?? RecipientStatus.ready;
|
||||
|
||||
if (r?.card != null) _methods[PaymentType.card] = r!.card;
|
||||
if (r?.iban != null) _methods[PaymentType.iban] = r!.iban;
|
||||
if (r?.wallet != null) _methods[PaymentType.wallet] = r!.wallet;
|
||||
if (r?.bank != null) _methods[PaymentType.bankAccount] = r!.bank;
|
||||
}
|
||||
|
||||
//TODO Change when registration is ready
|
||||
void _save() {
|
||||
if (!_formKey.currentState!.validate() || _methods.isEmpty) {
|
||||
AmplitudeService.recipientAddCompleted(
|
||||
_type,
|
||||
_status,
|
||||
_methods.keys.toSet(),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.recipientFormRule),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final recipient = Recipient(
|
||||
name: _nameCtrl.text,
|
||||
email: _emailCtrl.text,
|
||||
type: _type,
|
||||
status: _status,
|
||||
avatarUrl: null,
|
||||
card: _methods[PaymentType.card] as CardPaymentMethod?,
|
||||
iban: _methods[PaymentType.iban] as IbanPaymentMethod?,
|
||||
wallet: _methods[PaymentType.wallet] as WalletPaymentMethod?,
|
||||
bank: _methods[PaymentType.bankAccount] as RussianBankAccountPaymentMethod?,
|
||||
);
|
||||
|
||||
widget.onSaved?.call(recipient);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return FormView(
|
||||
formKey: _formKey,
|
||||
nameCtrl: _nameCtrl,
|
||||
emailCtrl: _emailCtrl,
|
||||
type: _type,
|
||||
status: _status,
|
||||
methods: _methods,
|
||||
onTypeChanged: (t) => setState(() => _type = t),
|
||||
onStatusChanged: (s) => setState(() => _status = s),
|
||||
onMethodsChanged: (type, data) {
|
||||
setState(() {
|
||||
if (data != null) {
|
||||
_methods[type] = data;
|
||||
} else {
|
||||
_methods.remove(type);
|
||||
}
|
||||
});
|
||||
},
|
||||
onSave: _save,
|
||||
isEditing: widget.recipient != null,
|
||||
onBack: () {
|
||||
widget.onSaved?.call(null);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
124
frontend/pweb/lib/pages/address_book/form/view.dart
Normal file
124
frontend/pweb/lib/pages/address_book/form/view.dart
Normal file
@@ -0,0 +1,124 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pshared/models/payment/type.dart';
|
||||
import 'package:pshared/models/recipient/status.dart';
|
||||
import 'package:pshared/models/recipient/type.dart';
|
||||
|
||||
import 'package:pweb/utils/payment/label.dart';
|
||||
import 'package:pweb/pages/address_book/form/method_tile.dart';
|
||||
import 'package:pweb/pages/address_book/form/widgets/button.dart';
|
||||
import 'package:pweb/pages/address_book/form/widgets/email_field.dart';
|
||||
import 'package:pweb/pages/address_book/form/widgets/header.dart';
|
||||
import 'package:pweb/pages/address_book/form/widgets/name_field.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class FormView extends StatelessWidget {
|
||||
final GlobalKey<FormState> formKey;
|
||||
final TextEditingController nameCtrl;
|
||||
final TextEditingController emailCtrl;
|
||||
final RecipientType type;
|
||||
final RecipientStatus status;
|
||||
final Map<PaymentType, Object?> methods;
|
||||
final ValueChanged<RecipientType> onTypeChanged;
|
||||
final ValueChanged<RecipientStatus> onStatusChanged;
|
||||
final void Function(PaymentType, Object?) onMethodsChanged;
|
||||
final VoidCallback onSave;
|
||||
final bool isEditing;
|
||||
final VoidCallback onBack;
|
||||
|
||||
final double maxWidth;
|
||||
final double elevation;
|
||||
final double borderRadius;
|
||||
final EdgeInsetsGeometry padding;
|
||||
final double spacingHeader;
|
||||
final double spacingFields;
|
||||
final double spacingDivider;
|
||||
final double spacingSave;
|
||||
final double spacingBottom;
|
||||
final TextStyle? titleTextStyle;
|
||||
|
||||
const FormView({
|
||||
super.key,
|
||||
required this.formKey,
|
||||
required this.nameCtrl,
|
||||
required this.emailCtrl,
|
||||
required this.type,
|
||||
required this.status,
|
||||
required this.methods,
|
||||
required this.onTypeChanged,
|
||||
required this.onStatusChanged,
|
||||
required this.onMethodsChanged,
|
||||
required this.onSave,
|
||||
required this.isEditing,
|
||||
required this.onBack,
|
||||
this.maxWidth = 500,
|
||||
this.elevation = 4,
|
||||
this.borderRadius = 16,
|
||||
this.padding = const EdgeInsets.all(20),
|
||||
this.spacingHeader = 20,
|
||||
this.spacingFields = 12,
|
||||
this.spacingDivider = 40,
|
||||
this.spacingSave = 30,
|
||||
this.spacingBottom = 16,
|
||||
this.titleTextStyle,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(maxWidth: maxWidth),
|
||||
child: Material(
|
||||
elevation: elevation,
|
||||
borderRadius: BorderRadius.circular(borderRadius),
|
||||
color: theme.colorScheme.onSecondary,
|
||||
child: Padding(
|
||||
padding: padding,
|
||||
child: Form(
|
||||
key: formKey,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
HeaderWidget(
|
||||
isEditing: isEditing,
|
||||
onBack: onBack,
|
||||
),
|
||||
SizedBox(height: spacingHeader),
|
||||
NameField(controller: nameCtrl),
|
||||
SizedBox(height: spacingFields),
|
||||
EmailField(controller: emailCtrl),
|
||||
Divider(height: spacingDivider),
|
||||
Text(
|
||||
AppLocalizations.of(context)!.choosePaymentMethod,
|
||||
style: titleTextStyle ??
|
||||
theme.textTheme.titleMedium
|
||||
?.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
SizedBox(height: spacingFields),
|
||||
...PaymentType.values.map(
|
||||
(p) => AdressBookPaymentMethodTile(
|
||||
type: p,
|
||||
title: getPaymentTypeLabel(context, p),
|
||||
methods: methods,
|
||||
onChanged: (data) => onMethodsChanged(p, data),
|
||||
),
|
||||
),
|
||||
SizedBox(height: spacingSave),
|
||||
SaveButton(onSave: onSave),
|
||||
SizedBox(height: spacingBottom),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class SaveButton extends StatelessWidget {
|
||||
final VoidCallback onSave;
|
||||
|
||||
final double width;
|
||||
final double height;
|
||||
final double borderRadius;
|
||||
final String? text;
|
||||
final TextStyle? textStyle;
|
||||
|
||||
const SaveButton({
|
||||
super.key,
|
||||
required this.onSave,
|
||||
this.width = 200,
|
||||
this.height = 45,
|
||||
this.borderRadius = 12,
|
||||
this.text,
|
||||
this.textStyle,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
height: height,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(borderRadius),
|
||||
onTap: onSave,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.primary,
|
||||
borderRadius: BorderRadius.circular(borderRadius),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
text ?? AppLocalizations.of(context)!.saveRecipient,
|
||||
style: textStyle ??
|
||||
theme.textTheme.labelLarge?.copyWith(
|
||||
color: theme.colorScheme.onPrimary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
|
||||
class ChoiceChips<T> extends StatelessWidget {
|
||||
final String label;
|
||||
final List<T> values;
|
||||
final T selected;
|
||||
final ValueChanged<T> onChanged;
|
||||
|
||||
final double spacing;
|
||||
final double runSpacing;
|
||||
final double labelSpacing;
|
||||
|
||||
const ChoiceChips({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.values,
|
||||
required this.selected,
|
||||
required this.onChanged,
|
||||
this.spacing = 8,
|
||||
this.runSpacing = 8,
|
||||
this.labelSpacing = 8,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: theme.textTheme.titleMedium!.copyWith(fontWeight: FontWeight.bold),
|
||||
),
|
||||
SizedBox(height: labelSpacing),
|
||||
Wrap(
|
||||
spacing: spacing,
|
||||
runSpacing: runSpacing,
|
||||
children: values.map((v) {
|
||||
final isSelected = v == selected;
|
||||
return ChoiceChip(
|
||||
selectedColor: theme.colorScheme.primary,
|
||||
backgroundColor: theme.colorScheme.onSecondary,
|
||||
showCheckmark: false,
|
||||
label: Text(
|
||||
v.toString().split('.').last,
|
||||
style: TextStyle(
|
||||
color: isSelected
|
||||
? theme.colorScheme.onSecondary
|
||||
: theme.colorScheme.inverseSurface,
|
||||
),
|
||||
),
|
||||
selected: isSelected,
|
||||
onSelected: (_) => onChanged(v),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class EmailField extends StatelessWidget {
|
||||
final TextEditingController controller;
|
||||
|
||||
final double borderRadius;
|
||||
final EdgeInsetsGeometry contentPadding;
|
||||
|
||||
const EmailField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
this.borderRadius = 12,
|
||||
this.contentPadding = const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
|
||||
return TextFormField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(
|
||||
labelText: loc.username,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(borderRadius),
|
||||
),
|
||||
contentPadding: contentPadding,
|
||||
),
|
||||
validator: (v) =>
|
||||
v == null || v.isEmpty ? loc.usernameErrorInvalid : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class HeaderWidget extends StatelessWidget {
|
||||
final bool isEditing;
|
||||
final VoidCallback? onBack;
|
||||
|
||||
final double spacing;
|
||||
final TextStyle? textStyle;
|
||||
|
||||
const HeaderWidget({
|
||||
super.key,
|
||||
required this.isEditing,
|
||||
this.onBack,
|
||||
this.spacing = 8,
|
||||
this.textStyle,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
color: theme.colorScheme.primary,
|
||||
onPressed: onBack,
|
||||
),
|
||||
SizedBox(width: spacing),
|
||||
Text(
|
||||
isEditing ? l10n.editRecipient : l10n.addRecipient,
|
||||
style: textStyle ??
|
||||
theme.textTheme.headlineSmall?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
|
||||
|
||||
class NameField extends StatelessWidget {
|
||||
final TextEditingController controller;
|
||||
|
||||
final double borderRadius;
|
||||
final EdgeInsetsGeometry contentPadding;
|
||||
|
||||
const NameField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
this.borderRadius = 12,
|
||||
this.contentPadding = const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context)!;
|
||||
|
||||
return TextFormField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(
|
||||
labelText: loc.recipientName,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(borderRadius),
|
||||
),
|
||||
contentPadding: contentPadding,
|
||||
),
|
||||
validator: (v) => v == null || v.isEmpty ? loc.enterRecipientName : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user