-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fe): add validations to reject submission fields (#929)
- Loading branch information
1 parent
bad8521
commit b61f756
Showing
2 changed files
with
37 additions
and
9 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
frontend/src/helpers/validators/SubmissionReviewValidations.ts
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,19 @@ | ||
/* eslint-disable dot-notation */ | ||
import { isMaxSize, isOnlyNumbers, isNotEmpty, isNotEmptyArray } from "@/helpers/validators/GlobalValidators"; | ||
|
||
const reviewFieldValidations: Record<string, ((value: any) => string)[]> = {}; | ||
|
||
// This function will return all validators for the field | ||
export const getValidations = (key: string): ((value: any) => string)[] => | ||
reviewFieldValidations[key] || []; | ||
|
||
const isMaxSizeMsg = (fieldName: string, maxSize: number) => | ||
isMaxSize(`The ${fieldName} has a ${maxSize} character limit`)(maxSize); | ||
|
||
reviewFieldValidations["reasons"] = [isNotEmptyArray("You must select at least one reason")]; | ||
|
||
reviewFieldValidations["message"] = [ | ||
isNotEmpty("Matching client number cannot be empty"), | ||
isOnlyNumbers("Matching client number should be composed of only numbers"), | ||
isMaxSizeMsg("matching client number", 8), | ||
]; |
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