// report.jsx — "Buat Laporan" stepper, submit asli ke Supabase. Exported to window. const STEPS = ['Kategori', 'Detail', 'Lokasi', 'Kirim']; function StepDots({ step }) { return (
{STEPS.map((s, i) => (
))}
); } function ReportFlow({ initialCat, clusters = [], onClose, onDone }) { const [step, setStep] = React.useState(0); const [cat, setCat] = React.useState(initialCat && CATS[initialCat] ? initialCat : null); const [title, setTitle] = React.useState(''); const [desc, setDesc] = React.useState(''); const [ig, setIg] = React.useState(''); const [address, setAddress] = React.useState(''); const [clusterId, setClusterId] = React.useState(''); const [anon, setAnon] = React.useState(false); const [photoFile, setPhotoFile] = React.useState(null); const [photoPrev, setPhotoPrev] = React.useState(null); const [loc, setLoc] = React.useState({ lat: -6.2436, lng: 106.6285, got: false }); const [err, setErr] = React.useState(''); const [busy, setBusy] = React.useState(false); const [sent, setSent] = React.useState(false); const fileRef = React.useRef(null); const c = cat ? CATS[cat] : null; const dark = false; React.useEffect(() => { if (step === 2 && !loc.got && navigator.geolocation) { navigator.geolocation.getCurrentPosition( p => setLoc({ lat: p.coords.latitude, lng: p.coords.longitude, got: true }), () => setLoc(l => ({ ...l, got: true })), { enableHighAccuracy: true, timeout: 8000 } ); } }, [step]); const onPickFile = (e) => { const f = e.target.files && e.target.files[0]; if (!f) return; setPhotoFile(f); if (photoPrev) URL.revokeObjectURL(photoPrev); setPhotoPrev(URL.createObjectURL(f)); }; const doSubmit = async () => { setBusy(true); setErr(''); const res = await gsData.submitReport({ cat, title: title.trim(), desc, anon, lat: loc.lat, lng: loc.lng, address: address.trim() || null, cluster_id: clusterId || null, photoFile, instagram_url: ig.trim() || null, }); setBusy(false); if (res.error) { setErr('Gagal mengirim: ' + res.error); return; } setSent(true); setTimeout(onDone, 1600); }; const next = () => { if (step === 0 && !cat) return setErr('Pilih kategori dulu ya'); if (step === 1 && !title.trim()) return setErr('Judul singkat diperlukan ya'); setErr(''); if (step === 3) return doSubmit(); setStep(s => Math.min(3, s + 1)); }; const back = () => { setErr(''); step === 0 ? onClose() : setStep(s => s - 1); }; if (sent) { return (

Laporan terkirim!

Terima kasih sudah menjaga lingkungan kita. Kamu dapat +50 poin. Warga & pengurus akan segera melihat laporanmu.

); } const selCluster = clusters.find(c => c.id === clusterId); return (
{step + 1}/4

{['Apa yang terjadi?', 'Ceritakan detailnya', 'Di mana lokasinya?', 'Periksa & kirim'][step]}

{['Pilih kategori laporanmu', 'Tambahkan foto dan deskripsi singkat', 'Pastikan titik lokasi sudah benar', 'Pastikan semua sudah benar'][step]}

{step === 0 && (
{CAT_ORDER.map(k => { const cc = CATS[k]; const on = cat === k; return ( ); })}
)} {step === 1 && (
{ setTitle(e.target.value); setErr(''); }} placeholder="cth. Lubang besar di Boulevard" style={{ width: '100%', padding: '13px 14px', borderRadius: 'var(--r-md)', border: '1px solid var(--border)', background: 'var(--surface-2)', fontFamily: 'var(--font)', fontSize: 14.5, fontWeight: 500, color: 'var(--text-1)', outline: 'none' }} />