Skip to content

Commit

Permalink
TF-3181 Handle on click contact support
Browse files Browse the repository at this point in the history
  • Loading branch information
dab246 authored and hoangdat committed Dec 12, 2024
1 parent 01d2a9b commit 7a6a02f
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 6 deletions.
38 changes: 38 additions & 0 deletions lib/features/base/mixin/contact_support_mixin.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

import 'package:core/utils/app_logger.dart';
import 'package:jmap_dart_client/jmap/mail/email/email_address.dart';
import 'package:model/extensions/contact_support_capability_extension.dart';
import 'package:model/support/contact_support_capability.dart';
import 'package:tmail_ui_user/features/email/presentation/model/composer_arguments.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/mailbox_dashboard_controller.dart';
import 'package:tmail_ui_user/main/utils/app_utils.dart';

typedef OnTapContactSupportAction = Function(ContactSupportCapability contactSupport);

mixin ContactSupportMixin {

void onGetHelpOrReportBug(
ContactSupportCapability contactSupport,
MailboxDashBoardController mailboxDashBoardController,
) {
log('ContactSupportMixin::onGetHelpOrReportBug:contactSupport = $contactSupport');
if (contactSupport.isMailAddressSupported) {
_handleMailAddress(contactSupport.supportMailAddress!, mailboxDashBoardController);
} else if (contactSupport.isHttpLinkSupported) {
_handleHttpLink(contactSupport.httpLink!);
}
}

void _handleMailAddress(
String mailAddress,
MailboxDashBoardController mailboxDashBoardController,
) {
mailboxDashBoardController.goToComposer(
ComposerArguments.fromEmailAddress(EmailAddress(null, mailAddress)),
);
}

void _handleHttpLink(String httpLink) {
AppUtils.launchLink(httpLink);
}
}
4 changes: 3 additions & 1 deletion lib/features/mailbox/presentation/mailbox_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import 'package:model/model.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';
import 'package:rxdart/transformers.dart';
import 'package:tmail_ui_user/features/base/base_mailbox_controller.dart';
import 'package:tmail_ui_user/features/base/mixin/contact_support_mixin.dart';
import 'package:tmail_ui_user/features/base/mixin/mailbox_action_handler_mixin.dart';
import 'package:tmail_ui_user/features/composer/domain/state/save_email_as_drafts_state.dart';
import 'package:tmail_ui_user/features/composer/domain/state/send_email_state.dart';
Expand Down Expand Up @@ -100,7 +101,8 @@ import 'package:tmail_ui_user/main/routes/route_navigation.dart';
import 'package:tmail_ui_user/main/routes/route_utils.dart';
import 'package:tmail_ui_user/main/utils/ios_sharing_manager.dart';

class MailboxController extends BaseMailboxController with MailboxActionHandlerMixin {
class MailboxController extends BaseMailboxController
with MailboxActionHandlerMixin, ContactSupportMixin {

final mailboxDashBoardController = Get.find<MailboxDashBoardController>();
final isMailboxListScrollable = false.obs;
Expand Down
6 changes: 5 additions & 1 deletion lib/features/mailbox/presentation/mailbox_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ class MailboxView extends BaseMailboxView {
fontWeight: FontWeight.w500,
color: AppColor.primaryColor,
),
onTapActionCallback: () {},
onTapActionCallback: () =>
controller.onGetHelpOrReportBug(
controller.contactSupportCapability!,
controller.mailboxDashBoardController,
),
),
),
],
Expand Down
6 changes: 5 additions & 1 deletion lib/features/mailbox/presentation/mailbox_view_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ class MailboxView extends BaseMailboxView {
fontWeight: FontWeight.w500,
color: AppColor.primaryColor,
),
onTapActionCallback: () {},
onTapActionCallback: () =>
controller.onGetHelpOrReportBug(
controller.contactSupportCapability!,
controller.mailboxDashBoardController,
),
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import 'package:pointer_interceptor/pointer_interceptor.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
import 'package:rxdart/transformers.dart';
import 'package:tmail_ui_user/features/base/action/ui_action.dart';
import 'package:tmail_ui_user/features/base/mixin/contact_support_mixin.dart';
import 'package:tmail_ui_user/features/base/reloadable/reloadable_controller.dart';
import 'package:tmail_ui_user/features/composer/domain/exceptions/set_method_exception.dart';
import 'package:tmail_ui_user/features/composer/domain/extensions/email_request_extension.dart';
Expand Down Expand Up @@ -172,7 +173,8 @@ import 'package:tmail_ui_user/main/utils/email_receive_manager.dart';
import 'package:tmail_ui_user/main/utils/ios_notification_manager.dart';
import 'package:uuid/uuid.dart';

