Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
Removed onFeedback due to validation complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
guerrato committed Feb 16, 2022
1 parent b26f52d commit 02d2a8f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/lib/components/inputs/basic/password/Password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const Password = (props: InputProps) => {

useEffect(() => {
props.onValidate?.call(null, getResultantValidationResponse(validationResponse))
props.onFeedback?.call(null, validationResponse)
}, [validationResponse])

return (
Expand Down
1 change: 0 additions & 1 deletion src/lib/components/inputs/basic/search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const Search = (props: InputProps) => {

useEffect(() => {
props.onValidate?.call(null, getResultantValidationResponse(validationResponse))
props.onFeedback?.call(null, validationResponse)
}, [validationResponse])

return (
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/inputs/basic/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ export interface InputValidation {
type: CriteriaType
rule?: number | boolean | RegExp | ValidationFunction
}
nonBlocking?: boolean
}

export type InputCriteriaResponse = {
message: string
type: InputResponseType
icon?: IconName
isValid: boolean
criteriaId?: string | number
}

export const criteriaRule = (
Expand Down
1 change: 0 additions & 1 deletion src/lib/components/inputs/basic/text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const Text = (props: InputProps) => {

useEffect(() => {
props.onValidate?.call(null, getResultantValidationResponse(validationResponse))
props.onFeedback?.call(null, validationResponse)
}, [validationResponse])

return (
Expand Down
29 changes: 20 additions & 9 deletions src/lib/hooks/useInputValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,27 @@ const handleResponse = (
invalidMessage: string,
validMessage: string,
type: InputResponseType,
nonBlocking: boolean,
isValid: boolean,
fromMultiple: boolean,
criteriaId?: string | number
fromMultiple: boolean
): InputCriteriaResponse => {
let message = invalidMessage

if (isValid && !fromMultiple) {
message = !isEmpty(validMessage) ? validMessage : ''
}

if (!isValid && nonBlocking) {
type = 'warning'
}

const icon = getValidationIcon(type)

return {
message,
type: type,
icon,
isValid,
criteriaId
isValid
}
}

Expand Down Expand Up @@ -109,9 +113,9 @@ export const useInputValidation = (props: InputProps) => {
crit.invalidMessage,
crit.validMessage,
crit.invalidResponseType,
crit.nonBlocking,
isValid,
false,
crit.id
false
)
)
break
Expand All @@ -121,9 +125,9 @@ export const useInputValidation = (props: InputProps) => {
crit.invalidMessage,
crit.validMessage,
crit.validResponseType,
crit.nonBlocking,
isValid,
false,
crit.id
false
)
)
}
Expand All @@ -138,7 +142,14 @@ export const useInputValidation = (props: InputProps) => {

validations = [
...validations,
handleResponse(crit.invalidMessage, crit.validMessage, respType, isValid, true, crit.id)
handleResponse(
crit.invalidMessage,
crit.validMessage,
respType,
crit.nonBlocking,
isValid,
true
)
]
}

Expand Down

0 comments on commit 02d2a8f

Please sign in to comment.