Skip to content

Commit

Permalink
chore: Revert "fix(authenticator): required phone number validator (#…
Browse files Browse the repository at this point in the history
…4106)" (#4117)

Revert "fix(authenticator): required phone number validator (#4106)"

This reverts commit eb6e68b.
  • Loading branch information
Jordan-Nelson authored Nov 13, 2023
1 parent eb6e68b commit ddafa9a
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ mixin AuthenticatorPhoneFieldMixin<FieldType extends Enum,
return phoneNumber?.ensureStartsWith('+${state.dialCode.value}');
}

String displayPhoneNumber(String? phoneNumber) {
phoneNumber = phoneNumber ?? '';
String displayPhoneNumber(String phoneNumber) {
final prefix = '+${state.dialCode.value}';
if (phoneNumber.startsWith(prefix)) {
phoneNumber = phoneNumber.substring(prefix.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,6 @@ mixin AuthenticatorUsernameField<FieldType extends Enum,
}
}

String displayPhoneNumber(String? phoneNumber) {
phoneNumber = phoneNumber ?? '';
final prefix = '+${state.dialCode.value}';
if (phoneNumber.startsWith(prefix)) {
phoneNumber = phoneNumber.substring(prefix.length);
}
return phoneNumber;
}

@override
FormFieldValidator<UsernameInput> get validator {
switch (selectedUsernameType) {
Expand All @@ -192,7 +183,7 @@ mixin AuthenticatorUsernameField<FieldType extends Enum,
isOptional: isOptional,
context: context,
inputResolver: stringResolver.inputs,
)(displayPhoneNumber(input?.username));
)(input?.username);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ import 'package:flutter/material.dart';
*/
final usernameRegex = RegExp(r'^\S+$');
final emailRegex = RegExp(r'^\S+@\S+$');

/// Regex for a valid phone number.
///
/// The "+" prefix is excluded since validation is performed against the number
/// without the prefix. That is, if the full number is "+1-123-555-7890", the
/// "+1" is dropped prior to validation.
final phoneNumberRegex = RegExp(r'^\d+$');
final phoneNumberRegex = RegExp(r'^\+\d+$');
final _codeRegex = RegExp(r'^\d{6}$');
final _uppercase = RegExp(r'[A-Z]');
final _lowercase = RegExp(r'[a-z]');
Expand Down Expand Up @@ -162,8 +156,8 @@ FormFieldValidator<String> validatePhoneNumber({
InputResolverKey.phoneNumberEmpty,
);
}
final formattedNumber = phoneNumber.trim();
if (!phoneNumberRegex.hasMatch(formattedNumber)) {
phoneNumber = phoneNumber.trim();
if (!phoneNumberRegex.hasMatch(phoneNumber)) {
return inputResolver.resolve(context, InputResolverKey.phoneNumberFormat);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ class _ConfirmSignInPhoneFieldState extends _ConfirmSignInTextFieldState
@override
FormFieldValidator<String> get validator {
return (phoneNumber) {
phoneNumber = displayPhoneNumber(phoneNumber);
phoneNumber = formatPhoneNumber(phoneNumber);
return validatePhoneNumber(
inputResolver: stringResolver.inputs,
context: context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ class _AuthenticatorPhoneFieldState<FieldType extends Enum>
@override
FormFieldValidator<String> get validator {
return (String? phoneNumber) {
phoneNumber = formatPhoneNumber(phoneNumber);
final validator = widget.validator;
if (validator != null) {
phoneNumber = formatPhoneNumber(phoneNumber);
return validator(phoneNumber);
}
phoneNumber = displayPhoneNumber(phoneNumber);
return validatePhoneNumber(
inputResolver: stringResolver.inputs,
context: context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ class _SignUpPhoneFieldState extends _SignUpTextFieldState
@override
FormFieldValidator<String> get validator {
return (phoneNumber) {
phoneNumber = displayPhoneNumber(phoneNumber);
phoneNumber = formatPhoneNumber(phoneNumber);
return validatePhoneNumber(
inputResolver: stringResolver.inputs,
context: context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,44 +118,6 @@ void main() {
},
);

testWidgets(
'displays message when submitted with empty phone number if the field is required',
(tester) async {
await tester.pumpWidget(
MockAuthenticatorApp(
initialStep: AuthenticatorStep.signUp,
signUpForm: SignUpForm.custom(
fields: [
SignUpFormField.username(),
SignUpFormField.phoneNumber(required: true),
SignUpFormField.password(),
],
),
),
);
await tester.pumpAndSettle();

final signUpPage = SignUpPage(tester: tester);

await signUpPage.submitSignUp();

await tester.pumpAndSettle();

Finder findPhoneFieldError() => find.descendant(
of: signUpPage.phoneField,
matching: find.text('Phone Number field must not be blank.'),
);

expect(findPhoneFieldError(), findsOneWidget);

await signUpPage.enterPhoneNumber('1235556789');

await signUpPage.submitSignUp();

expect(findPhoneFieldError(), findsNothing);
},
);

testWidgets(
'displays message when submitted with invalid birth date',
(tester) async {
Expand Down

0 comments on commit ddafa9a

Please sign in to comment.