-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
275 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ export const emailPlaceHolder = "[email protected]"; | |
|
||
interface EmailInputProps { | ||
required: boolean; | ||
autoFocus: boolean; | ||
autoFocus?: boolean; | ||
name: string; | ||
autoComplete?: "username"; | ||
helpBlock?: React.ReactNode; // help text shown above input | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,46 @@ | ||
import { emailPattern } from "./regexPatterns"; | ||
import { emailPattern, emptyStringPattern } from "./regexPatterns"; | ||
|
||
interface EmailData { | ||
email?: string; | ||
given_name?: string; | ||
surname?: string; | ||
[key: string]: any; | ||
} | ||
|
||
/** | ||
* Validate that the value is a plausible e-mail address. The returned string should be a translate() lookup key. | ||
* @param values | ||
* @returns | ||
*/ | ||
export function validateEmailInForm(values: EmailData): EmailData { | ||
export function validateSignupUserInForm(values: EmailData): EmailData { | ||
const errors: EmailData = {}; | ||
if (values !== undefined) { | ||
errors.email = validateEmailField(values.email); | ||
["email", "given_name", "surname"].forEach((inputName) => { | ||
if (!values[inputName] || emptyStringPattern.test(values[inputName])) { | ||
errors[inputName] = "required"; | ||
} | ||
}); | ||
if (values.email) { | ||
const emailError = validateEmailField(values.email); | ||
if (emailError) { | ||
errors.email = emailError; | ||
} | ||
} | ||
} | ||
|
||
return errors; | ||
} | ||
|
||
// backwards compat export | ||
export const validate = validateEmailInForm; | ||
export const validate = validateSignupUserInForm; | ||
|
||
/** | ||
* Validate that the value is a plausible e-mail address. The returned string should be a translate() lookup key. | ||
* @param values | ||
* @returns | ||
*/ | ||
export function validateEmailField(value?: string): string | undefined { | ||
if (!value) { | ||
return "required"; | ||
} | ||
if (!emailPattern.test(value)) { | ||
if (value && !emailPattern.test(value)) { | ||
return "email.invalid_email"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.