class MailboxDashBoardController extends ReloadableController with UserSettingPopupMenuMixin {
class MailboxDashBoardController extends ReloadableController
with UserSettingPopupMenuMixin, ContactSupportMixin {

final RemoveEmailDraftsInteractor _removeEmailDraftsInteractor = Get.find<RemoveEmailDraftsInteractor>();
final EmailReceiveManager _emailReceiveManager = Get.find<EmailReceiveManager>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ class MailboxDashBoardView extends BaseMailboxDashBoardView {
onShowAppDashboardAction: controller.showAppDashboardAction,
onTapApplicationLogoAction: controller.redirectToInboxAction,
onTapAvatarAction: (position) => controller.handleClickAvatarAction(context, position),
onTapContactSupportAction: (contactSupport) =>
controller.onGetHelpOrReportBug(
contactSupport,
controller,
),
);
}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:core/presentation/views/button/tmail_button_widget.dart';
import 'package:core/presentation/views/image/avatar_builder.dart';
import 'package:flutter/material.dart';
import 'package:model/support/contact_support_capability.dart';
import 'package:tmail_ui_user/features/base/mixin/contact_support_mixin.dart';
import 'package:tmail_ui_user/features/base/widget/application_logo_with_text_widget.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/controller/app_grid_dashboard_controller.dart';
import 'package:tmail_ui_user/features/mailbox_dashboard/presentation/styles/navigation_bar_style.dart';
Expand All @@ -22,6 +23,7 @@ class NavigationBarWidget extends StatelessWidget {
final VoidCallback? onTapApplicationLogoAction;
final VoidCallback? onShowAppDashboardAction;
final OnTapAvatarActionWithPositionClick? onTapAvatarAction;
final OnTapContactSupportAction? onTapContactSupportAction;

const NavigationBarWidget({
super.key,
Expand All @@ -33,6 +35,7 @@ class NavigationBarWidget extends StatelessWidget {
this.onShowAppDashboardAction,
this.onTapApplicationLogoAction,
this.onTapAvatarAction,
this.onTapContactSupportAction,
});

@override
Expand Down Expand Up @@ -69,7 +72,7 @@ class NavigationBarWidget extends StatelessWidget {
backgroundColor: Colors.transparent,
margin: const EdgeInsetsDirectional.only(end: 8),
tooltipMessage: AppLocalizations.of(context).getHelpOrReportABug,
onTapActionCallback: () {},
onTapActionCallback: () => onTapContactSupportAction?.call(contactSupportCapability!),
),
if (AppConfig.appGridDashboardAvailable && appGridController != null)
Padding(
Expand Down Expand Up @@ -109,7 +112,7 @@ class NavigationBarWidget extends StatelessWidget {
backgroundColor: Colors.transparent,
margin: const EdgeInsetsDirectional.only(end: 8),
tooltipMessage: AppLocalizations.of(context).getHelpOrReportABug,
onTapActionCallback: () {},
onTapActionCallback: () => onTapContactSupportAction?.call(contactSupportCapability!),
),
if (AppConfig.appGridDashboardAvailable && appGridController != null)
Padding(
Expand Down
11 changes: 11 additions & 0 deletions model/lib/extensions/contact_support_capability_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

import 'package:model/support/contact_support_capability.dart';

extension ContactSupportCapabilityExtension on ContactSupportCapability {

bool get isMailAddressSupported =>
supportMailAddress?.trim().isNotEmpty == true;

bool get isHttpLinkSupported =>
httpLink?.trim().isNotEmpty == true;
}
1 change: 1 addition & 0 deletions model/lib/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export 'extensions/properties_extension.dart';
export 'extensions/session_extension.dart';
export 'extensions/username_extension.dart';
export 'extensions/utc_date_extension.dart';
export 'extensions/contact_support_capability_extension.dart';
// Identity
export 'identity/identity_request_dto.dart';
export 'mailbox/expand_mode.dart';
Expand Down
100 changes: 100 additions & 0 deletions test/features/session/session_extensions_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:jmap_dart_client/jmap/core/session/session.dart';
import 'package:jmap_dart_client/jmap/core/state.dart';
import 'package:jmap_dart_client/jmap/core/unsigned_int.dart';
import 'package:jmap_dart_client/jmap/core/user_name.dart';
import 'package:model/support/contact_support_capability.dart';
import 'package:tmail_ui_user/features/home/domain/extensions/session_extensions.dart';

import '../../fixtures/account_fixtures.dart';
Expand Down Expand Up @@ -102,4 +103,103 @@ void main() {
expect(result, isNull);
});
});

group('getContactSupportCapability::test', () {
test('SHOULD return ContactSupportCapability WHEN ContactSupportCapability is available', () {
// Arrange
final contactSupportCapability = ContactSupportCapability(
supportMailAddress: '[email protected]',
httpLink: 'https://contact.support',
);
final session = Session(
{
SessionExtensions.linagoraContactSupportCapability: contactSupportCapability
},
{
AccountFixtures.aliceAccountId: Account(
AccountName('Alice'),
true,
false,
{
SessionExtensions.linagoraContactSupportCapability: contactSupportCapability
},
)
},
{},
UserName(''),
Uri(),
Uri(),
Uri(),
Uri(),
State(''),
);

// Act
final result = session.getContactSupportCapability(AccountFixtures.aliceAccountId);

// Assert
expect(result?.supportMailAddress, equals(contactSupportCapability.supportMailAddress));
expect(result?.httpLink, equals(contactSupportCapability.httpLink));
});

test('SHOULD return null WHEN ContactSupportCapability is not available', () {
// Arrange
final session = Session(
{
SessionExtensions.linagoraContactSupportCapability: EmptyCapability()
},
{
AccountFixtures.aliceAccountId: Account(
AccountName('Alice'),
true,
false,
{
SessionExtensions.linagoraContactSupportCapability: EmptyCapability()
},
)
},
{},
UserName(''),
Uri(),
Uri(),
Uri(),
Uri(),
State(''),
);

// Act
final result = session.getContactSupportCapability(AccountFixtures.aliceAccountId);

// Assert
expect(result, isNull);
});

test('SHOULD return null WHEN ContactSupportCapability is not supported', () {
// Arrange
final session = Session(
{},
{
AccountFixtures.aliceAccountId: Account(
AccountName('Alice'),
true,
false,
{},
)
},
{},
UserName(''),
Uri(),
Uri(),
Uri(),
Uri(),
State(''),
);

// Act
final result = session.getContactSupportCapability(AccountFixtures.aliceAccountId);

// Assert
expect(result, isNull);
});
});
}

0 comments on commit 7a6a02f

Please sign in to comment.