ok
This commit is contained in:
@@ -41,19 +41,58 @@ export default function AddDocumentModal({ isOpen, onClose }) {
|
|||||||
const handleAddOption = (fieldId) => {setFields(fields.map(field =>field.id === fieldId? { ...field, options: [...field.options, { id: Date.now(), value: '' }] }: field));};
|
const handleAddOption = (fieldId) => {setFields(fields.map(field =>field.id === fieldId? { ...field, options: [...field.options, { id: Date.now(), value: '' }] }: field));};
|
||||||
const handleOptionChange = (fieldId, optionId, event) => {const { value } = event.target;setFields(fields.map(field =>field.id === fieldId? { ...field, options: field.options.map(opt => opt.id === optionId ? { ...opt, value } : opt) }: field));};
|
const handleOptionChange = (fieldId, optionId, event) => {const { value } = event.target;setFields(fields.map(field =>field.id === fieldId? { ...field, options: field.options.map(opt => opt.id === optionId ? { ...opt, value } : opt) }: field));};
|
||||||
const handleRemoveOption = (fieldId, optionId) => {setFields(fields.map(field =>field.id === fieldId? { ...field, options: field.options.filter(opt => opt.id !== optionId) }: field));};
|
const handleRemoveOption = (fieldId, optionId) => {setFields(fields.map(field =>field.id === fieldId? { ...field, options: field.options.filter(opt => opt.id !== optionId) }: field));};
|
||||||
const handleSave = () => {
|
const handleSave = async () => {
|
||||||
const newDocumentType = {
|
// Validasi nama tipe dokumen
|
||||||
template: selectedTemplate,
|
if (!docTypeName.trim()) {
|
||||||
name: docTypeName,
|
alert("Nama tipe dokumen wajib diisi");
|
||||||
fields: fields.map(({ id, name, type, options }) => ({
|
return;
|
||||||
name,
|
}
|
||||||
type,
|
// Siapkan expectation sesuai format backend
|
||||||
...(type === 'Selection' && { options: options.map(opt => opt.value) })
|
const expectation = {};
|
||||||
}))
|
fields.forEach(field => {
|
||||||
};
|
if (!field.name.trim()) return;
|
||||||
console.log("Menyimpan data JSON:", JSON.stringify(newDocumentType, null, 2));
|
if (field.type === "Selection") {
|
||||||
onClose();
|
expectation[field.name] = {
|
||||||
setSelectedTemplate(null);
|
type: "selection",
|
||||||
|
options: field.options.map(opt => opt.value).filter(Boolean)
|
||||||
|
};
|
||||||
|
} else if (field.type === "Number") {
|
||||||
|
expectation[field.name] = "number";
|
||||||
|
} else if (field.type === "Date") {
|
||||||
|
expectation[field.name] = "date";
|
||||||
|
} else {
|
||||||
|
expectation[field.name] = "text";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const org = localStorage.getItem('selected_organization');
|
||||||
|
if (!org) throw new Error("Organisasi belum dipilih");
|
||||||
|
const { organization_id } = JSON.parse(org);
|
||||||
|
|
||||||
|
const res = await fetch("https://bot.kediritechnopark.com/webhook/create-data-type", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
organization_id,
|
||||||
|
nama_tipe: docTypeName,
|
||||||
|
expectation,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
if (!res.ok) {
|
||||||
|
const errData = await res.json().catch(() => ({}));
|
||||||
|
throw new Error(errData.message || "Gagal menambah jenis dokumen");
|
||||||
|
}
|
||||||
|
// Reset state dan tutup modal
|
||||||
|
setSelectedTemplate(null);
|
||||||
|
setDocTypeName('');
|
||||||
|
setFields([]);
|
||||||
|
onClose();
|
||||||
|
// Jika DashboardPage Anda memakai onSuccess, panggil juga di sini:
|
||||||
|
// if (typeof onSuccess === "function") onSuccess();
|
||||||
|
} catch (err) {
|
||||||
|
alert(err.message);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isOpen) return null;
|
if (!isOpen) return null;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export default function InputDataPage() {
|
|||||||
const fileInputRef = useRef(null);
|
const fileInputRef = useRef(null);
|
||||||
const cameraInputRef = useRef(null);
|
const cameraInputRef = useRef(null);
|
||||||
const [isDragging, setIsDragging] = useState(false);
|
const [isDragging, setIsDragging] = useState(false);
|
||||||
|
console.log(expectation)
|
||||||
// --- PERUBAHAN: State baru untuk progress upload ---
|
// --- PERUBAHAN: State baru untuk progress upload ---
|
||||||
const [uploadProgress, setUploadProgress] = useState(0);
|
const [uploadProgress, setUploadProgress] = useState(0);
|
||||||
|
|
||||||
@@ -47,6 +47,7 @@ export default function InputDataPage() {
|
|||||||
const totalFiles = filesToUpload.length;
|
const totalFiles = filesToUpload.length;
|
||||||
const successfulUploads = [];
|
const successfulUploads = [];
|
||||||
const failedUploads = [];
|
const failedUploads = [];
|
||||||
|
const allResults = []; // <-- Variabel untuk mengumpulkan semua hasil
|
||||||
|
|
||||||
for (let i = 0; i < totalFiles; i++) {
|
for (let i = 0; i < totalFiles; i++) {
|
||||||
const file = filesToUpload[i];
|
const file = filesToUpload[i];
|
||||||
@@ -71,6 +72,7 @@ export default function InputDataPage() {
|
|||||||
|
|
||||||
const resultJson = await response.json();
|
const resultJson = await response.json();
|
||||||
successfulUploads.push({ file: file.name, result: resultJson });
|
successfulUploads.push({ file: file.name, result: resultJson });
|
||||||
|
allResults.push(resultJson); // <-- Kumpulkan hasil response di sini
|
||||||
console.log(`Sukses mengupload ${file.name}:`, resultJson);
|
console.log(`Sukses mengupload ${file.name}:`, resultJson);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -82,6 +84,9 @@ export default function InputDataPage() {
|
|||||||
setIsUploading(false);
|
setIsUploading(false);
|
||||||
setUploadProgress(0);
|
setUploadProgress(0);
|
||||||
|
|
||||||
|
// allResults sekarang berisi array hasil response dari semua file
|
||||||
|
console.log("Semua hasil response:", allResults);
|
||||||
|
|
||||||
// Beri ringkasan hasil upload
|
// Beri ringkasan hasil upload
|
||||||
alert(`Selesai! Berhasil: ${successfulUploads.length}, Gagal: ${failedUploads.length}`);
|
alert(`Selesai! Berhasil: ${successfulUploads.length}, Gagal: ${failedUploads.length}`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user