ok
This commit is contained in:
@@ -1,16 +1,8 @@
|
|||||||
import React, { useState, useRef, useEffect, useCallback } from 'react';
|
import React, { useState, useRef, useEffect, useCallback } from 'react';
|
||||||
import { useParams, Link, useLocation } from 'react-router-dom';
|
import { useParams, Link, useLocation } from 'react-router-dom';
|
||||||
import CameraModal from './CameraModal';
|
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
|
// Icons
|
||||||
const BackIcon = () => (<svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth="2"><path strokeLinecap="round" strokeLinejoin="round" d="M15 19l-7-7 7-7" /></svg>);
|
const BackIcon = () => (<svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth="2"><path strokeLinecap="round" strokeLinejoin="round" d="M15 19l-7-7 7-7" /></svg>);
|
||||||
@@ -44,6 +36,7 @@ export default function InputDataPage() {
|
|||||||
setLoadingEntries(true);
|
setLoadingEntries(true);
|
||||||
try {
|
try {
|
||||||
const data = await fetchEntries(data_type_id);
|
const data = await fetchEntries(data_type_id);
|
||||||
|
console.log(data)
|
||||||
setEntries(data);
|
setEntries(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetch entries:", error);
|
console.error("Error fetch entries:", error);
|
||||||
@@ -110,7 +103,7 @@ export default function InputDataPage() {
|
|||||||
saved: false,
|
saved: false,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.warn(`Hasil scan kosong untuk file ${file.name}`);
|
console.warn(`Hasil scan kosong untuk file ${file.name}`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Gagal mengupload ${file.name}:`, error);
|
console.error(`Gagal mengupload ${file.name}:`, error);
|
||||||
@@ -135,6 +128,7 @@ export default function InputDataPage() {
|
|||||||
const renderField = (key, value) => {
|
const renderField = (key, value) => {
|
||||||
let type = "text";
|
let type = "text";
|
||||||
let options = [];
|
let options = [];
|
||||||
|
|
||||||
if (typeof expectation[key] === "object" && expectation[key] !== null) {
|
if (typeof expectation[key] === "object" && expectation[key] !== null) {
|
||||||
type = expectation[key].type;
|
type = expectation[key].type;
|
||||||
options = expectation[key].options || [];
|
options = expectation[key].options || [];
|
||||||
@@ -142,12 +136,60 @@ export default function InputDataPage() {
|
|||||||
type = expectation[key] || "text";
|
type = expectation[key] || "text";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === "date") return <input type="date" value={value} onChange={(e) => 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 === "selection") return <select value={value} onChange={(e) => updateField(key, e.target.value)} className="mt-1 block w-full border border-gray-300 rounded-md p-1">{options.map((opt, idx) => (<option key={idx} value={opt}>{opt}</option>))}</select>;
|
|
||||||
if (type === "number") return <input type="number" value={value} onChange={(e) => updateField(key, e.target.value)} className="mt-1 block w-full border border-gray-300 rounded-md p-1" />;
|
if (type === "date") {
|
||||||
return <input type="text" value={value} onChange={(e) => updateField(key, e.target.value)} className="mt-1 block w-full border border-gray-300 rounded-md p-1" />;
|
return (
|
||||||
|
<input
|
||||||
|
type="date"
|
||||||
|
value={value || ""}
|
||||||
|
placeholder="Pilih tanggal"
|
||||||
|
onChange={(e) => updateField(key, e.target.value)}
|
||||||
|
className={commonClass}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === "selection") {
|
||||||
|
return (
|
||||||
|
<select
|
||||||
|
value={value || ""}
|
||||||
|
onChange={(e) => updateField(key, e.target.value)}
|
||||||
|
className={commonClass}
|
||||||
|
>
|
||||||
|
<option disabled value="">-- Pilih salah satu --</option>
|
||||||
|
{(options || []).map((opt, idx) => (
|
||||||
|
<option key={idx} value={opt}>{opt}</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === "number") {
|
||||||
|
return (
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
value={value || ""}
|
||||||
|
placeholder="Masukkan angka"
|
||||||
|
onChange={(e) => updateField(key, e.target.value)}
|
||||||
|
className={commonClass}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default: text input
|
||||||
|
return (
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={value || ""}
|
||||||
|
placeholder="Masukkan teks"
|
||||||
|
onChange={(e) => updateField(key, e.target.value)}
|
||||||
|
className={commonClass}
|
||||||
|
/>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const toggleDelete = () => {
|
const toggleDelete = () => {
|
||||||
const newResults = [...uploadResults];
|
const newResults = [...uploadResults];
|
||||||
if (newResults[resultIndex]) {
|
if (newResults[resultIndex]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user