feat : fix fetch bug
This commit is contained in:
+66
-18
@@ -85,27 +85,49 @@
|
||||
|
||||
<div class="bg-white p-5 rounded-xl shadow-sm border border-gray-200 space-y-3 text-center">
|
||||
<h3 class="text-xs font-bold uppercase tracking-wider text-gray-500 mb-2">Aksi Otoritas Dokumen</h3>
|
||||
<button onclick="proses_keputusan_admin('Verified')" class="w-full py-3 bg-emerald-600 hover:bg-emerald-700 text-white text-xs font-bold rounded-lg transition-colors shadow-sm">Setujui Sebagai Mustahik</button>
|
||||
<button onclick="proses_keputusan_admin('Rejected')" class="w-full py-3 bg-red-600 hover:bg-red-700 text-white text-xs font-bold rounded-lg transition-colors shadow-sm">Tolak Pengajuan Bantuan</button>
|
||||
<button onclick="ubah_status_verifikasi(id_warga_terpilih, 'Verified')" class="w-full py-3 bg-emerald-600 hover:bg-emerald-700 text-white text-xs font-bold rounded-lg transition-colors shadow-sm">Setujui Sebagai Mustahik</button>
|
||||
<button onclick="ubah_status_verifikasi(id_warga_terpilih, 'Rejected')" class="w-full py-3 bg-red-600 hover:bg-red-700 text-white text-xs font-bold rounded-lg transition-colors shadow-sm">Tolak Pengajuan Bantuan</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</main>
|
||||
|
||||
<div id="modal_konfirmasi" class="fixed inset-0 z-50 flex items-center justify-center hidden bg-gray-900 bg-opacity-50 backdrop-blur-sm transition-opacity">
|
||||
<div class="bg-white p-6 rounded-2xl shadow-2xl w-full max-w-sm border border-gray-200 transform transition-all">
|
||||
<div class="flex items-center gap-4 mb-4">
|
||||
<div class="w-12 h-12 rounded-full bg-yellow-50 flex items-center justify-center text-yellow-500 flex-shrink-0">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>
|
||||
</div>
|
||||
<div>
|
||||
<h3 class="text-lg font-bold text-gray-900">Konfirmasi Aksi</h3>
|
||||
<p class="text-xs text-gray-500 mt-1">Tindakan ini akan mengubah basis data.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p id="teks_pesan_modal" class="text-sm text-gray-700 mb-6 py-2 border-y border-gray-100">
|
||||
Apakah Anda yakin ingin mengubah status data ini?
|
||||
</p>
|
||||
|
||||
<div class="flex justify-end gap-3">
|
||||
<button onclick="tutup_modal()" class="px-4 py-2.5 text-xs font-bold text-gray-600 bg-gray-100 hover:bg-gray-200 rounded-xl transition-colors">Batalkan</button>
|
||||
<button onclick="eksekusi_perubahan_status()" id="btn_modal_setuju" class="px-4 py-2.5 text-xs font-bold text-white bg-gray-900 hover:bg-gray-800 rounded-xl transition-colors shadow-sm">Ya, Lanjutkan</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Ekstraksi parameter ID dari string URL query browser
|
||||
const parameter_url = new URLSearchParams(window.location.search);
|
||||
const id_warga_terpilih = parameter_url.get('id');
|
||||
|
||||
let instansi_peta_detail = null;
|
||||
let antrean_id_warga = null;
|
||||
let antrean_status_baru = null;
|
||||
|
||||
// Memformat nominal angka reguler menjadi format mata uang Rupiah Indonesia
|
||||
function format_mata_uang_rupiah(angka) {
|
||||
return new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR', maximumFractionDigits: 0 }).format(angka);
|
||||
}
|
||||
|
||||
// Memetakan posisi koordinat spasial warga ke dalam objek Leaflet.js
|
||||
function petakan_lokasi_warga(lat, lng, nama) {
|
||||
if (!lat || !lng) return;
|
||||
|
||||
@@ -119,9 +141,7 @@
|
||||
.openPopup();
|
||||
}
|
||||
|
||||
// Merender seluruh string objek data yang ditarik secara aman ke komponen UI
|
||||
function isi_komponen_antarmuka(data) {
|
||||
// Keamanan XSS: Memanfaatkan textContent murni untuk mencegah injeksi skrip HTML
|
||||
document.getElementById('det_id_sistem').textContent = data.id;
|
||||
document.getElementById('det_nama_kk').textContent = data.nama_kk;
|
||||
document.getElementById('det_nik').textContent = data.nik;
|
||||
@@ -152,20 +172,17 @@
|
||||
badge.className = 'inline-block px-2.5 py-1 text-[10px] font-bold rounded-md bg-yellow-50 text-yellow-700 border border-yellow-200';
|
||||
}
|
||||
|
||||
// Eksekusi pemetaan visual spasial
|
||||
petakan_lokasi_warga(parseFloat(data.lat), parseFloat(data.lng), data.nama_kk);
|
||||
}
|
||||
|
||||
// Meminta muatan data spesifik satu warga ke peladen Express Node.js
|
||||
async function ambil_data_detail_warga() {
|
||||
if (!id_warga_terpilih) {
|
||||
return alert('ID parameter tidak ditemukan pada URL peramban.');
|
||||
}
|
||||
|
||||
try {
|
||||
/* Baris Kompleks: Melakukan pemanggilan asinkron GET menuju rute detail REST API
|
||||
dengan menyertakan nilai parameter ID target untuk diolah kueri SQL JOIN oleh peladen. */
|
||||
const http_response = await fetch(`http://localhost:3000/api/admin/mustahik/${id_warga_terpilih}`);
|
||||
// Diubah ke relative path
|
||||
const http_response = await fetch(`/api/admin/mustahik/${id_warga_terpilih}`);
|
||||
const json_result = await http_response.json();
|
||||
|
||||
if (!http_response.ok) throw new Error(json_result.error || 'Gagal mengambil data detail.');
|
||||
@@ -177,29 +194,60 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Memproses mutasi perubahan status persetujuan data dari panel admin ke server
|
||||
async function proses_keputusan_admin(keputusan_status) {
|
||||
if (!confirm(`Apakah Anda yakin memvalidasi data ini dengan status ${keputusan_status}?`)) return;
|
||||
function ubah_status_verifikasi(id_warga, status_baru) {
|
||||
antrean_id_warga = id_warga;
|
||||
antrean_status_baru = status_baru;
|
||||
|
||||
const teks_pesan = document.getElementById('teks_pesan_modal');
|
||||
teks_pesan.innerHTML = `Apakah Anda yakin memvalidasi data ini dengan status <span class="font-bold text-gray-900">${status_baru}</span>?`;
|
||||
|
||||
const tombol_setuju = document.getElementById('btn_modal_setuju');
|
||||
if (status_baru === 'Verified') {
|
||||
tombol_setuju.className = 'px-4 py-2.5 text-xs font-bold text-white bg-emerald-600 hover:bg-emerald-700 rounded-xl transition-colors shadow-sm';
|
||||
} else {
|
||||
tombol_setuju.className = 'px-4 py-2.5 text-xs font-bold text-white bg-red-600 hover:bg-red-700 rounded-xl transition-colors shadow-sm';
|
||||
}
|
||||
|
||||
document.getElementById('modal_konfirmasi').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function tutup_modal() {
|
||||
document.getElementById('modal_konfirmasi').classList.add('hidden');
|
||||
antrean_id_warga = null;
|
||||
antrean_status_baru = null;
|
||||
}
|
||||
|
||||
async function eksekusi_perubahan_status() {
|
||||
if (!antrean_id_warga || !antrean_status_baru) return;
|
||||
|
||||
const tombol_setuju = document.getElementById('btn_modal_setuju');
|
||||
tombol_setuju.disabled = true;
|
||||
tombol_setuju.textContent = 'Memproses...';
|
||||
|
||||
try {
|
||||
const http_response = await fetch(`http://localhost:3000/api/admin/verifikasi/${id_warga_terpilih}`, {
|
||||
// Diubah ke relative path
|
||||
const http_response = await fetch(`/api/admin/verifikasi/${antrean_id_warga}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ status_validasi: keputusan_status })
|
||||
body: JSON.stringify({ status_validasi: antrean_status_baru })
|
||||
});
|
||||
|
||||
const json_result = await http_response.json();
|
||||
if (!http_response.ok) throw new Error(json_result.error || 'Gagal mengubah status.');
|
||||
|
||||
tutup_modal();
|
||||
alert('Status otorisasi data berhasil diperbarui!');
|
||||
window.location.reload();
|
||||
|
||||
} catch (error_sistem) {
|
||||
tutup_modal();
|
||||
alert('Gagal mengeksekusi perintah: ' + error_sistem.message);
|
||||
} finally {
|
||||
tombol_setuju.disabled = false;
|
||||
tombol_setuju.textContent = 'Ya, Lanjutkan';
|
||||
}
|
||||
}
|
||||
|
||||
// Eksekusi inisialisasi pemuatan data awal
|
||||
ambil_data_detail_warga();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user