export default function DashboardGriyaRudinaAsri() { const { useState } = React; const [user, setUser] = useState(null); const [password, setPassword] = useState(''); const [menu, setMenu] = useState('dashboard'); const [danaMasuk, setDanaMasuk] = useState([ { id: 1, tanggal: '2026-07-01', keterangan: 'Iuran Warga', nominal: 500000 } ]); const [danaKeluar, setDanaKeluar] = useState([ { id: 1, tanggal: '2026-07-01', keterangan: 'Perawatan Lingkungan', nominal: 150000 } ]); const [form, setForm] = useState({ tipe: 'masuk', tanggal: '', keterangan: '', nominal: '' }); const login = () => { if (password === 'Grae24') { setUser({ role: 'admin', name: 'Administrator' }); } else if (password === 'balikpapan') { setUser({ role: 'warga', name: 'Warga' }); } else { alert('Password salah'); } }; const tambahData = () => { const dataBaru = { id: Date.now(), tanggal: form.tanggal, keterangan: form.keterangan, nominal: Number(form.nominal) }; if (form.tipe === 'masuk') { setDanaMasuk([...danaMasuk, dataBaru]); } else { setDanaKeluar([...danaKeluar, dataBaru]); } setForm({ tipe: 'masuk', tanggal: '', keterangan: '', nominal: '' }); }; const hapusData = (id, tipe) => { if (user.role !== 'admin') return; if (tipe === 'masuk') { setDanaMasuk(danaMasuk.filter(x => x.id !== id)); } else { setDanaKeluar(danaKeluar.filter(x => x.id !== id)); } }; const totalMasuk = danaMasuk.reduce((a, b) => a + b.nominal, 0); const totalKeluar = danaKeluar.reduce((a, b) => a + b.nominal, 0); const saldo = totalMasuk - totalKeluar; if (!user) { return (
{user.name} - {user.role}
Rp {totalMasuk.toLocaleString()}
Rp {totalKeluar.toLocaleString()}
Rp {saldo.toLocaleString()}
| Tanggal | Keterangan | Nominal | {user.role === 'admin' &&Aksi | }
|---|---|---|---|
| {d.tanggal} | {d.keterangan} | Rp {d.nominal.toLocaleString()} | {user.role === 'admin' && ()} |
| Tanggal | Keterangan | Nominal | {user.role === 'admin' &&Aksi | }
|---|---|---|---|
| {d.tanggal} | {d.keterangan} | Rp {d.nominal.toLocaleString()} | {user.role === 'admin' && ()} |