diff --git a/src/core/client/auth/components/SignIn.tsx b/src/core/client/auth/components/SignIn.tsx index 46dc0a910..12d2d8585 100644 --- a/src/core/client/auth/components/SignIn.tsx +++ b/src/core/client/auth/components/SignIn.tsx @@ -63,7 +63,7 @@ const SignIn: StatelessComponent = props => { Email Address = props => { {({ handleSubmit, submitError }) => (
- - + + Sign up to join the conversation - - {submitError && ( - - {submitError} - - )} - - - {({ input, meta }) => ( - + + {submitError && ( + + {submitError} + + )} + + {({ input, meta }) => ( + + Email Address + + - {meta.touched && - (meta.error || meta.submitError) && ( - - {meta.error || meta.submitError} - - )} - - )} - - - - {({ input, meta }) => ( - + + {meta.touched && + (meta.error || meta.submitError) && ( + + {meta.error || meta.submitError} + + )} + + )} + + + {({ input, meta }) => ( + + Username + + A unique identifier displayed on your comments. You may use “_” and “.” + + - {meta.touched && - (meta.error || meta.submitError) && ( - - {meta.error || meta.submitError} - - )} - - )} - - - - {({ input, meta }) => ( - + + {meta.touched && + (meta.error || meta.submitError) && ( + + {meta.error || meta.submitError} + + )} + + )} + + + {({ input, meta }) => ( + + Password + + - Must be at least 8 characters + {"Must be at least {$minLength} characters"} + + - {meta.touched && - (meta.error || meta.submitError) && ( - - {meta.error || meta.submitError} - - )} - - )} - - - - {({ input, meta }) => ( - + + {meta.touched && + (meta.error || meta.submitError) && ( + + {meta.error || meta.submitError} + + )} + + )} + + + {({ input, meta }) => ( + + Confirm Password - - Must be at least 8 characters - + + - {meta.touched && - (meta.error || meta.submitError) && ( - - {meta.error || meta.submitError} - - )} - - )} - - -
+ + {meta.touched && + (meta.error || meta.submitError) && ( + + {meta.error || meta.submitError} + + )} + + )} + + - - Already have an account? - - -
-
+ + + + } + > + + {"Already have an account? "} + + + + )} diff --git a/src/core/client/framework/lib/errors/badUserInputError.ts b/src/core/client/framework/lib/errors/badUserInputError.ts index aa5d127af..e1674ae06 100644 --- a/src/core/client/framework/lib/errors/badUserInputError.ts +++ b/src/core/client/framework/lib/errors/badUserInputError.ts @@ -1,12 +1,12 @@ import { mapValues, once } from "lodash"; import { ReactNode } from "react"; -import { VALIDATION_REQUIRED, VALIDATION_TOO_SHORT } from "../messages"; +import { VALIDATION_REQUIRED } from "../messages"; /** * ValidationError represents all possible string values * that is responded by the server. */ -type ValidationError = "TOO_SHORT"; +type ValidationError = "REQUIRED"; /** * InvalidArgsMap as responded by the server. @@ -36,7 +36,6 @@ interface BadUserInputExtension { * Map server `ValidationError` to a translation message. */ const validationMap = { - TOO_SHORT: VALIDATION_TOO_SHORT, REQUIRED: VALIDATION_REQUIRED, }; diff --git a/src/core/client/framework/lib/messages.tsx b/src/core/client/framework/lib/messages.tsx index 61c74aa4b..28beed2f4 100644 --- a/src/core/client/framework/lib/messages.tsx +++ b/src/core/client/framework/lib/messages.tsx @@ -12,9 +12,9 @@ export const VALIDATION_REQUIRED = () => (
); -export const VALIDATION_TOO_SHORT = () => ( +export const VALIDATION_TOO_SHORT = (minLength: number) => ( - This field is too short. + {"This field must contain at least {$minLength} characters."} ); @@ -24,15 +24,27 @@ export const INVALID_EMAIL = () => ( ); -export const INVALID_USERNAME = () => ( - - Please enter a valid username. +export const INVALID_CHARACTERS = () => ( + + Invalid characters. Try again. ); -export const INVALID_PASSWORD = () => ( - - Please enter a valid password. +export const USERNAME_TOO_SHORT = (minLength: number) => ( + + {"Usernames must contain at least {$minLength} characters."} + +); + +export const USERNAME_TOO_LONG = (maxLength: number) => ( + + {"Usernames cannot be longer than {$maxLength} characters."} + +); + +export const PASSWORD_TOO_SHORT = (minLength: number) => ( + + {"Password must contain at least {$minLength} characters."} ); diff --git a/src/core/client/framework/lib/validation.tsx b/src/core/client/framework/lib/validation.tsx index 87e8f855c..6634e9fde 100644 --- a/src/core/client/framework/lib/validation.tsx +++ b/src/core/client/framework/lib/validation.tsx @@ -1,9 +1,11 @@ import { ReactNode } from "react"; import { + INVALID_CHARACTERS, INVALID_EMAIL, - INVALID_PASSWORD, - INVALID_USERNAME, + PASSWORD_TOO_SHORT, PASSWORDS_DO_NOT_MATCH, + USERNAME_TOO_LONG, + USERNAME_TOO_SHORT, VALIDATION_REQUIRED, } from "./messages"; @@ -47,19 +49,44 @@ export const validateEmail = createValidator( ); /** - * validateUsername is a Validator that checks that the value is a valid username. + * validateUsernameCharacters is a Validator that checks that the username only contains valid characters. */ -export const validateUsername = createValidator( +export const validateUsernameCharacters = createValidator( v => /^[a-zA-Z0-9_.]+$/.test(v), - INVALID_USERNAME() + INVALID_CHARACTERS() +); + +/** + * validateUsernameMinLength is a Validator that checks that the username has a min length of characters + */ +export const validateUsernameMinLength = createValidator( + v => v.length >= 3, + USERNAME_TOO_SHORT(3) +); + +/** + * validateUsernameMaxLength is a Validator that checks that the username has a max length of characters + */ +export const validateUsernameMaxLength = createValidator( + v => v.length <= 20, + USERNAME_TOO_LONG(20) +); + +/** + * validateUsername is a Validator that checks that the username is valid. + */ +export const validateUsername = composeValidators( + validateUsernameCharacters, + validateUsernameMinLength, + validateUsernameMaxLength ); /** * validateUsername is a Validator that checks that the value is a valid username. */ export const validatePassword = createValidator( - v => /^(?=.{8,}).*$/.test(v), - INVALID_PASSWORD() + v => v.length >= 8, + PASSWORD_TOO_SHORT(8) ); /**s diff --git a/src/locales/en-US/auth.ftl b/src/locales/en-US/auth.ftl index 87e1649ae..9b8bb1d80 100644 --- a/src/locales/en-US/auth.ftl +++ b/src/locales/en-US/auth.ftl @@ -7,7 +7,7 @@ signIn-signInToJoinHeader = Sign in to join the conversation signIn-signInAndJoinButton = Sign in and join the conversation signIn-emailAddressLabel = Email Address -signIn-emailAddressTextfield = +signIn-emailAddressTextField = .placeholder = Email Address signIn-passwordLabel = Password @@ -17,3 +17,29 @@ signIn-passwordTextfield = signIn-forgotYourPassword = Forgot your password? signIn-noAccountSignUp = Don't have an account? + +## Sign Up + +signUp-signUpToJoinHeader = Sign up to join the conversation + +signUp-signUpAndJoinButton = Sign up and join the conversation + +signUp-emailAddressLabel = Email Address +signUp-emailAddressTextField + .placeholder = Email Address + +signUp-usernameLabel = Username +signUp-usernameDescription = A unique identifier displayed on your comments. You may use “_” and “.” +signUp-usernameTextField + .placeholder = Username + +signUp-passwordLabel = Password +signUp-passwordDescription = Must be at least {$minLength} characters +signUp-passwordTextField + .placeholder = Password + +signUp-confirmPasswordLabel = Confirm Password +signUp-confirmPasswordTextField + .placeholder = Confirm Password + +signUp-accountAvailableSignIn = Already have an account? diff --git a/src/locales/en-US/framework.ftl b/src/locales/en-US/framework.ftl index 555637497..42e6d2751 100644 --- a/src/locales/en-US/framework.ftl +++ b/src/locales/en-US/framework.ftl @@ -5,6 +5,13 @@ ## Validation framework-validation-required = This field is required. +framework-validation-tooShort = The field must contain at least {$minLength} characters. +framework-validation-passwordTooShort = Password must contain at least {$minLength} characters. +framework-validation-usernameTooShort = Username must contain at least {$minLength} characters. +framework-validation-usernameTooLong = Usernames cannot be longer than {$maxLength} characters. +framework-validation-invalidCharacters = Invalid characters. Try again. +framework-validation-invalidEmail = Please enter a valid email address. +framework-validation-passwordsDoNotMatch = Passwords do not match. Try again. framework-timeago-time = { $value }