diff --git a/SerpentRace_Frontend/src/pages/Auth/EmailVerification.jsx b/SerpentRace_Frontend/src/pages/Auth/EmailVerification.jsx new file mode 100755 index 00000000..ce82e961 --- /dev/null +++ b/SerpentRace_Frontend/src/pages/Auth/EmailVerification.jsx @@ -0,0 +1,85 @@ +import { useState, useRef } from "react"; +import Background from "../../assets/backgrounds/Background"; +import { motion } from "framer-motion"; +import Button from "../../components/Buttons/Button"; + + +export default function EmailVerification() { + const [code, setCode] = useState(Array(6).fill("")); + const inputRefs = useRef([]); + + const handleChange = (e, index) => { + const { value } = e.target; + if (/^\d*$/.test(value) && value.length <= 1) { + const newCode = [...code]; + newCode[index] = value; + setCode(newCode); + if (value && index < 5) { + inputRefs.current[index + 1].focus(); + } + } + }; + + const handleKeyDown = (e, index) => { + if (e.key === "Backspace" && !code[index] && index > 0) { + inputRefs.current[index - 1].focus(); + } else if (e.key === "ArrowLeft" && index > 0) { + inputRefs.current[index - 1].focus(); + } else if (e.key === "ArrowRight" && index < 5) { + inputRefs.current[index + 1].focus(); + } else if (/^\d$/.test(e.key) && code[index]) { + e.preventDefault(); + const newCode = [...code]; + newCode[index] = e.key; + setCode(newCode); + + if (index < 5) { + setTimeout(() => { + inputRefs.current[index + 1].focus(); + }, 0); + } + } + }; + + const handleSubmit = (e) => { + e.preventDefault(); + console.log("Code submitted:", code.join("")); + // Logika a megerősítő kód ellenőrzésére + }; + + return ( +
+ + +
+

+ Email megerősítés +

+
+
+ {code.map((digit, index) => ( + handleChange(e, index)} + onKeyDown={(e) => handleKeyDown(e, index)} + ref={(el) => (inputRefs.current[index] = el)} + className={`w-12 h-12 px-2 py-3 border rounded-lg focus:ring-4 focus:ring-indigo-400 text-gray-700 placeholder-gray-400 bg-gray-50 text-center text-2xl tracking-widest ${!digit ? 'placeholder-opacity-100' : 'placeholder-opacity-0'}`} + // placeholder="_" + maxLength="1" + /> + ))} +
+
+
+
+ ); +} \ No newline at end of file