Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra validation for Token info application form #2408

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ui/shared/forms/validators/text.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const noWhitespaceValidator = (value: unknown) => {
if (typeof value !== 'string') {
return true;
}

if (value === '') {
return true;
}

const trimmedValue = value.replace(/\s/g, '');

return trimmedValue !== '' || 'Should contain text';
};
13 changes: 11 additions & 2 deletions ui/tokenInfo/TokenInfoForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import FormFieldAddress from 'ui/shared/forms/fields/FormFieldAddress';
import FormFieldEmail from 'ui/shared/forms/fields/FormFieldEmail';
import FormFieldText from 'ui/shared/forms/fields/FormFieldText';
import FormFieldUrl from 'ui/shared/forms/fields/FormFieldUrl';
import { noWhitespaceValidator } from 'ui/shared/forms/validators/text';

import TokenInfoFieldIconUrl from './fields/TokenInfoFieldIconUrl';
import TokenInfoFieldProjectSector from './fields/TokenInfoFieldProjectSector';
Expand Down Expand Up @@ -101,6 +102,14 @@ const TokenInfoForm = ({ address, tokenName, application, onSubmit }: Props) =>
}
}, [ formState.isValid, formState.submitCount ]);

const nonWhitespaceFieldRules = React.useMemo(() => {
return {
validate: {
no_whitespace: noWhitespaceValidator,
},
};
}, []);

if (configQuery.isError) {
return <DataFetchAlert/>;
}
Expand All @@ -126,7 +135,7 @@ const TokenInfoForm = ({ address, tokenName, application, onSubmit }: Props) =>
<FormFieldEmail<Fields> name="requester_email" isRequired placeholder="Requester email" { ...fieldProps }/>

<TokenInfoFormSectionHeader>Project info</TokenInfoFormSectionHeader>
<FormFieldText<Fields> name="project_name" placeholder="Project name" { ...fieldProps }/>
<FormFieldText<Fields> name="project_name" placeholder="Project name" { ...fieldProps } rules={ nonWhitespaceFieldRules }/>
<TokenInfoFieldProjectSector { ...fieldProps } config={ configQuery.data.projectSectors }/>
<FormFieldEmail<Fields> name="project_email" isRequired placeholder="Official project email address" { ...fieldProps }/>
<FormFieldUrl<Fields> name="project_website" isRequired placeholder="Official project website" { ...fieldProps }/>
Expand All @@ -141,7 +150,7 @@ const TokenInfoForm = ({ address, tokenName, application, onSubmit }: Props) =>
isRequired
placeholder="Project description"
maxH="160px"
rules={{ maxLength: 300 }}
rules={{ maxLength: 300, ...nonWhitespaceFieldRules }}
asComponent="Textarea"
{ ...fieldProps }
/>
Expand Down