From 02d2a8f8a15ea4a32cc7b9c148ff6041bd8f1dec Mon Sep 17 00:00:00 2001 From: Pedro Guerrato Date: Wed, 16 Feb 2022 16:06:27 -0300 Subject: [PATCH] Removed onFeedback due to validation complexity --- .../inputs/basic/password/Password.tsx | 1 - .../components/inputs/basic/search/Search.tsx | 1 - .../components/inputs/basic/shared/types.ts | 2 +- src/lib/components/inputs/basic/text/Text.tsx | 1 - src/lib/hooks/useInputValidation.ts | 29 +++++++++++++------ 5 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/lib/components/inputs/basic/password/Password.tsx b/src/lib/components/inputs/basic/password/Password.tsx index cad3fe8d..5e545544 100644 --- a/src/lib/components/inputs/basic/password/Password.tsx +++ b/src/lib/components/inputs/basic/password/Password.tsx @@ -25,7 +25,6 @@ export const Password = (props: InputProps) => { useEffect(() => { props.onValidate?.call(null, getResultantValidationResponse(validationResponse)) - props.onFeedback?.call(null, validationResponse) }, [validationResponse]) return ( diff --git a/src/lib/components/inputs/basic/search/Search.tsx b/src/lib/components/inputs/basic/search/Search.tsx index 37258f93..da986997 100644 --- a/src/lib/components/inputs/basic/search/Search.tsx +++ b/src/lib/components/inputs/basic/search/Search.tsx @@ -22,7 +22,6 @@ export const Search = (props: InputProps) => { useEffect(() => { props.onValidate?.call(null, getResultantValidationResponse(validationResponse)) - props.onFeedback?.call(null, validationResponse) }, [validationResponse]) return ( diff --git a/src/lib/components/inputs/basic/shared/types.ts b/src/lib/components/inputs/basic/shared/types.ts index 99d8d7f3..9096484d 100644 --- a/src/lib/components/inputs/basic/shared/types.ts +++ b/src/lib/components/inputs/basic/shared/types.ts @@ -43,6 +43,7 @@ export interface InputValidation { type: CriteriaType rule?: number | boolean | RegExp | ValidationFunction } + nonBlocking?: boolean } export type InputCriteriaResponse = { @@ -50,7 +51,6 @@ export type InputCriteriaResponse = { type: InputResponseType icon?: IconName isValid: boolean - criteriaId?: string | number } export const criteriaRule = ( diff --git a/src/lib/components/inputs/basic/text/Text.tsx b/src/lib/components/inputs/basic/text/Text.tsx index 9bd49995..281b2ee6 100644 --- a/src/lib/components/inputs/basic/text/Text.tsx +++ b/src/lib/components/inputs/basic/text/Text.tsx @@ -17,7 +17,6 @@ export const Text = (props: InputProps) => { useEffect(() => { props.onValidate?.call(null, getResultantValidationResponse(validationResponse)) - props.onFeedback?.call(null, validationResponse) }, [validationResponse]) return ( diff --git a/src/lib/hooks/useInputValidation.ts b/src/lib/hooks/useInputValidation.ts index 3b766968..83513f8a 100644 --- a/src/lib/hooks/useInputValidation.ts +++ b/src/lib/hooks/useInputValidation.ts @@ -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 } } @@ -109,9 +113,9 @@ export const useInputValidation = (props: InputProps) => { crit.invalidMessage, crit.validMessage, crit.invalidResponseType, + crit.nonBlocking, isValid, - false, - crit.id + false ) ) break @@ -121,9 +125,9 @@ export const useInputValidation = (props: InputProps) => { crit.invalidMessage, crit.validMessage, crit.validResponseType, + crit.nonBlocking, isValid, - false, - crit.id + false ) ) } @@ -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 + ) ] }