From 329cb0de757e61267f315756319ba2eeec06997e Mon Sep 17 00:00:00 2001 From: arsam Date: Fri, 18 Sep 2026 23:24:46 +0330 Subject: [PATCH] Import source: app/src/lib/TeknavCAP Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality. --- app/src/lib/TeknavCAP.jsx | 124 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 app/src/lib/TeknavCAP.jsx diff --git a/app/src/lib/TeknavCAP.jsx b/app/src/lib/TeknavCAP.jsx new file mode 100644 index 0000000..f6cd543 --- /dev/null +++ b/app/src/lib/TeknavCAP.jsx @@ -0,0 +1,124 @@ +import { useState, useEffect } from 'react'; + +const TeknavCAP = ({ onChange, style = {} }) => { + const [captchaId, setCaptchaId] = useState(''); + const [captchaSvg, setCaptchaSvg] = useState(''); + const [userSolution, setUserSolution] = useState(''); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(''); + + const loadCaptcha = async () => { + setLoading(true); + setError(''); + setUserSolution(''); + try { + const response = await fetch('/api/v1/teknav-cap/generate', { + credentials: 'include', + }); + if (!response.ok) throw new Error('Failed to load captcha'); + const data = await response.json(); + setCaptchaId(data.id); + setCaptchaSvg(data.data); + if (onChange) onChange({ captchaId: data.id, userSolution: '' }); + } catch (err) { + setError('خطا در بارگذاری کپچا'); + console.error('TeknavCAP load error:', err); + } finally { + setLoading(false); + } + }; + + useEffect(() => { + loadCaptcha(); + }, []); + + const handleInputChange = (e) => { + const value = e.target.value; + setUserSolution(value); + if (onChange) onChange({ captchaId, userSolution: value }); + }; + + return ( +
+
+
+ {loading ? ( +
در حال بارگذاری...
+ ) : error ? ( +
{error}
+ ) : ( +
+ )} +
+ +
+ e.target.style.borderColor = '#0F6B73'} + onBlur={(e) => e.target.style.borderColor = '#E4DDD2'} + /> +
+ ); +}; + +export default TeknavCAP;