update latest
This commit is contained in:
parent
677f126642
commit
01c4cf71b0
|
|
@ -62,6 +62,7 @@ export default function StepValidate() {
|
|||
const table = state.result?.data;
|
||||
const data = {
|
||||
title: metadata.title,
|
||||
path: state.result?.data.tmp_path,
|
||||
columns: table.columns,
|
||||
rows: table.preview,
|
||||
author: metadata,
|
||||
|
|
|
|||
|
|
@ -264,7 +264,7 @@ export default function StepSuccess() {
|
|||
{/* Tombol Upload Lagi (Reset Context) */}
|
||||
<button
|
||||
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
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -51,6 +51,11 @@ function UploadProviderContent({ children }: { children: React.ReactNode }) {
|
|||
const stepParam = searchParams.get("step") as UploadStepType;
|
||||
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 !== "UPLOAD" && !state.file) {
|
||||
router.replace(pathname);
|
||||
|
|
@ -63,11 +68,6 @@ function UploadProviderContent({ children }: { children: React.ReactNode }) {
|
|||
}
|
||||
}, [searchParams, state.file, pathname, router]);
|
||||
|
||||
const reset = () => {
|
||||
setState(initialState);
|
||||
router.push(pathname);
|
||||
};
|
||||
|
||||
// 2. STATE -> URL (Handle Navigation)
|
||||
// 🔥 Update Logic Navigation
|
||||
const goToStep = (newStep: UploadStepType, options?: { replace?: boolean }) => {
|
||||
|
|
@ -89,6 +89,12 @@ function UploadProviderContent({ children }: { children: React.ReactNode }) {
|
|||
setState((prev) => ({ ...prev, step: newStep }));
|
||||
};
|
||||
|
||||
|
||||
const reset = () => {
|
||||
setState(initialState);
|
||||
router.push(pathname);
|
||||
};
|
||||
|
||||
return (
|
||||
<UploadContext.Provider value={{ state, setState, reset, goToStep }}>
|
||||
{children}
|
||||
|
|
|
|||
|
|
@ -283,22 +283,28 @@ export function usePdfViewer() {
|
|||
toast.warning("Harap pilih minimal 1 halaman untuk diproses.");
|
||||
return;
|
||||
}
|
||||
|
||||
setLoading(true);
|
||||
try {
|
||||
const res = await uploadApi.uploadFile(
|
||||
state.file!,
|
||||
localSelectedPages,
|
||||
null,
|
||||
localSelectedPages, // Kirim array halaman: [1, 2, 5]
|
||||
null, // sheet null karena ini PDF
|
||||
state.fileDesc
|
||||
);
|
||||
|
||||
setState(prev => ({ ...prev, result: res }));
|
||||
if (res.tables && res.tables.length > 0) {
|
||||
|
||||
if (res.data.tables && res.data.tables.length > 0) {
|
||||
goToStep("TABLE_PICKER");
|
||||
toast.success(`Ditemukan ${res.tables.length} tabel. Silakan pilih tabel.`);
|
||||
} else {
|
||||
toast.success(`Ditemukan ${res.data.tables.length} tabel. Silakan pilih tabel.`);
|
||||
} else if (!res.data.tables) {
|
||||
goToStep("VALIDATE");
|
||||
toast.info("Tabel tidak terdeteksi spesifik, lanjut ke validasi.");
|
||||
} else {
|
||||
toast.warning(res.message);
|
||||
}
|
||||
|
||||
} catch (err: any) {
|
||||
console.error(err);
|
||||
toast.error(err.message || "Gagal memproses halaman PDF terpilih.");
|
||||
|
|
|
|||
|
|
@ -167,7 +167,6 @@ export function useUploadLogic() {
|
|||
const handleSaveToDatabase = async (payload: any) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
|
||||
// Panggil API
|
||||
const res = await uploadApi.saveToDatabase(payload);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,18 +8,21 @@ const uploadApi = {
|
|||
if (sheet) formData.append("sheet", sheet);
|
||||
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" },
|
||||
});
|
||||
},
|
||||
|
||||
processPdf: async (data: any, fileName: string, fileDesc: string): Promise<any> => {
|
||||
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> => {
|
||||
return apiHelpers.post("/upload/to-postgis", data);
|
||||
// return apiHelpers.post("/upload/to-postgis", data);
|
||||
return apiHelpers.post("/pipeline/publish", data);
|
||||
},
|
||||
|
||||
getStyles: async (): Promise<any> => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user