// Era Koleji — application form const Form = () => { const [form, setForm] = React.useState({ fullname: "", tc: "", phone: "", email: "", school: "", pref1: "", pref2: "", why: "", }); const [errors, setErrors] = React.useState({}); const [submitted, setSubmitted] = React.useState(false); const [submitting, setSubmitting] = React.useState(false); const filledCount = Object.values(form).filter(v => v.trim().length > 0).length; const progress = Math.round((filledCount / 8) * 100); const validate = () => { const e = {}; if (!form.fullname.trim() || form.fullname.trim().split(" ").length < 2) { e.fullname = "Lütfen ad ve soyadınızı girin."; } if (!/^[1-9][0-9]{10}$/.test(form.tc)) { e.tc = "TC Kimlik No 11 haneli olmalı, 0 ile başlamamalıdır."; } if (!/^(\+90|0)?\s?5\d{2}\s?\d{3}\s?\d{2}\s?\d{2}$/.test(form.phone.replace(/\s/g, ""))) { e.phone = "Geçerli bir telefon numarası girin."; } if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(form.email)) { e.email = "Geçerli bir e-posta adresi girin."; } if (!form.school.trim()) { e.school = "Okul ve sınıf bilgisi gerekli."; } if (!form.pref1) { e.pref1 = "1. tercihinizi seçin."; } if (!form.pref2) { e.pref2 = "2. tercihinizi seçin."; } if (form.pref1 && form.pref2 && form.pref1 === form.pref2) { e.pref2 = "1. ve 2. tercih farklı komiteler olmalıdır."; } if (!form.why.trim() || form.why.trim().length < 20) { e.why = "En az 20 karakter ile motivasyonunuzu paylaşın."; } return e; }; const handleChange = (k) => (ev) => { let val = ev.target.value; if (k === "tc") val = val.replace(/\D/g, "").slice(0, 11); if (k === "phone") val = val.replace(/[^\d+\s]/g, "").slice(0, 17); setForm({ ...form, [k]: val }); if (errors[k]) setErrors({ ...errors, [k]: undefined }); }; const handleSubmit = (ev) => { ev.preventDefault(); const e = validate(); setErrors(e); if (Object.keys(e).length === 0) { setSubmitting(true); (async () => { const id = "EKUF-" + Math.floor(Math.random() * 9000 + 1000); const c1 = COMMITTEES.find(c => c.id === form.pref1); const c2 = COMMITTEES.find(c => c.id === form.pref2); const row = { id, fullname: form.fullname, tc: form.tc, phone: form.phone, email: form.email, school: form.school, pref1: form.pref1, pref2: form.pref2, pref1_name: c1?.name, pref2_name: c2?.name, why: form.why, status: "pending", }; try { if (window.SB) { const { error } = await window.SB.from("applications").insert(row); if (error) throw error; } window._lastAppId = id; setSubmitting(false); setSubmitted(true); } catch (err) { console.error(err); setSubmitting(false); setErrors({ submit: "Başvuru gönderilemedi: " + (err.message || "Sunucu hatası") }); } })(); } else { const first = document.querySelector(".form-input.invalid, .form-select.invalid, .form-textarea.invalid"); if (first) first.focus({ preventScroll: false }); } }; const findCommittee = (id) => COMMITTEES.find(c => c.id === id); if (submitted) { const p1 = findCommittee(form.pref1); const p2 = findCommittee(form.pref2); return (

Başvurunuz Alındı!

Era Koleji Ulusal Formu'na gösterdiğiniz ilgi için teşekkür ederiz. Başvurunuz değerlendirildikten sonra sizinle e-posta yoluyla iletişime geçeceğiz.

Ad Soyad
{form.fullname}
1. Tercih
{p1?.name}
2. Tercih
{p2?.name}
Başvuru No
{window._lastAppId || "EKUF-0000"}
); } const inputCls = (k) => `form-input${errors[k] ? " invalid" : ""}`; const selectCls = (k) => `form-select${errors[k] ? " invalid" : ""}`; const textareaCls = (k) => `form-textarea${errors[k] ? " invalid" : ""}`; return (
Başvuru
{progress}%
{errors.fullname && {errors.fullname}}
{errors.tc ? {errors.tc} : Bilgileriniz gizli tutulur, üçüncü taraflarla paylaşılmaz. }
{errors.phone && {errors.phone}}
{errors.email && {errors.email}}
{errors.school && {errors.school}}
{errors.pref1 ? {errors.pref1} : Katılmak istediğiniz öncelikli komite. }
{errors.pref2 ? {errors.pref2} : 1. tercih dolarsa atanacağınız komite. }