Skip to content

Commit

Permalink
feat: Optimize validate message (#290)
Browse files Browse the repository at this point in the history
* feat: Optimize validate message

* feat: Optimize validate message
  • Loading branch information
Liam-Zhao committed Sep 11, 2023
1 parent 5e1a13d commit 35dedfd
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 48 deletions.
18 changes: 9 additions & 9 deletions src/components/clusters/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default function EditCluster() {
autoComplete: 'family-name',
value: bio,
placeholder: 'Please enter description',
helperText: bioError ? 'The length is 1-1000' : '',
helperText: bioError ? 'Fill in the characters, the length is 0-1000.' : '',
error: bioError,

onChange: (e: any) => {
Expand All @@ -128,7 +128,7 @@ export default function EditCluster() {
autoComplete: 'family-name',
placeholder: 'Please enter Location',
value: location,
helperText: locationError ? 'Maximum length is 100' : '',
helperText: locationError ? 'Fill in the characters, the length is 0-100.' : '',
error: locationError,

onChange: (e: any) => {
Expand Down Expand Up @@ -184,7 +184,7 @@ export default function EditCluster() {
name: 'idc',
placeholder: 'Please enter IDC',
error: idcError,
helperText: idcError ? 'Maximum length is 100' : '',
helperText: idcError ? 'Fill in the characters, the length is 0-100.' : '',

onKeyDown: (e: any) => {
if (e.keyCode === 13) {
Expand Down Expand Up @@ -228,7 +228,7 @@ export default function EditCluster() {
name: 'cidrs',
placeholder: 'Please enter CIDRs',
error: cidrsError,
helperText: cidrsError ? 'Maximum length is 1000' : '',
helperText: cidrsError ? 'Fill in the characters, the length is 0-1000.' : '',

onKeyDown: (e: any) => {
if (e.keyCode === 13) {
Expand Down Expand Up @@ -256,7 +256,7 @@ export default function EditCluster() {
autoComplete: 'family-name',
placeholder: 'Please enter Seed Peer load limit',
value: seed_peer_cluster_config?.load_limit,
helperText: seedPeerLoadLimitError ? 'Must be a number and range from 0-5000' : '',
helperText: seedPeerLoadLimitError ? 'Fill in the number, the length is 0-5000.' : '',
error: seedPeerLoadLimitError,

onChange: (e: any) => {
Expand Down Expand Up @@ -293,7 +293,7 @@ export default function EditCluster() {
type: 'number',
autoComplete: 'family-name',
placeholder: 'Please enter Peer load limit',
helperText: peerLoadLimitError ? 'Must be a number and range from 0-2000' : '',
helperText: peerLoadLimitError ? 'Fill in the number, the length is 0-2000.' : '',
error: peerLoadLimitError,
value: load_limit,

Expand Down Expand Up @@ -334,7 +334,7 @@ export default function EditCluster() {
autoComplete: 'family-name',
placeholder: 'Please enter Number of concurrent download pieces',
value: concurrent_piece_count,
helperText: numberOfConcurrentDownloadPiecesError ? 'Must be a number and range from 0-50' : '',
helperText: numberOfConcurrentDownloadPiecesError ? 'Fill in the number, the length is 0-50.' : '',
error: numberOfConcurrentDownloadPiecesError,

onChange: (e: any) => {
Expand Down Expand Up @@ -373,7 +373,7 @@ export default function EditCluster() {
autoComplete: 'family-name',
placeholder: 'Please enter Candidate parent limit',
value: candidate_parent_limit,
helperText: candidateParentLimitError ? 'Must be a number and range from 1-20' : '',
helperText: candidateParentLimitError ? 'Fill in the number, the length is 1-20.' : '',
error: candidateParentLimitError,

onChange: (e: any) => {
Expand Down Expand Up @@ -415,7 +415,7 @@ export default function EditCluster() {
autoComplete: 'family-name',
placeholder: 'Please enter Filter parent limit',
value: filter_parent_limit,
helperText: filterParentLimitError ? 'Must be a number and range from 10-1000' : '',
helperText: filterParentLimitError ? 'Fill in the number, the length is 10-1000.' : '',
error: filterParentLimitError,

onChange: (e: any) => {
Expand Down
22 changes: 11 additions & 11 deletions src/components/clusters/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export default function NewCluster() {
name: 'name',
autoComplete: 'family-name',
placeholder: 'Enter your name',
helperText: nameError ? 'The length is 1-40' : '',
helperText: nameError ? 'Fill in the characters, the length is 1-40.' : '',
error: nameError,

onChange: (e: any) => {
Expand All @@ -60,7 +60,7 @@ export default function NewCluster() {
setError: setNameError,

validate: (value: string) => {
const reg = /^(?=.*[A-Za-z0-9@$!%*?&._-])[A-Za-z0-9@$!%*?&._-]{1,}$/;
const reg = /^(?=.*[A-Za-z0-9@$!%*?&._-])[A-Za-z0-9@$!%*?&._-]{1,40}$/;
return reg.test(value);
},
},
Expand All @@ -71,7 +71,7 @@ export default function NewCluster() {
name: 'description',
autoComplete: 'family-name',
placeholder: 'Enter a cluster description',
helperText: bioError ? 'The length is 1-1000' : '',
helperText: bioError ? 'Fill in the characters, the length is 0-1000.' : '',
error: bioError,

onChange: (e: any) => {
Expand All @@ -96,7 +96,7 @@ export default function NewCluster() {
name: 'location',
autoComplete: 'family-name',
placeholder: 'Please enter location',
helperText: locationError ? 'Maximum length is 100' : '',
helperText: locationError ? 'Fill in the characters, the length is 0-100.' : '',
error: locationError,

onChange: (e: any) => {
Expand Down Expand Up @@ -150,7 +150,7 @@ export default function NewCluster() {
name: 'idc',
placeholder: 'Please enter IDC',
error: idcError,
helperText: idcError ? 'Maximum length is 100' : '',
helperText: idcError ? 'Fill in the characters, the length is 0-100.' : '',

onKeyDown: (e: any) => {
if (e.keyCode === 13) {
Expand Down Expand Up @@ -196,7 +196,7 @@ export default function NewCluster() {
name: 'cidrs',
placeholder: 'Please enter CIDRs',
error: cidrsError,
helperText: cidrsError ? 'Maximum length is 1000' : '',
helperText: cidrsError ? 'Fill in the characters, the length is 0-1000.' : '',

onKeyDown: (e: any) => {
if (e.keyCode === 13) {
Expand Down Expand Up @@ -225,7 +225,7 @@ export default function NewCluster() {
autoComplete: 'family-name',
placeholder: 'Please enter Seed Peer load limit',
defaultValue: 300,
helperText: seedPeerLoadLimitError ? 'Must be a number and range from 0-5000' : '',
helperText: seedPeerLoadLimitError ? 'Fill in the number, the length is 0-5000.' : '',
error: seedPeerLoadLimitError,

onChange: (e: any) => {
Expand Down Expand Up @@ -260,7 +260,7 @@ export default function NewCluster() {
autoComplete: 'family-name',
placeholder: 'Please enter Peer load limit',
defaultValue: 50,
helperText: peerLoadLimitError ? 'Must be a number and range from 0-2000' : '',
helperText: peerLoadLimitError ? 'Fill in the number, the length is 0-2000.' : '',
error: peerLoadLimitError,

onChange: (e: any) => {
Expand Down Expand Up @@ -297,7 +297,7 @@ export default function NewCluster() {
autoComplete: 'family-name',
placeholder: 'Please enter Number of concurrent download pieces',
defaultValue: 4,
helperText: numberOfConcurrentDownloadPiecesError ? 'Must be a number and range from 0-2000' : '',
helperText: numberOfConcurrentDownloadPiecesError ? 'Fill in the number, the length is 0-50.' : '',
error: numberOfConcurrentDownloadPiecesError,

onChange: (e: any) => {
Expand Down Expand Up @@ -332,7 +332,7 @@ export default function NewCluster() {
autoComplete: 'family-name',
placeholder: 'Please enter Candidate parent limit',
defaultValue: 4,
helperText: candidateParentLimitError ? 'Must be a number and range from 1-20' : '',
helperText: candidateParentLimitError ? 'Fill in the number, the length is 1-20.' : '',
error: candidateParentLimitError,

onChange: (e: any) => {
Expand Down Expand Up @@ -368,7 +368,7 @@ export default function NewCluster() {
placeholder: 'Please enter Filter parent limit',
defaultValue: 40,
fullWidth: false,
helperText: filterParentLimitError ? 'Must be a number and range from 10-1000' : '',
helperText: filterParentLimitError ? 'Fill in the number, the length is 10-1000.' : '',
error: filterParentLimitError,

onChange: (e: any) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/developer/tokens/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function UpdateTokens() {
autoComplete: 'family-name',
placeholder: 'Enter your description',
value: tokens.bio,
helperText: bioError ? 'The length is 1-1000' : '',
helperText: bioError ? 'Fill in the characters, the length is 0-1000.' : '',
error: bioError,

InputProps: {
Expand Down
6 changes: 3 additions & 3 deletions src/components/developer/tokens/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function CreateTokens() {
name: 'name',
autoComplete: 'family-name',
placeholder: 'Enter your token name',
helperText: nameError ? 'Please enter the correct token name' : '',
helperText: nameError ? 'Fill in the characters, the length is 1-100.' : '',
error: nameError,
InputProps: {
endAdornment: (
Expand All @@ -78,7 +78,7 @@ export default function CreateTokens() {
setError: setNameError,

validate: (value: string) => {
const reg = /^(?=.*[A-Za-z0-9@$!%*?&._-])[A-Za-z0-9@$!%*?&._-]{1,}$/;
const reg = /^(?=.*[A-Za-z0-9@$!%*?&._-])[A-Za-z0-9@$!%*?&._-]{1,100}$/;
return reg.test(value);
},
},
Expand All @@ -89,7 +89,7 @@ export default function CreateTokens() {
name: 'bio',
autoComplete: 'family-name',
placeholder: 'Enter your description',
helperText: bioError ? 'The length is 1-1000' : '',
helperText: bioError ? 'Fill in the characters, the length is 0-1000.' : '',
error: bioError,
InputProps: {
endAdornment: (
Expand Down
24 changes: 11 additions & 13 deletions src/components/profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ export default function Profile() {
name: 'bio',
multiline: true,
autoComplete: 'family-name',
placeholder: 'Enter your Bio',
helperText: bioError ? 'The length is 0-1000' : '',
placeholder: 'Enter your description',
helperText: bioError ? 'Fill in the characters, the length is 0-1000.' : '',
error: bioError,
value: user.bio,

Expand Down Expand Up @@ -169,7 +169,7 @@ export default function Profile() {
autoComplete: 'family-name',
value: user.phone,
placeholder: 'Enter your Phone',
helperText: phoneError ? 'Please enter the correct phone number' : '',
helperText: phoneError ? 'Invalid phone number.' : '',
error: phoneError,

onChange: (e: any) => {
Expand Down Expand Up @@ -202,7 +202,7 @@ export default function Profile() {
autoComplete: 'family-name',
value: user.location,
placeholder: 'Enter your location',
helperText: locationError ? 'Please enter your address' : '',
helperText: locationError ? 'Fill in the characters, the length is 0-100.' : '',
error: locationError,

onChange: (e: any) => {
Expand All @@ -222,7 +222,7 @@ export default function Profile() {
setError: setLocationError,

validate: (value: string) => {
const reg = /^[A-Za-z0-9]{0,1000}$/;
const reg = /^[A-Za-z0-9]{0,100}$/;
return reg.test(value);
},
},
Expand All @@ -234,7 +234,7 @@ export default function Profile() {
autoComplete: 'family-name',
value: user.email,
placeholder: 'Enter your Email',
helperText: emailError ? 'Please enter the correct email format' : '',
helperText: emailError ? 'Email is invalid or already taken.' : '',
error: emailError,

onChange: (e: any) => {
Expand Down Expand Up @@ -270,7 +270,7 @@ export default function Profile() {
type: showOldPassword ? 'text' : 'password',
placeholder: 'Enter your old password',
value: old_password,
helperText: phoneError ? 'Please enter the correct password' : '',
helperText: phoneError ? 'Fill in the characters, the maximum length is 16.' : '',
error: phoneError,

onChange: (e: any) => {
Expand Down Expand Up @@ -314,9 +314,7 @@ export default function Profile() {
type: showNewPassword ? 'text' : 'password',
autoComplete: 'family-name',
placeholder: 'Enter your new password',
helperText: locationError
? 'At least 8-16 characters, at least 1 uppercase letter, 1 lowercase letter, and 1 number'
: '',
helperText: locationError ? `At least 8-16 characters, with at least 1 lowercase letter and 1 number.` : '',
error: locationError,
value: new_password,

Expand Down Expand Up @@ -349,7 +347,7 @@ export default function Profile() {
syncError: false,
setError: setLocationError,
validate: (value: string) => {
const reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/;
const reg = /^(?=.*[a-z])(?=.*\d)[^]{8,16}$/;
return reg.test(value);
},
},
Expand All @@ -361,7 +359,7 @@ export default function Profile() {
type: showConfirmPassword ? 'text' : 'password',
autoComplete: 'family-name',
placeholder: 'Enter your payload',
helperText: emailError ? 'Please enter the same password' : '',
helperText: emailError ? 'Please enter the same password.' : '',
error: emailError,

onChange: (e: any) => {
Expand Down Expand Up @@ -392,7 +390,7 @@ export default function Profile() {
setError: setEmailError,

validate: (value: string) => {
const reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/;
const reg = /^(?=.*[a-z])(?=.*\d)[^]{8,16}$/;
return value === newPassword && reg.test(value);
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/signin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function SignIn() {
name: 'account',
autoComplete: 'family-name',
placeholder: 'Enter your account',
helperText: accountError ? 'Please enter the correct account number' : '',
helperText: accountError ? 'Fill in the characters, the length is 3-10.' : '',
error: accountError,

onChange: (e: any) => {
Expand All @@ -58,7 +58,7 @@ export default function SignIn() {
type: showPassword ? 'text' : 'password',
autoComplete: 'password',
placeholder: 'Enter your password',
helperText: passwordError ? 'Please enter the correct password ' : '',
helperText: passwordError ? 'Fill in the characters, the maximum length is 16.' : '',
error: passwordError,

onChange: (e: any) => {
Expand Down
16 changes: 7 additions & 9 deletions src/components/signup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function SignUp() {
const [showPassword, setShowPassword] = useState(false);
const [showConfirmPassword, setShowConfirmPassword] = useState(false);
const [pageLoding, setPageLoding] = useState(false);

const navigate = useNavigate();
const location = useLocation();

Expand All @@ -40,7 +40,7 @@ export default function SignUp() {
id: 'account',
placeholder: 'Enter your account',
error: accountError,
helperText: accountError ? 'At least four characters do not contain special characters' : '',
helperText: accountError ? 'Fill in the characters, the length is 3-10.' : '',

onChange: (e: any) => {
changeValidate(e.target.value, formList[0]);
Expand All @@ -62,7 +62,7 @@ export default function SignUp() {
id: 'email',
placeholder: 'Enter your email',
error: emailError,
helperText: emailError ? 'Enter the correct email' : '',
helperText: emailError ? 'Email is invalid or already taken.' : '',

onChange: (e: any) => {
changeValidate(e.target.value, formList[1]);
Expand All @@ -83,9 +83,7 @@ export default function SignUp() {
id: 'password',
placeholder: 'Enter your password',
autoComplete: 'new-password',
helperText: passwordError
? 'At least 8-16 characters, at least 1 uppercase letter, 1 lowercase letter, and 1 number'
: '',
helperText: passwordError ? `At least 8-16 characters, with at least 1 lowercase letter and 1 number.` : '',
type: showPassword ? 'text' : 'password',
error: passwordError,
InputProps: {
Expand All @@ -112,7 +110,7 @@ export default function SignUp() {
setError: setPasswordError,

validate: (value: string) => {
const reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/;
const reg = /^(?=.*[a-z])(?=.*\d)[^]{8,16}$/;
return reg.test(value);
},
},
Expand All @@ -125,7 +123,7 @@ export default function SignUp() {
autoComplete: 'new-password',
placeholder: 'Repeat your new password',
error: confirmPassworError,
helperText: confirmPassworError ? 'Please enter the same password' : '',
helperText: confirmPassworError ? 'Please enter the same password.' : '',

InputProps: {
endAdornment: (
Expand All @@ -152,7 +150,7 @@ export default function SignUp() {
setError: setConfirmPassworError,

validate: (value: string) => {
const reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/;
const reg = /^(?=.*[a-z])(?=.*\d)[^]{8,16}$/;
return value === password && reg.test(value);
},
},
Expand Down

0 comments on commit 35dedfd

Please sign in to comment.