From d5e77b42a1166c499ddc01f779744504e9bec42f Mon Sep 17 00:00:00 2001 From: arsam Date: Fri, 18 Sep 2026 23:16:53 +0330 Subject: [PATCH] Import source: src/components/CenterPanel/forms/URLForm Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality. --- src/components/CenterPanel/forms/URLForm.tsx | 69 ++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/components/CenterPanel/forms/URLForm.tsx diff --git a/src/components/CenterPanel/forms/URLForm.tsx b/src/components/CenterPanel/forms/URLForm.tsx new file mode 100644 index 0000000..d38de2a --- /dev/null +++ b/src/components/CenterPanel/forms/URLForm.tsx @@ -0,0 +1,69 @@ +import { useState } from 'react'; +import { useQR } from '../../../context/QRContext'; +import { useToast } from '../../../context/ToastContext'; + +function isValidUrl(v: string) { + if (!v.trim()) return true; + return /^https?:\/\/.+\..+/.test(v.trim()); +} + +export function URLForm() { + const { state, dispatch } = useQR(); + const { show } = useToast(); + const { websiteUrl } = state.formData.url; + const [shortening, setShortening] = useState(false); + const valid = isValidUrl(websiteUrl); + + const set = (v: string) => dispatch({ type: 'SET_FORM_FIELD', qrType: 'url', field: 'websiteUrl', value: v }); + + const shorten = async () => { + if (!websiteUrl.trim() || !valid) return; + setShortening(true); + try { + const res = await fetch(`https://is.gd/create.php?format=json&url=${encodeURIComponent(websiteUrl)}`); + const data = await res.json(); + if (data.shorturl) { set(data.shorturl); show('URL shortened!', 'success'); } + else show(data.errormessage ?? 'Could not shorten URL', 'error'); + } catch { + show('Shortener unavailable', 'error'); + } finally { + setShortening(false); + } + }; + + return ( +
+ +
+
+ set(e.target.value)} + placeholder="https://example.com" + className="h-12 px-4 rounded-[11px] text-[14px] outline-none transition-all w-full" + style={{ + background: 'var(--bg-input)', + border: `1px solid ${!valid ? '#ef4444' : 'var(--border-sub)'}`, + color: 'var(--text-primary)', + }} + onFocus={e => { if (valid) { e.currentTarget.style.borderColor = '#7C6FE0'; e.currentTarget.style.boxShadow = '0 0 0 3px rgba(124,111,224,0.12)'; }}} + onBlur={e => { e.currentTarget.style.borderColor = valid ? 'var(--border-sub)' : '#ef4444'; e.currentTarget.style.boxShadow = 'none'; }} + /> + {!valid &&

Must start with http:// or https://

} +
+ +
+
+ ); +}