Skip to content

Commit

Permalink
feat(admin): force lowercase slug when creating an org [EP-2755] (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-qc committed Oct 16, 2020
1 parent 4077f79 commit 92b0a4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/earth-admin/src/pages-client/organizations/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
Input,
setupErrors,
Spinner,
upperNumericDashesRule,
lowerNumericDashesRule,
validEmailRule,
} from '@marapp/earth-shared';

Expand Down Expand Up @@ -109,7 +109,7 @@ export function NewOrganization(props: IProps) {
ref={register({
required: 'Slug name is required',
validate: {
upperNumericDashesRule: upperNumericDashesRule(),
lowerNumericDashesRule: lowerNumericDashesRule(),
},
})}
/>
Expand Down
9 changes: 9 additions & 0 deletions packages/earth-shared/src/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ const upperNumericDashes = (value: string): boolean => {
return regex.test(value);
};

const lowerNumericDashes = (value: string): boolean => {
const regex = RegExp('^[a-z0-9](-?[a-z0-9])*$');
return regex.test(value);
};

const alphaNumericDashes = (value: string): boolean => {
const regex = RegExp(/^[a-z0-9](-?[a-z0-9])*$/gi);
return regex.test(value);
Expand All @@ -82,6 +87,10 @@ export const upperNumericDashesRule = (
errorMessage: string = 'Only upercase alphanumeric characters and hyphens allowed.'
) => compose(maybeShowError(errorMessage), upperNumericDashes);

export const lowerNumericDashesRule = (
errorMessage: string = 'Only lowercase alphanumeric characters and hyphens allowed.'
) => compose(maybeShowError(errorMessage), lowerNumericDashes);

export const alphaNumericDashesRule = (
errorMessage: string = 'Only lowercase alphanumeric characters and hyphens allowed.'
) => compose(maybeShowError(errorMessage), alphaNumericDashes);
Expand Down

0 comments on commit 92b0a4e

Please sign in to comment.