Skip to content

Commit

Permalink
fixup! TW-2046 Added name validation in group creation
Browse files Browse the repository at this point in the history
  • Loading branch information
KhaledNjim committed Nov 13, 2024
1 parent 30252e7 commit 356e2a5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 28 deletions.
5 changes: 2 additions & 3 deletions lib/domain/exception/verify_name_exception.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import 'package:equatable/equatable.dart';

abstract class VerifyNameException extends Equatable implements Exception {
static const spaceOnlyWithinName = 'The name cannot contain only spaces';
static const nameWithOnlySpace = 'The name cannot contain only spaces';

final String? message;

const VerifyNameException(this.message);

@override
Expand All @@ -13,5 +12,5 @@ abstract class VerifyNameException extends Equatable implements Exception {

class NameWithSpaceOnlyException extends VerifyNameException {
const NameWithSpaceOnlyException()
: super(VerifyNameException.spaceOnlyWithinName);
: super(VerifyNameException.nameWithOnlySpace);
}
7 changes: 4 additions & 3 deletions lib/pages/new_group/new_group_chat_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:fluffychat/app_state/success.dart';
import 'package:fluffychat/domain/app_state/room/create_new_group_chat_state.dart';
import 'package:fluffychat/domain/app_state/room/upload_content_state.dart';
import 'package:fluffychat/domain/app_state/validator/verify_name_view_state.dart';
import 'package:fluffychat/domain/model/extensions/validator_failure_extension.dart';
import 'package:fluffychat/domain/model/verification/name_with_space_only_validator.dart';
import 'package:fluffychat/domain/usecase/verify_name_interactor.dart';
import 'package:fluffychat/pages/new_group/new_group_chat_info_view.dart';
Expand Down Expand Up @@ -316,17 +317,17 @@ class NewGroupChatInfoController extends State<NewGroupChatInfo>
}

String? getErrorMessage(String content) {
verifyNameInteractor.execute(content, [NameWithSpaceOnlyValidator()]).fold(
return verifyNameInteractor
.execute(content, [NameWithSpaceOnlyValidator()]).fold(
(failure) {
if (failure is VerifyNameFailure) {
return failure.exception.getMessage(context);
return failure.getMessage(context);
} else {
return null;
}
},
(success) => null,
);
return null;
}

@override
Expand Down
56 changes: 35 additions & 21 deletions lib/pages/new_group/new_group_chat_info_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -201,29 +201,43 @@ class NewGroupChatInfoView extends StatelessWidget {
child: ValueListenableBuilder(
valueListenable: newGroupInfoController.createRoomStateNotifier,
builder: (context, value, child) {
return TextField(
controller: newGroupInfoController.groupNameTextEditingController,
focusNode: newGroupInfoController.groupNameFocusNode,
enabled: !newGroupInfoController.isCreatingRoom,
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide:
BorderSide(color: Theme.of(context).colorScheme.shadow),
),
errorText: newGroupInfoController.getErrorMessage(
newGroupInfoController.groupNameTextEditingController.text,
),
labelText: L10n.of(context)!.widgetName,
labelStyle: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
return ValueListenableBuilder(
valueListenable:
newGroupInfoController.groupNameTextEditingController,
builder: (context, value, _) {
return TextField(
controller:
newGroupInfoController.groupNameTextEditingController,
focusNode: newGroupInfoController.groupNameFocusNode,
enabled: !newGroupInfoController.isCreatingRoom,
decoration: InputDecoration(
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
color: LinagoraSysColors.material().error,
),
),
hintText: L10n.of(context)!.enterGroupName,
hintStyle: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: LinagoraRefColors.material().neutral[60],
border: OutlineInputBorder(
borderSide:
BorderSide(color: Theme.of(context).colorScheme.shadow),
),
contentPadding: NewGroupChatInfoStyle.contentPadding,
),
contextMenuBuilder: mobileTwakeContextMenuBuilder,
errorText: newGroupInfoController.getErrorMessage(
newGroupInfoController.groupNameTextEditingController.text,
),
errorStyle:
TextStyle(color: LinagoraSysColors.material().error),
labelText: L10n.of(context)!.widgetName,
labelStyle: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurface,
),
hintText: L10n.of(context)!.enterGroupName,
hintStyle: Theme.of(context).textTheme.bodyLarge?.copyWith(
color: LinagoraRefColors.material().neutral[60],
),
contentPadding: NewGroupChatInfoStyle.contentPadding,
),
contextMenuBuilder: mobileTwakeContextMenuBuilder,
);
},
);
},
),
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/new_group/new_group_info_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ extension NewGroupInfoControllerExtension on NewGroupChatInfoController {
groupNameTextEditingController.addListener(() {
groupName = groupNameTextEditingController.text;
haveGroupNameNotifier.value =
groupNameTextEditingController.text.isNotEmpty;
groupNameTextEditingController.text.isNotEmpty &&
getErrorMessage(groupNameTextEditingController.text) == null;
});
}

Expand Down

0 comments on commit 356e2a5

Please sign in to comment.