update latest

This commit is contained in:
DmsAnhr 2026-02-10 08:56:22 +07:00
parent 677f126642
commit 01c4cf71b0
6 changed files with 31 additions and 16 deletions

View File

@ -62,6 +62,7 @@ export default function StepValidate() {
const table = state.result?.data; const table = state.result?.data;
const data = { const data = {
title: metadata.title, title: metadata.title,
path: state.result?.data.tmp_path,
columns: table.columns, columns: table.columns,
rows: table.preview, rows: table.preview,
author: metadata, author: metadata,

View File

@ -264,7 +264,7 @@ export default function StepSuccess() {
{/* Tombol Upload Lagi (Reset Context) */} {/* Tombol Upload Lagi (Reset Context) */}
<button <button
onClick={reset} onClick={reset}
className="text-gray-500 hover:text-gray-700 text-sm font-medium hover:underline transition" className="text-gray-500 hover:text-gray-700 text-sm font-medium hover:underline transition cursor-pointer"
> >
Upload data lagi Upload data lagi
</button> </button>

View File

@ -51,6 +51,11 @@ function UploadProviderContent({ children }: { children: React.ReactNode }) {
const stepParam = searchParams.get("step") as UploadStepType; const stepParam = searchParams.get("step") as UploadStepType;
const validSteps: UploadStepType[] = ["UPLOAD", "PDF_VIEWER", "TABLE_PICKER", "VALIDATE", "SUCCESS"]; const validSteps: UploadStepType[] = ["UPLOAD", "PDF_VIEWER", "TABLE_PICKER", "VALIDATE", "SUCCESS"];
// if (state.step === "SUCCESS" && stepParam !== "SUCCESS") {
// reset();
// return;
// }
if (stepParam && validSteps.includes(stepParam)) { if (stepParam && validSteps.includes(stepParam)) {
if (stepParam !== "UPLOAD" && !state.file) { if (stepParam !== "UPLOAD" && !state.file) {
router.replace(pathname); router.replace(pathname);
@ -63,11 +68,6 @@ function UploadProviderContent({ children }: { children: React.ReactNode }) {
} }
}, [searchParams, state.file, pathname, router]); }, [searchParams, state.file, pathname, router]);
const reset = () => {
setState(initialState);
router.push(pathname);
};
// 2. STATE -> URL (Handle Navigation) // 2. STATE -> URL (Handle Navigation)
// 🔥 Update Logic Navigation // 🔥 Update Logic Navigation
const goToStep = (newStep: UploadStepType, options?: { replace?: boolean }) => { const goToStep = (newStep: UploadStepType, options?: { replace?: boolean }) => {
@ -89,6 +89,12 @@ function UploadProviderContent({ children }: { children: React.ReactNode }) {
setState((prev) => ({ ...prev, step: newStep })); setState((prev) => ({ ...prev, step: newStep }));
}; };
const reset = () => {
setState(initialState);
router.push(pathname);
};
return ( return (
<UploadContext.Provider value={{ state, setState, reset, goToStep }}> <UploadContext.Provider value={{ state, setState, reset, goToStep }}>
{children} {children}

View File

@ -283,22 +283,28 @@ export function usePdfViewer() {
toast.warning("Harap pilih minimal 1 halaman untuk diproses."); toast.warning("Harap pilih minimal 1 halaman untuk diproses.");
return; return;
} }
setLoading(true); setLoading(true);
try { try {
const res = await uploadApi.uploadFile( const res = await uploadApi.uploadFile(
state.file!, state.file!,
localSelectedPages, localSelectedPages, // Kirim array halaman: [1, 2, 5]
null, null, // sheet null karena ini PDF
state.fileDesc state.fileDesc
); );
setState(prev => ({ ...prev, result: res })); setState(prev => ({ ...prev, result: res }));
if (res.tables && res.tables.length > 0) {
if (res.data.tables && res.data.tables.length > 0) {
goToStep("TABLE_PICKER"); goToStep("TABLE_PICKER");
toast.success(`Ditemukan ${res.tables.length} tabel. Silakan pilih tabel.`); toast.success(`Ditemukan ${res.data.tables.length} tabel. Silakan pilih tabel.`);
} else { } else if (!res.data.tables) {
goToStep("VALIDATE"); goToStep("VALIDATE");
toast.info("Tabel tidak terdeteksi spesifik, lanjut ke validasi."); toast.info("Tabel tidak terdeteksi spesifik, lanjut ke validasi.");
} else {
toast.warning(res.message);
} }
} catch (err: any) { } catch (err: any) {
console.error(err); console.error(err);
toast.error(err.message || "Gagal memproses halaman PDF terpilih."); toast.error(err.message || "Gagal memproses halaman PDF terpilih.");

View File

@ -167,7 +167,6 @@ export function useUploadLogic() {
const handleSaveToDatabase = async (payload: any) => { const handleSaveToDatabase = async (payload: any) => {
setLoading(true); setLoading(true);
try { try {
// Panggil API // Panggil API
const res = await uploadApi.saveToDatabase(payload); const res = await uploadApi.saveToDatabase(payload);

View File

@ -8,18 +8,21 @@ const uploadApi = {
if (sheet) formData.append("sheet", sheet); if (sheet) formData.append("sheet", sheet);
formData.append("file_desc", fileDesc); formData.append("file_desc", fileDesc);
return apiHelpers.post("/upload/file", formData, { // return apiHelpers.post("/upload/file", formData, {
return apiHelpers.post("/pipeline/analyze", formData, {
headers: { "Content-Type": "multipart/form-data" }, headers: { "Content-Type": "multipart/form-data" },
}); });
}, },
processPdf: async (data: any, fileName: string, fileDesc: string): Promise<any> => { processPdf: async (data: any, fileName: string, fileDesc: string): Promise<any> => {
const payload = { ...data, fileName, fileDesc }; const payload = { ...data, fileName, fileDesc };
return apiHelpers.post("/upload/process-pdf", payload); // return apiHelpers.post("/upload/process-pdf", payload);
return apiHelpers.post("/pipeline/analyze/df", payload);
}, },
saveToDatabase: async (data: any): Promise<any> => { saveToDatabase: async (data: any): Promise<any> => {
return apiHelpers.post("/upload/to-postgis", data); // return apiHelpers.post("/upload/to-postgis", data);
return apiHelpers.post("/pipeline/publish", data);
}, },
getStyles: async (): Promise<any> => { getStyles: async (): Promise<any> => {