-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: validation add service form in lab registration (#359)
* fix: validation service form in registration * fix: add handleRules file
- Loading branch information
Showing
4 changed files
with
114 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Using Object.freeze for the constant means the object can't be changed. It's similar to enum on typescript | ||
|
||
export default Object.freeze({ | ||
REQUIRED: "This field is required", | ||
EMAIL: "Email is invalid. It should contain @ followed by a domain", | ||
INCORRECT_PASSWORD: "The password you entered is incorrect", | ||
|
||
/** | ||
* | ||
* @param {string} format | ||
* @returns {string} | ||
*/ | ||
FILE_FORMAT: (format) => { | ||
const message = "The files uploaded are not in the supported file formats" | ||
if (format) return message + ` (${format})` | ||
|
||
return message | ||
}, | ||
|
||
/** | ||
* | ||
* @param {number | string} size | ||
* @returns {string} | ||
*/ | ||
FILE_SIZE: (size) => { | ||
const message = "The total file size uploaded exceeds the maximum file size allowed" | ||
if (size) return message + ` ${size}MB` | ||
|
||
return message | ||
}, | ||
|
||
/** | ||
* | ||
* @param {number | string} number | ||
* @returns {string} | ||
*/ | ||
FILE_NUMBER: (number) => { | ||
const message = "The total number of files uploaded exceeds the maximum file size allowed" | ||
if (number) return message + ` (${number}) Files` | ||
|
||
return message | ||
}, | ||
|
||
/** | ||
* | ||
* @param {number | string} length | ||
* @param {number | string} includeChars | ||
* @returns {string} | ||
*/ | ||
PASSWORD: (length = 0, includeChars) => { | ||
const message = `Password must have at least ${length} character` | ||
if (includeChars) return message + `, that include at least ${includeChars}` | ||
|
||
return message | ||
}, | ||
|
||
/** | ||
* | ||
* @param { string } label | ||
* @returns {string} | ||
*/ | ||
INVALID: (label) => { | ||
const message = `${label} is Invalid` | ||
return message | ||
}, | ||
|
||
INPUT_CHARACTER: (type) => { | ||
const message = `This field can only contain ${type}` | ||
return message | ||
}, | ||
/** | ||
* | ||
* @param {number | string} number | ||
* @returns {string} | ||
*/ | ||
MAX_CHARACTER: (number) => { | ||
const message = `This field only allows ${number} characters` | ||
return message | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import errorMessages from "./error-messages" | ||
|
||
export default Object.freeze({ | ||
FIELD_REQUIRED: val => !!val || errorMessages.REQUIRED, | ||
ENGLISH_ALPHABET: val => (!!val && /^[A-Za-z0-9!@#$%^&*\\(\\)\-_=+:;"',.\\/? \n]+$/.test(val)) || errorMessages.INPUT_CHARACTER("English alphabet"), | ||
MAX_CHARACTER: (max) => { | ||
return val => (!!val && val.length <= max) || errorMessages.MAX_CHARACTER(max) | ||
}, | ||
FILE_SIZE: (size) => { | ||
return val => (!!val && val.size <= size) || errorMessages.FILE_SIZE(size / 1000000) | ||
}, | ||
DEFAULT_ACCEPT_DOCUMENTS: val => (!!val && (val.type === "application/pdf" || val.type === "application/msword" || val.type === "application/vnd.openxmlformats-officedocument.wordprocessingml.document")) || errorMessages.FILE_FORMAT("PDF/DOC/DOCX") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters