verified that otp is six digits

This commit is contained in:
victorAnumudu
2023-02-22 11:35:35 +01:00
parent 9cb773d360
commit 48ea72270f
2 changed files with 28 additions and 6 deletions
@@ -1,6 +1,6 @@
import React, { useEffect } from "react"; import React, { useEffect } from "react";
export default function Otp({handleChange}) { export default function Otp({handleChange, value}) {
useEffect(() => { useEffect(() => {
const otp = document.querySelector("#otp-inputs"); const otp = document.querySelector("#otp-inputs");
// eslint-disable-next-line no-restricted-syntax // eslint-disable-next-line no-restricted-syntax
@@ -25,6 +25,8 @@ export default function Otp({handleChange}) {
type="text" type="text"
maxLength={1} maxLength={1}
id="otp" id="otp"
name='value_one'
value={value.value_one}
onChange={handleChange} onChange={handleChange}
/> />
</div> </div>
@@ -34,6 +36,8 @@ export default function Otp({handleChange}) {
type="text" type="text"
maxLength={1} maxLength={1}
id="otp" id="otp"
name='value_two'
value={value.value_two}
onChange={handleChange} onChange={handleChange}
/> />
</div> </div>
@@ -43,6 +47,8 @@ export default function Otp({handleChange}) {
type="text" type="text"
maxLength={1} maxLength={1}
id="otp" id="otp"
name='value_three'
value={value.value_three}
onChange={handleChange} onChange={handleChange}
/> />
</div> </div>
@@ -52,6 +58,8 @@ export default function Otp({handleChange}) {
type="text" type="text"
maxLength={1} maxLength={1}
id="otp" id="otp"
name='value_four'
value={value.value_four}
onChange={handleChange} onChange={handleChange}
/> />
</div> </div>
@@ -61,6 +69,8 @@ export default function Otp({handleChange}) {
type="text" type="text"
maxLength={1} maxLength={1}
id="otp" id="otp"
name='value_five'
value={value.value_five}
onChange={handleChange} onChange={handleChange}
/> />
</div> </div>
@@ -70,6 +80,8 @@ export default function Otp({handleChange}) {
type="text" type="text"
maxLength={1} maxLength={1}
id="otp" id="otp"
name='value_six'
value={value.value_six}
onChange={handleChange} onChange={handleChange}
/> />
</div> </div>
@@ -21,11 +21,18 @@ export default function VerifyYou() {
// state for user inputed values // state for user inputed values
const [verificationCode, setVerificationCode] = useState('') const [verificationCode, setVerificationCode] = useState({
value_one: '',
value_two: '',
value_three: '',
value_four: '',
value_five: '',
value_six: '',
})
const handleVerificationInput = ({target:{value}}) => { // function that listens to input change const handleVerificationInput = ({target:{name, value}}) => { // function that listens to input change
setVerificationCode(prev => { setVerificationCode(prev => {
return prev + value return {...prev, [name]:value}
}) })
} }
@@ -38,7 +45,10 @@ export default function VerifyYou() {
setLoading(true) // Sets loading spinner setLoading(true) // Sets loading spinner
let code = verificationCode let code = '';
for(let values in verificationCode){
code+=verificationCode[values]
}
if(!code){ // checks if code is empty if(!code){ // checks if code is empty
setLoading(false) setLoading(false)
@@ -102,7 +112,7 @@ export default function VerifyYou() {
</div> </div>
</div> </div>
<div className="input-area"> <div className="input-area">
<Otp handleChange={handleVerificationInput}/> <Otp handleChange={handleVerificationInput} value={verificationCode}/>
{errorMessage.message != '' && <p className={`text-center p-3 ${errorMessage.success ? 'text-green-600' : 'text-red-600'}`}>{errorMessage.message}</p>} {errorMessage.message != '' && <p className={`text-center p-3 ${errorMessage.success ? 'text-green-600' : 'text-red-600'}`}>{errorMessage.message}</p>}
<div className="signin-area mb-3.5"> <div className="signin-area mb-3.5">
<button <button