diff --git a/src/components/ErrorNotification.jsx b/src/components/ErrorNotification.jsx
new file mode 100644
index 0000000..b65ec70
--- /dev/null
+++ b/src/components/ErrorNotification.jsx
@@ -0,0 +1,61 @@
+import { useEffect } from "react";
+import { motion, AnimatePresence } from "framer-motion";
+
+export default function ErrorNotification({ message, onClose, duration = 4000 }) {
+ // Auto close setelah beberapa detik
+ useEffect(() => {
+ if (!message) return;
+ const timer = setTimeout(() => {
+ onClose && onClose();
+ }, duration);
+ return () => clearTimeout(timer);
+ }, [message, onClose, duration]);
+
+ return (
+
+ {message && (
+
+
+ {/* Icon */}
+
+
+ {/* Text */}
+
+
Terjadi Kesalahan
+
{message}
+
+
+ {/* Close Button */}
+
+
+
+ )}
+
+ );
+}
diff --git a/src/pages/admin/upload/controller_admin_upload.jsx b/src/pages/admin/upload/controller_admin_upload.jsx
index 9d5b896..b31d3f7 100644
--- a/src/pages/admin/upload/controller_admin_upload.jsx
+++ b/src/pages/admin/upload/controller_admin_upload.jsx
@@ -72,8 +72,9 @@ export function useUploadController() {
}else{
setLoading(false);
}
- } finally {
- // setLoading(false);
+ } catch(err){
+ setLoading(false);
+ throw err
}
};
@@ -84,8 +85,9 @@ export function useUploadController() {
const res = await uploadPdf(selectedTable);
dispatch(setResult(res));
navigate("/admin/upload/validate");
- } finally {
- // setLoading(false);
+ } catch(err){
+ setLoading(false);
+ throw err
}
};
@@ -100,8 +102,9 @@ export function useUploadController() {
const res = await saveToDatabase(data);
dispatch(setValidatedData(res));
navigate("/admin/upload/success");
- } finally {
- // setLoading(false);
+ } catch(err){
+ setLoading(false);
+ throw err
}
};
diff --git a/src/pages/admin/upload/service_admin_upload.jsx b/src/pages/admin/upload/service_admin_upload.jsx
index b22964a..3630672 100644
--- a/src/pages/admin/upload/service_admin_upload.jsx
+++ b/src/pages/admin/upload/service_admin_upload.jsx
@@ -40,8 +40,7 @@ export async function uploadFile(file, page = null, sheet = null) {
});
return response.data;
} catch (error) {
- console.error("Upload gagal:", error);
- throw error.response?.data || { message: "Gagal mengunggah file." };
+ throw error.response?.data.detail || "Gagal proses file.";
}
}
@@ -52,8 +51,7 @@ export async function uploadPdf(data) {
});
return response.data;
} catch (error) {
- console.error("Gagal kirim JSON:", error);
- throw error.response?.data || { message: "Terjadi kesalahan." };
+ throw error.response?.data.detail || { message: "Gagal proses file." };
}
}
@@ -65,7 +63,6 @@ export async function saveToDatabase(data) {
});
return response.data;
} catch (error) {
- console.error("Gagal kirim JSON:", error);
- throw error.response?.data || { message: "Terjadi kesalahan." };
+ throw error.response?.data.detail || { message: "Gagal upload data." };
}
}
diff --git a/src/pages/admin/upload/views_admin_upload.jsx b/src/pages/admin/upload/views_admin_upload.jsx
index f9f0426..f118dc3 100644
--- a/src/pages/admin/upload/views_admin_upload.jsx
+++ b/src/pages/admin/upload/views_admin_upload.jsx
@@ -1,10 +1,11 @@
+import { useEffect, useState } from "react";
import { useUploadController } from "./controller_admin_upload";
import { useDispatch } from "react-redux";
import LoadingOverlay from "../../../components/LoadingOverlay";
+import ErrorNotification from "../../../components/ErrorNotification";
import FileDropzone from "../../../components/FileDropzone";
import PdfPageSelector from "../../../components/PdfPageSelector";
import { Link } from "react-router-dom";
-import { useEffect } from "react";
import { reset } from "../../../store/slices/uploadSlice";
export default function ViewsAdminUploadStep1() {
@@ -26,6 +27,8 @@ export default function ViewsAdminUploadStep1() {
handleUpload,
handleNextPdf
} = useUploadController();
+ const [errorMsg, setErrorMsg] = useState("");
+ const ext = file ? file.name.split(".").pop().toLowerCase() : "";
const handlePageSelection = (pages) => {
console.log("Halaman PDF yang dipilih:", pages);
@@ -33,16 +36,34 @@ export default function ViewsAdminUploadStep1() {
dispatch(setSelectedPages(pages));
};
- const ext = file ? file.name.split(".").pop().toLowerCase() : "";
+ const handleProcess = async () => {
+ try {
+ await handleUpload();
+ } catch (err) {
+ setErrorMsg(err);
+ }
+ };
+
+ const handleProcessPdf = async () => {
+ try {
+ await handleNextPdf();
+ } catch (err) {
+ setErrorMsg(err);
+ }
+ };
useEffect(() => {
dispatch(reset())
}, [])
-
return (
+
setErrorMsg("")}
+ />
+
@@ -119,7 +140,7 @@ export default function ViewsAdminUploadStep1() {
{/* Tombol Upload */}
1) ? 'hidden' : 'block' }`}>