Merge pull request 'Added Last Name display and made it editable' (#145) from SEND015 into main
All checks were successful
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/mntx_gateway Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
All checks were successful
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/mntx_gateway Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
Reviewed-on: #145
This commit was merged in pull request #145.
This commit is contained in:
@@ -7,50 +7,70 @@ import 'package:pweb/models/edit_state.dart';
|
||||
|
||||
class AccountNameState extends ChangeNotifier {
|
||||
AccountNameState({
|
||||
required this.initialName,
|
||||
required this.initialFirstName,
|
||||
required this.initialLastName,
|
||||
required this.errorMessage,
|
||||
required AccountProvider accountProvider,
|
||||
}) : _accountProvider = accountProvider {
|
||||
_controller = TextEditingController(text: initialName);
|
||||
_firstNameController = TextEditingController(text: initialFirstName);
|
||||
_lastNameController = TextEditingController(text: initialLastName);
|
||||
}
|
||||
|
||||
final AccountProvider _accountProvider;
|
||||
final String initialName;
|
||||
final String initialFirstName;
|
||||
final String initialLastName;
|
||||
final String errorMessage;
|
||||
|
||||
late final TextEditingController _controller;
|
||||
late final TextEditingController _firstNameController;
|
||||
late final TextEditingController _lastNameController;
|
||||
EditState _editState = EditState.view;
|
||||
String _errorText = '';
|
||||
bool _disposed = false;
|
||||
|
||||
TextEditingController get controller => _controller;
|
||||
TextEditingController get firstNameController => _firstNameController;
|
||||
TextEditingController get lastNameController => _lastNameController;
|
||||
EditState get editState => _editState;
|
||||
String get errorText => _errorText;
|
||||
bool get isEditing => _editState != EditState.view;
|
||||
bool get isSaving => _editState == EditState.saving;
|
||||
bool get isBusy => _accountProvider.isLoading || isSaving;
|
||||
String get currentName => _accountProvider.account?.name ?? initialName;
|
||||
String get currentFirstName => _accountProvider.account?.name ?? initialFirstName;
|
||||
String get currentLastName => _accountProvider.account?.lastName ?? initialLastName;
|
||||
String get currentFullName {
|
||||
final first = currentFirstName.trim();
|
||||
final last = currentLastName.trim();
|
||||
if (first.isEmpty && last.isEmpty) return '';
|
||||
if (first.isEmpty) return last;
|
||||
if (last.isEmpty) return first;
|
||||
return '$first $last';
|
||||
}
|
||||
|
||||
void startEditing() => _setState(EditState.edit);
|
||||
|
||||
void cancelEditing() {
|
||||
_controller.text = currentName;
|
||||
_firstNameController.text = currentFirstName;
|
||||
_lastNameController.text = currentLastName;
|
||||
_setError('');
|
||||
_setState(EditState.view);
|
||||
}
|
||||
|
||||
void syncName(String latestName) {
|
||||
void syncNames(String latestFirstName, String latestLastName) {
|
||||
if (isEditing) return;
|
||||
if (_controller.text != latestName) {
|
||||
_controller.text = latestName;
|
||||
if (_firstNameController.text != latestFirstName) {
|
||||
_firstNameController.text = latestFirstName;
|
||||
}
|
||||
if (_lastNameController.text != latestLastName) {
|
||||
_lastNameController.text = latestLastName;
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> save() async {
|
||||
final newName = _controller.text.trim();
|
||||
final current = currentName;
|
||||
final newFirstName = _firstNameController.text.trim();
|
||||
final newLastName = _lastNameController.text.trim();
|
||||
final currentFirst = currentFirstName;
|
||||
final currentLast = currentLastName;
|
||||
|
||||
if (newName.isEmpty || newName == current) {
|
||||
if (newFirstName.isEmpty || (newFirstName == currentFirst && newLastName == currentLast)) {
|
||||
cancelEditing();
|
||||
return false;
|
||||
}
|
||||
@@ -59,7 +79,7 @@ class AccountNameState extends ChangeNotifier {
|
||||
_setState(EditState.saving);
|
||||
|
||||
try {
|
||||
await _accountProvider.resetUsername(newName);
|
||||
await _accountProvider.resetUsername(newFirstName, lastName: newLastName);
|
||||
_setState(EditState.view);
|
||||
return true;
|
||||
} catch (_) {
|
||||
@@ -88,7 +108,8 @@ class AccountNameState extends ChangeNotifier {
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
_controller.dispose();
|
||||
_firstNameController.dispose();
|
||||
_lastNameController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user