Skip to content

Commit

Permalink
Merge pull request #51 from glific/feature/update-validations
Browse files Browse the repository at this point in the history
Update validations for router components
  • Loading branch information
pankaj-ag authored Sep 2, 2021
2 parents 4900490 + 1bee533 commit 66f7beb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createResultNameInput } from 'components/flow/routers/widgets';
import TextInputElement from 'components/form/textinput/TextInputElement';
import TypeList from 'components/nodeeditor/TypeList';
import { FormState, StringEntry } from 'store/nodeEditor';
import { Alphanumeric, Required, StartIsNonNumeric, validate } from 'store/validators';
import { LowerCaseAlphaNumeric, Required, StartIsNonNumeric, validate } from 'store/validators';
import i18n from 'config/i18n';

// TODO: Remove use of Function
Expand Down Expand Up @@ -45,7 +45,7 @@ export default class ExpressionRouterForm extends React.Component<

private handleUpdateResultName(value: string): void {
const resultName = validate(i18n.t('forms.result_name', 'Result Name'), value, [
Alphanumeric,
LowerCaseAlphaNumeric,
StartIsNonNumeric
]);
this.setState({
Expand Down
4 changes: 2 additions & 2 deletions src/components/flow/routers/response/ResponseRouterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createResultNameInput } from 'components/flow/routers/widgets';
import TimeoutControl from 'components/form/timeout/TimeoutControl';
import TypeList from 'components/nodeeditor/TypeList';
import { FormState, StringEntry } from 'store/nodeEditor';
import { Alphanumeric, StartIsNonNumeric, validate } from 'store/validators';
import { LowerCaseAlphaNumeric, StartIsNonNumeric, validate } from 'store/validators';
import { WAIT_LABEL } from 'components/flow/routers/constants';
import i18n from 'config/i18n';

Expand Down Expand Up @@ -47,7 +47,7 @@ export default class ResponseRouterForm extends React.Component<

private handleUpdateResultName(value: string): void {
const resultName = validate(i18n.t('forms.result_name', 'Result Name'), value, [
Alphanumeric,
LowerCaseAlphaNumeric,
StartIsNonNumeric
]);
this.setState({
Expand Down
9 changes: 7 additions & 2 deletions src/components/flow/routers/result/ResultRouterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import TypeList from 'components/nodeeditor/TypeList';
import * as React from 'react';
import { Asset } from 'store/flowContext';
import { FormEntry, FormState, mergeForm, StringEntry } from 'store/nodeEditor';
import { Alphanumeric, shouldRequireIf, StartIsNonNumeric, validate } from 'store/validators';
import {
LowerCaseAlphaNumeric,
shouldRequireIf,
StartIsNonNumeric,
validate
} from 'store/validators';

import {
DELIMITER_OPTIONS,
Expand Down Expand Up @@ -61,7 +66,7 @@ export default class ResultRouterForm extends React.Component<

private handleUpdateResultName(value: string): void {
const resultName = validate(i18n.t('forms.result_name', 'Result Name'), value, [
Alphanumeric,
LowerCaseAlphaNumeric,
StartIsNonNumeric
]);
this.setState({
Expand Down
4 changes: 2 additions & 2 deletions src/components/flow/routers/webhook/WebhookRouterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import TypeList from 'components/nodeeditor/TypeList';
import * as React from 'react';
import { FormEntry, FormState, mergeForm, StringEntry, ValidationFailure } from 'store/nodeEditor';
import {
Alphanumeric,
LowerCaseAlphaNumeric,
Required,
shouldRequireIf,
StartIsNonNumeric,
Expand Down Expand Up @@ -167,7 +167,7 @@ export default class WebhookRouterForm extends React.Component<
private handleUpdateResultName(value: string): void {
const resultName = validate(i18n.t('forms.result_name', 'Result Name'), value, [
Required,
Alphanumeric,
LowerCaseAlphaNumeric,
StartIsNonNumeric
]);
this.setState({
Expand Down
4 changes: 4 additions & 0 deletions src/store/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,7 @@ export const ValidURL = fromRegex(REGEX_URL, 'is not a valid URL');
export const Numeric = fromRegex(/^([-+]?((\.\d+)|(\d+)(\.\d+)?)$)/, 'must be a number');
export const Alphanumeric = fromRegex(/^[a-z\d\-_\s]+$/i, 'can only have letters and numbers');
export const NumOrExp = fromRegex(/^@.*$|^([-+]?((\.\d+)|(\d+)(\.\d+)?)$)/, 'must be a number');
export const LowerCaseAlphaNumeric = fromRegex(
/^[a-z0-9_]+$/,
'must be a lowercase alphanumeric character with no spaces'
);

0 comments on commit 66f7beb

Please sign in to comment.