/* ════════════════════════════════════════════════
Dashboard — shell + modul
════════════════════════════════════════════════ */
const _di = (p) => ;
const DICON = {
overview: _di(<>>),
banner: _di(<>>),
pageheaders: _di(<>>),
articles: _di(<>>),
registrations: _di(<>>),
donasi: _di(),
toko: _di(<>>),
programs: _di(<>>),
teachers: _di(<>>),
testimonials: _di(),
fasilitas: _di(<>>),
kegiatan: _di(<>>),
settings: _di(<>>),
users: _di(<>>),
globe: _di(<>>),
questions: _di(<>>),
logout: _di(<>>),
};
function Dashboard({ user, navigate, onLogout }) {
const [tab, setTab] = useState('overview');
const [toastNode, toast] = useToast();
const [mobileNav, setMobileNav] = useState(false);
const [pwModal, setPwModal] = useState(false);
const roleLabelTop = user.role === 'admin' ? 'Administrator' : (user.role === 'writer' ? 'Penulis' : user.role);
const isAdmin = user.role === 'admin';
const menu = [
{ key: 'overview', label: 'Ringkasan', icon: DICON.overview, admin: false },
{ key: 'profile', label: 'Profil Saya', icon: DICON.teachers, admin: false },
{ key: 'banner', label: 'Banner Beranda', icon: DICON.banner, admin: true },
{ key: 'pageheaders', label: 'Header Halaman', icon: DICON.pageheaders, admin: true },
{ key: 'articles', label: 'Artikel', icon: DICON.articles, admin: false },
{ key: 'questions', label: 'Pertanyaan', icon: DICON.questions, admin: false },
{ key: 'registrations', label: 'Pendaftar', icon: DICON.registrations, admin: true },
{ key: 'donasi', label: 'Donasi', icon: DICON.donasi, admin: true },
{ key: 'toko', label: 'Toko Buku', icon: DICON.toko, admin: true },
{ key: 'programs', label: 'Program', icon: DICON.programs, admin: true },
{ key: 'teachers', label: 'Pengajar', icon: DICON.teachers, admin: true },
{ key: 'testimonials', label: 'Testimoni', icon: DICON.testimonials, admin: true },
{ key: 'fasilitas', label: 'Fasilitas', icon: DICON.fasilitas, admin: true },
{ key: 'kegiatan', label: 'Kegiatan', icon: DICON.kegiatan, admin: true },
{ key: 'settings', label: 'Pengaturan', icon: DICON.settings, admin: true },
{ key: 'smtp', label: 'Pengaturan Email', icon: DICON.globe, admin: true },
{ key: 'users', label: 'Pengguna', icon: DICON.users, admin: true },
].filter(m => !m.admin || isAdmin);
const Module = {
overview: ,
banner: ,
articles: ,
registrations: ,
donasi: ,
toko: ,
programs: ,
teachers: ,
testimonials: ,
fasilitas: ,
kegiatan: ,
settings: ,
pageheaders: ,
users: ,
smtp: ,
profile: ,
questions: ,
}[tab];
const sidebar = (

Dashboard
Qurrota A'yun
);
return (
{/* Sidebar desktop */}
{/* Sidebar mobile (drawer) */}
{mobileNav && (
setMobileNav(false)} style={{ position: 'fixed', inset: 0, background: 'rgba(0,0,0,.5)', zIndex: 200 }}>
e.stopPropagation()} style={{ width: 250, height: '100%', background: 'var(--brand-deep)' }}>{sidebar}
)}
{/* Main */}
{Module}
{pwModal &&
setPwModal(false)} toast={toast} />}
{toastNode}
);
}
/* ── Ringkasan ── */
function OverviewModule({ user, setTab }) {
const [stats, setStats] = useState({ articles: 0, regs: 0, campaigns: 0, donasi: 0 });
useEffect(() => {
Promise.all([
api.get('articles.php?action=all'),
api.get('registrations.php?action=list'),
api.get('donations.php?action=public_stats'),
]).then(([a, r, s]) => {
setStats({
articles: a.ok && a.articles ? a.articles.length : 0,
regs: r.ok && r.registrations ? r.registrations.length : 0,
campaigns: s.ok ? (s.kampanye_aktif ?? s.total_campaign ?? 0) : 0,
donasi: s.ok ? (s.total_masuk || 0) : 0,
});
});
}, []);
return (
Assalamu'alaikum, {user.name.split(' ')[0]}
Ringkasan aktivitas situs Markaz Qurrota A'yun.
Akses Cepat
setTab('articles')}>Tulis Artikel
setTab('registrations')}>Lihat Pendaftar
setTab('donasi')}>Kelola Donasi
);
}
window.Dashboard = Dashboard;
/* ── Modal ubah password sendiri ── */
function ChangePasswordModal({ onClose, toast }) {
const [f, setF] = useState({ old_password: '', new_password: '', confirm: '' });
const [saving, setSaving] = useState(false);
const [err, setErr] = useState('');
const submit = async () => {
if (f.new_password.length < 8) { setErr('Password baru minimal 8 karakter.'); return; }
if (f.new_password !== f.confirm) { setErr('Konfirmasi password tidak cocok.'); return; }
setSaving(true); setErr('');
const r = await api.post('auth.php?action=change_password', { old_password: f.old_password, new_password: f.new_password });
setSaving(false);
if (r.ok) { toast('✅ Password berhasil diubah'); onClose(); }
else setErr(r.error || 'Gagal mengubah password.');
};
return (
setF(s => ({ ...s, old_password: e.target.value }))} style={dInp} placeholder="••••••••" />
setF(s => ({ ...s, new_password: e.target.value }))} style={dInp} placeholder="••••••••" />
setF(s => ({ ...s, confirm: e.target.value }))} style={dInp} placeholder="••••••••" />
{err && {err}
}
{saving ? 'Menyimpan…' : '💾 Simpan'}
Batal
);
}
window.ChangePasswordModal = ChangePasswordModal;