TF-536 Add presentation layer for edit identity

This commit is contained in:
dab246
2022-05-06 15:13:37 +07:00
committed by Dat H. Pham
parent 15de506b97
commit 5cc5ff9761
12 changed files with 246 additions and 40 deletions
@@ -14,6 +14,7 @@ import 'package:tmail_ui_user/features/mailbox_creator/domain/model/verification
import 'package:tmail_ui_user/features/mailbox_creator/domain/state/verify_name_view_state.dart';
import 'package:tmail_ui_user/features/mailbox_creator/domain/usecases/verify_name_interactor.dart';
import 'package:tmail_ui_user/features/mailbox_creator/presentation/extensions/validator_failure_extension.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/model/identity_action_type.dart';
import 'package:tmail_ui_user/main/routes/route_navigation.dart';
class IdentityCreatorController extends BaseController {
@@ -36,6 +37,8 @@ class IdentityCreatorController extends BaseController {
AccountId? accountId;
UserProfile? userProfile;
IdentityActionType? actionType;
Identity? identity;
String? _nameIdentity;
String? _contentHtmlEditor;
@@ -53,7 +56,11 @@ class IdentityCreatorController extends BaseController {
@override
void onReady() {
_getArguments();
_setDefaultValueForIdentity();
if (actionType == IdentityActionType.edit && identity != null) {
_setUpValueFromIdentity();
} else {
_setDefaultValueForIdentity();
}
super.onReady();
}
@@ -77,6 +84,8 @@ class IdentityCreatorController extends BaseController {
if (arguments is IdentityCreatorArguments) {
accountId = arguments.accountId;
userProfile = arguments.userProfile;
actionType = arguments.actionType;
identity = arguments.identity;
}
}
@@ -86,13 +95,54 @@ class IdentityCreatorController extends BaseController {
replyToOfIdentity.value = noneEmailAddress;
if (userProfile != null && userProfile?.email.isNotEmpty == true) {
final userEmailAddress = EmailAddress(userProfile!.email, userProfile!.email);
final userEmailAddress = EmailAddress(null, userProfile!.email);
listEmailAddressDefault.add(userEmailAddress);
listEmailAddressOfReplyTo.add(userEmailAddress);
emailOfIdentity.value = userEmailAddress;
}
}
void _setUpValueFromIdentity() {
Set<EmailAddress> listEmailAddress = {};
listEmailAddress.add(noneEmailAddress);
_nameIdentity = identity?.name ?? '';
inputNameIdentityController.text = identity?.name ?? '';
if (identity?.replyTo?.isNotEmpty == true) {
replyToOfIdentity.value = identity!.replyTo!.first;
listEmailAddress.add(identity!.replyTo!.first);
} else {
replyToOfIdentity.value = noneEmailAddress;
}
if (identity?.bcc?.isNotEmpty == true) {
bccOfIdentity.value = identity!.bcc!.first;
listEmailAddress.add(identity!.bcc!.first);
} else {
bccOfIdentity.value = noneEmailAddress;
}
if (identity?.email?.isNotEmpty == true) {
emailOfIdentity.value = EmailAddress(null, identity?.email!);
listEmailAddress.add(EmailAddress(null, identity?.email!));
}
listEmailAddressOfReplyTo.value = listEmailAddress.toList();
listEmailAddressDefault.value = listEmailAddress
.where((emailAddress) => emailAddress != noneEmailAddress)
.toList();
if (identity?.textSignature?.value.isNotEmpty == true) {
signaturePlainEditorController.text = identity?.textSignature?.value ?? '';
}
if (identity?.htmlSignature?.value.isNotEmpty == true) {
updateContentHtmlEditor(identity?.htmlSignature?.value ?? '');
signatureHtmlEditorController.setText(identity?.htmlSignature?.value ?? '');
}
}
void selectSignatureType(SignatureType newSignatureType) {
signatureType.value = newSignatureType;
}
@@ -7,6 +7,7 @@ import 'package:tmail_ui_user/features/identity_creator/presentation/identity_cr
import 'package:tmail_ui_user/features/identity_creator/presentation/model/signature_type.dart';
import 'package:tmail_ui_user/features/identity_creator/presentation/widgets/identity_drop_list_field_builder.dart';
import 'package:tmail_ui_user/features/identity_creator/presentation/widgets/identity_input_field_builder.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/model/identity_action_type.dart';
import 'package:tmail_ui_user/main/localizations/app_localizations.dart';
class IdentityCreatorView extends GetWidget<IdentityCreatorController> {
@@ -24,9 +25,16 @@ class IdentityCreatorView extends GetWidget<IdentityCreatorController> {
backgroundColor: Colors.white,
body: SafeArea(
child: ClipRRect(
borderRadius: _responsiveUtils.isMobile(context) && _responsiveUtils.isPortrait(context)
? const BorderRadius.only(topRight: Radius.circular(14), topLeft: Radius.circular(14))
: const BorderRadius.all(Radius.zero),
borderRadius: const BorderRadius.only(topRight: Radius.circular(14), topLeft: Radius.circular(14)),
child: _buildBodyMobile(context)
),
)
),
landscapeMobile: Scaffold(
backgroundColor: Colors.white,
body: SafeArea(
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.zero),
child: _buildBodyMobile(context)
),
)
@@ -418,29 +426,34 @@ class IdentityCreatorView extends GetWidget<IdentityCreatorController> {
)),
const SizedBox(height: 24),
Container(
alignment: Alignment.centerRight,
alignment: Alignment.center,
color: Colors.white,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
buildTextButton(
AppLocalizations.of(context).cancel,
textStyle: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 17,
color: AppColor.colorTextButton),
backgroundColor: AppColor.emailAddressChipColor,
width: 128,
height: 44,
radius: 10,
onTap: () => controller.closeView(context)),
Expanded(
child: buildTextButton(
AppLocalizations.of(context).cancel,
textStyle: const TextStyle(
fontWeight: FontWeight.w500,
fontSize: 17,
color: AppColor.colorTextButton),
backgroundColor: AppColor.emailAddressChipColor,
width: 128,
height: 44,
radius: 10,
onTap: () => controller.closeView(context)),
),
const SizedBox(width: 12),
buildTextButton(
AppLocalizations.of(context).create,
width: 128,
height: 44,
radius: 10,
onTap: () => controller.createNewIdentity(context)),
Expanded(
child: Obx(() => buildTextButton(
controller.actionType == IdentityActionType.create
? AppLocalizations.of(context).create
: AppLocalizations.of(context).save,
width: 128,
height: 44,
radius: 10,
onTap: () => controller.createNewIdentity(context))),
),
]
),
)
@@ -1,14 +1,25 @@
import 'package:equatable/equatable.dart';
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/identities/identity.dart';
import 'package:model/model.dart';
import 'package:tmail_ui_user/features/manage_account/presentation/model/identity_action_type.dart';
class IdentityCreatorArguments with EquatableMixin {
final AccountId accountId;
final UserProfile userProfile;
final IdentityActionType actionType;
final Identity? identity;
IdentityCreatorArguments(this.accountId, this.userProfile);
IdentityCreatorArguments(
this.accountId,
this.userProfile,
{
this.identity,
this.actionType = IdentityActionType.create
}
);
@override
List<Object?> get props => [accountId, userProfile];
List<Object?> get props => [accountId, userProfile, identity, actionType];
}