diff --git a/src/pages/InputDataPage.js b/src/pages/InputDataPage.js index e6fe5ee..f52bd6a 100644 --- a/src/pages/InputDataPage.js +++ b/src/pages/InputDataPage.js @@ -1,16 +1,8 @@ import React, { useState, useRef, useEffect, useCallback } from 'react'; import { useParams, Link, useLocation } from 'react-router-dom'; import CameraModal from './CameraModal'; +import { fetchEntries } from '../api'; -// --- MOCK API LOGIC --- -const fetchEntries = async (dataTypeId) => { - console.log(`Fetching entries for data_type_id: ${dataTypeId}`); - return new Promise(resolve => { - setTimeout(() => { - resolve([]); - }, 500); - }); -}; // Icons const BackIcon = () => (); @@ -44,6 +36,7 @@ export default function InputDataPage() { setLoadingEntries(true); try { const data = await fetchEntries(data_type_id); + console.log(data) setEntries(data); } catch (error) { console.error("Error fetch entries:", error); @@ -69,7 +62,7 @@ export default function InputDataPage() { return [...prevFiles, ...uniqueNewFiles]; }); }; - + const handleCaptureComplete = (imageFile) => { if (imageFile) { handleFiles([imageFile]); @@ -80,7 +73,7 @@ export default function InputDataPage() { const removeFile = (index) => { setFilesToUpload(prevFiles => prevFiles.filter((_, i) => i !== index)); }; - + const handleUpload = async () => { if (filesToUpload.length === 0) return; setIsUploading(true); @@ -110,7 +103,7 @@ export default function InputDataPage() { saved: false, }); } else { - console.warn(`Hasil scan kosong untuk file ${file.name}`); + console.warn(`Hasil scan kosong untuk file ${file.name}`); } } catch (error) { console.error(`Gagal mengupload ${file.name}:`, error); @@ -135,6 +128,7 @@ export default function InputDataPage() { const renderField = (key, value) => { let type = "text"; let options = []; + if (typeof expectation[key] === "object" && expectation[key] !== null) { type = expectation[key].type; options = expectation[key].options || []; @@ -142,12 +136,60 @@ export default function InputDataPage() { type = expectation[key] || "text"; } - if (type === "date") return updateField(key, e.target.value)} className="mt-1 block w-full border border-gray-300 rounded-md p-1" />; - if (type === "selection") return ; - if (type === "number") return updateField(key, e.target.value)} className="mt-1 block w-full border border-gray-300 rounded-md p-1" />; - return updateField(key, e.target.value)} className="mt-1 block w-full border border-gray-300 rounded-md p-1" />; + const commonClass = "mt-1 block w-full border border-gray-300 rounded-md p-1"; + + if (type === "date") { + return ( + updateField(key, e.target.value)} + className={commonClass} + /> + ); + } + + if (type === "selection") { + return ( + + ); + } + + if (type === "number") { + return ( + updateField(key, e.target.value)} + className={commonClass} + /> + ); + } + + // Default: text input + return ( + updateField(key, e.target.value)} + className={commonClass} + /> + ); }; + const toggleDelete = () => { const newResults = [...uploadResults]; if (newResults[resultIndex]) { @@ -155,7 +197,7 @@ export default function InputDataPage() { setUploadResults(newResults); } }; - + const handleSaveAllValid = async () => { const itemsToSave = uploadResults.filter(r => !r.deleted && !r.saved); if (itemsToSave.length === 0) { @@ -230,7 +272,7 @@ export default function InputDataPage() { ); }; - + const currentResult = uploadResults[resultIndex]; const fieldsPerPage = 3; const allFields = currentResult?.formData ? Object.entries(currentResult.formData) : []; @@ -294,7 +336,7 @@ export default function InputDataPage() { {renderEntriesTable()} - + {modalVisible && currentResult && (