diff --git a/src/OnboardingSPA/components/TextInput/TextInputSiteGen/index.js b/src/OnboardingSPA/components/TextInput/TextInputSiteGen/index.js index c213f45ec..b61800f6c 100644 --- a/src/OnboardingSPA/components/TextInput/TextInputSiteGen/index.js +++ b/src/OnboardingSPA/components/TextInput/TextInputSiteGen/index.js @@ -6,28 +6,46 @@ const TextInputSiteGen = ( { height, placeholder, customerInput, + setIsValidInput, setCustomerInput, } ) => { const textareaRef = useRef( null ); + const [ analysisScore, setAnalysisScore ] = useState( 0 ); const [ inputText, setInputText ] = useState( 'nfd-sg-input-box__field' ); useEffect( () => { textareaRef.current.style.height = height; const scrollHeight = textareaRef.current.scrollHeight; textareaRef.current.style.height = scrollHeight + 'px'; + const analysisResult = calculateAnalysisScore( customerInput ); + setAnalysisScore( analysisResult ); + setIsValidInput( analysisResult >= 2 ); }, [ customerInput ] ); - const calculateDetail = ( num ) => { + const calculateAnalysisScore = ( input ) => { + /* Number of Characters in the input + * Count < 100 => 0 + * 100 < Count <= 150 => 1 + * 150 < Count <= 200 => 2 + * 200 < Count => 3 + */ + const characterCount = input?.length; + let characterScore = 0; + if ( characterCount > 200 ) { + characterScore = 3; + } else if ( characterCount > 150 ) { + characterScore = 2; + } else if ( characterCount > 100 ) { + characterScore = 1; + } + + return characterScore; + }; + + const addInputScoreSyling = ( num ) => { const selectedButton = 'nfd-sg-input-box__info-icon--selected'; - switch ( num ) { - case 1: - if ( customerInput?.length > 30 ) return selectedButton; - break; - case 2: - if ( customerInput?.length > 60 ) return selectedButton; - break; - case 3: - if ( customerInput?.length > 100 ) return selectedButton; + if ( num <= analysisScore ) { + return selectedButton; } }; @@ -37,6 +55,21 @@ const TextInputSiteGen = ( { setInputText( 'nfd-sg-input-box__field' ); }; + const renderDetails = () => { + const buttons = []; + for ( let i = 1; i <= 3; i++ ) { + buttons.push( +
+ ); + } + return buttons; + }; + return (