bug fixed
This commit is contained in:
parent
8dca1f0a84
commit
ea2e952586
@ -925,36 +925,58 @@ const IsicHsCodes = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleExportCSV = () => {
|
const extractText = (node) => {
|
||||||
const csvHeader = headers.slice(0, headers.length - 1).join(',');
|
if (typeof node === "string") return node; // string
|
||||||
const csvRows = rowsData.map((item) => {
|
if (typeof node === "number") return String(node);
|
||||||
return [
|
|
||||||
item.code,
|
|
||||||
item.product,
|
|
||||||
item.description || '-',
|
|
||||||
item.unit,
|
|
||||||
item.estimatedMapped,
|
|
||||||
item.createdBy,
|
|
||||||
item.updated || item.createdOn || '-',
|
|
||||||
item.status,
|
|
||||||
]
|
|
||||||
.map((value) => `"${String(value ?? '').replace(/"/g, '""')}"`)
|
|
||||||
.join(',');
|
|
||||||
});
|
|
||||||
|
|
||||||
const csvContent = csvHeader + '\n' + csvRows.join('\n');
|
// React elementழா?
|
||||||
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
|
if (node?.props?.children) {
|
||||||
const url = URL.createObjectURL(blob);
|
if (Array.isArray(node.props.children)) {
|
||||||
const link = document.createElement('a');
|
return node.props.children.map(extractText).join(" ");
|
||||||
link.href = url;
|
}
|
||||||
link.setAttribute('download', 'hs-codes-export.csv');
|
return extractText(node.props.children);
|
||||||
document.body.appendChild(link);
|
}
|
||||||
link.click();
|
|
||||||
document.body.removeChild(link);
|
return "";
|
||||||
URL.revokeObjectURL(url);
|
};
|
||||||
|
|
||||||
|
const handleExportCSV = () => {
|
||||||
|
// FIX HEADER TEXT EXTRACTION
|
||||||
|
const csvHeader = headers
|
||||||
|
.slice(0, headers.length - 1)
|
||||||
|
.map((h) => extractText(h.name)) // <-- main fix
|
||||||
|
.join(",");
|
||||||
|
|
||||||
|
// Rows same logic
|
||||||
|
const csvRows = rowsData.map((item) => {
|
||||||
|
return [
|
||||||
|
item.code,
|
||||||
|
item.product,
|
||||||
|
item.description || "-",
|
||||||
|
item.unit,
|
||||||
|
item.estimatedMapped,
|
||||||
|
item.createdBy,
|
||||||
|
item.updated || item.createdOn || "-",
|
||||||
|
item.status,
|
||||||
|
]
|
||||||
|
.map((value) => `"${String(value ?? "").replace(/"/g, '""')}"`)
|
||||||
|
.join(",");
|
||||||
|
});
|
||||||
|
|
||||||
|
const csvContent = csvHeader + "\n" + csvRows.join("\n");
|
||||||
|
|
||||||
|
const blob = new Blob([csvContent], { type: "text/csv;charset=utf-8;" });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
|
||||||
|
const link = document.createElement("a");
|
||||||
|
link.href = url;
|
||||||
|
link.download = "hs-codes-export.csv";
|
||||||
|
link.click();
|
||||||
|
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
showToast("CSV Exported successfully!", "success");
|
||||||
|
};
|
||||||
|
|
||||||
setToast({ show: true, message: 'CSV exported successfully!', type: 'success' });
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSaveForm = async () => {
|
const handleSaveForm = async () => {
|
||||||
if (!form.code || !form.product) {
|
if (!form.code || !form.product) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user