bug fixed
This commit is contained in:
parent
8dca1f0a84
commit
ea2e952586
@ -925,36 +925,58 @@ const IsicHsCodes = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleExportCSV = () => {
|
||||
const csvHeader = headers.slice(0, headers.length - 1).join(',');
|
||||
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.setAttribute('download', 'hs-codes-export.csv');
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
|
||||
setToast({ show: true, message: 'CSV exported successfully!', type: 'success' });
|
||||
};
|
||||
const extractText = (node) => {
|
||||
if (typeof node === "string") return node; // string
|
||||
if (typeof node === "number") return String(node);
|
||||
|
||||
// React elementழா?
|
||||
if (node?.props?.children) {
|
||||
if (Array.isArray(node.props.children)) {
|
||||
return node.props.children.map(extractText).join(" ");
|
||||
}
|
||||
return extractText(node.props.children);
|
||||
}
|
||||
|
||||
return "";
|
||||
};
|
||||
|
||||
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");
|
||||
};
|
||||
|
||||
|
||||
const handleSaveForm = async () => {
|
||||
if (!form.code || !form.product) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user