This commit is contained in:
Vassshhh
2025-06-30 16:03:40 +07:00
parent bcd53de641
commit ac212226b3

View File

@@ -364,37 +364,53 @@ const Dashboard = () => {
}
}
};
const handleBatchUpload = async () => {
const token = localStorage.getItem('token');
const newFiles = [];
for (const file of selectedFiles) {
const formData = new FormData();
formData.append('file', file); // Kirim satu per satu file
formData.append('file', file);
const response = await fetch('https://bot.kediritechnopark.com/webhook/files/upload', {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`
// ❗Jangan set 'Content-Type' untuk FormData, biarkan browser mengaturnya
},
body: formData
});
if (!response.ok) {
if (response.ok) {
newFiles.push({
json: {
Key: file.name,
LastModified: new Date().toISOString(),
Size: file.size,
StorageClass: 'STANDARD'
}
});
} else {
console.error(`Upload gagal untuk file ${file.name}`);
}
}
// ✅ Set fileList sekaligus
setFileList((prev) => [...prev, ...newFiles]);
alert('Upload selesai');
setSelectedFiles([]); // Kosongkan setelah selesai upload
setSelectedFiles([]);
};
const handleBatchDelete = async () => {
if (!window.confirm(`Yakin ingin menghapus ${selectedKeys.length} file?`)) return;
const token = localStorage.getItem('token');
const successKeys = [];
const failedKeys = [];
for (const key of selectedKeys) {
try {
const response = await fetch(
`https://bot.kediritechnopark.com/webhook/files/delete?key=${encodeURIComponent(key)}`,
{
@@ -404,11 +420,35 @@ const handleBatchUpload = async () => {
}
}
);
if (response.ok) {
successKeys.push(key);
} else {
failedKeys.push(key);
}
} catch (err) {
console.error(`Gagal menghapus ${key}`, err);
failedKeys.push(key);
}
}
// ✅ Update fileList sekaligus
setFileList((prev) =>
prev.filter((file) => !successKeys.includes(file.json.Key))
);
// ✅ Kosongkan selected
setSelectedKeys([]);
// ✅ Beri feedback ke user
if (failedKeys.length === 0) {
alert('File berhasil dihapus.');
} else {
alert(`Sebagian gagal dihapus:\n${failedKeys.join('\n')}`);
}
};
// ⬇️ Jika masih loading, tampilkan full white screen
if (loading) {
return <div style={{ backgroundColor: 'white', width: '100vw', height: '100vh' }} />;