Skip to content

Commit

Permalink
Introduce final form, i18n helper, validators and refactor AddEmailAd…
Browse files Browse the repository at this point in the history
…dress (coralproject#1636)

* Introduce final form, validators and refactor AddEmailAddress

* First i18n script

* Sort locales

* Add delete and copy action

* Copy over available validator translations

* Add comments

* Export validations in plugin-api

* Linting

* yarn.lock

* Sort locales

* Drop unused translations

* Add translations for validators

* Add action drop-unused

* Add comments

* Add note about limitation

* Fix desc
  • Loading branch information
cvle authored and wyattjoh committed Jun 5, 2018
1 parent 6b6e597 commit 41fab3e
Show file tree
Hide file tree
Showing 31 changed files with 4,910 additions and 4,582 deletions.
91 changes: 91 additions & 0 deletions client/coral-framework/lib/validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import t from 'coral-framework/services/i18n';

/**
* createNotificationService returns a notification services based on pym.
* @param {func} condition callback that checks that the given argument is valid.
* @param {error} string error that is displayed when validation fails.
* @return {func} validator function
*/
export function createValidator(condition, error) {
return (v, values) => (condition(v, values) ? undefined : error);
}

/**
* composeValidators chains validators and runs them in sequence until
* one validator fails and returns an error message.
* @param {func[]} validators array of validator functions.
* @return {func} validator fuction
*/
export function composeValidators(...validators) {
return value =>
validators.reduce(
(error, validator) => error || validator(value),
undefined
);
}

/**
* required checks that the value is truthy.
* @return {func} validator fuction
*/
export const required = createValidator(v => !!v, t('validators.required'));

/**
* Confirm will check that this field has the same value as another.
* @param {string} key key of other form field to compare with.
* @param {error} string error that is displayed when validation fails.
* @return {func} validator fuction
*/
export const confirm = (key, error) =>
createValidator((v, data) => v === data[key], error);

/**
* Verify email.
* @return {func} validator fuction
*/
export const verifyEmail = createValidator(
email => /^.+@.+\..+$/.test(email),
t('validators.verify_email')
);

/**
* Confirm email.
* @param {string} key key of other form field to compare with.
* @return {func} validator fuction
*/
export const confirmEmail = key => confirm(key, t('validators.confirm_email'));

/**
* Verify password.
* @return {func} validator fuction
*/
export const verifyPassword = createValidator(
pass => /^(?=.{8,}).*$/.test(pass),
t('validators.verify_password')
);

/**
* Confirm password.
* @param {string} key key of other form field to compare with.
* @return {func} validator fuction
*/
export const confirmPassword = key =>
confirm(key, t('validators.confirm_password'));

/**
* Verify username.
* @return {func} validator fuction
*/
export const verifyUsername = createValidator(
username => /^[a-zA-Z0-9_]+$/.test(username),
t('validators.verify_username')
);

/**
* Verify organization name.
* @return {func} validator fuction
*/
export const verifyOrganizationName = createValidator(
org => /^[a-zA-Z0-9_ ]+$/.test(org),
t('validators.verify_organization_name')
);
561 changes: 284 additions & 277 deletions locales/ar.yml

Large diffs are not rendered by default.

889 changes: 447 additions & 442 deletions locales/da.yml

Large diffs are not rendered by default.

861 changes: 434 additions & 427 deletions locales/de.yml

Large diffs are not rendered by default.

900 changes: 454 additions & 446 deletions locales/en.yml

Large diffs are not rendered by default.

845 changes: 426 additions & 419 deletions locales/es.yml

Large diffs are not rendered by default.

767 changes: 386 additions & 381 deletions locales/fi_FI.yml

Large diffs are not rendered by default.

797 changes: 387 additions & 410 deletions locales/fr.yml

Large diffs are not rendered by default.

785 changes: 395 additions & 390 deletions locales/nl_NL.yml

Large diffs are not rendered by default.

698 changes: 351 additions & 347 deletions locales/pt_BR.yml

Large diffs are not rendered by default.

Loading

0 comments on commit 41fab3e

Please sign in to comment.