feature/csv-templates

This commit is contained in:
hreyes
2026-03-03 10:13:35 -07:00
parent ededff9dce
commit ec8c3a7c2d
26 changed files with 253 additions and 46 deletions

View File

@@ -4,6 +4,7 @@
import { UploadCloud, Lock } from 'lucide-svelte';
import { cn } from '$lib/utils';
import { toast } from 'svelte-sonner';
import { api } from '$lib/api';
let {
items,
@@ -88,7 +89,7 @@
}
}
function handleContextMenu(e: MouseEvent, item: CsvUploadItem) {
async function handleContextMenu(e: MouseEvent, item: CsvUploadItem) {
if (item.disabled) {
e.preventDefault();
return;
@@ -96,16 +97,23 @@
e.preventDefault();
if (!item.templateUrl) return;
if (!item.templateId) return;
const link = document.createElement('a');
link.href = item.templateUrl;
link.download = item.templateUrl.split('/').pop() || 'plantilla.xls';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
toast.info(`Descargando plantilla para ${item.title}...`);
try {
toast.info(`Descargando plantilla para ${item.title}...`);
const { blob, filename } = await api.getCsvTemplateDownload(item.templateId);
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = filename;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
toast.success(`Plantilla descargada: ${filename}`);
} catch (err) {
toast.error(err instanceof Error ? err.message : 'Error al descargar la plantilla');
}
}
</script>