'use client'; import React, { useRef, useState } from 'react'; import { useRouter } from 'next/navigation'; import { FileSpreadsheet, Loader2, Upload } from 'lucide-react'; export default function CalendarUpload({ tenantLabel, }: { tenantLabel?: string; }) { const router = useRouter(); const inputRef = useRef(null); const [busy, setBusy] = useState(false); const [msg, setMsg] = useState(null); const [err, setErr] = useState(null); async function onFile(file: File) { setBusy(true); setErr(null); setMsg(null); try { const fd = new FormData(); fd.append('file', file); const r = await fetch('/api/calendar/upload', { method: 'POST', body: fd }); const j = await r.json().catch(() => ({})); if (!r.ok) { setErr(j.error || 'No se pudo leer el archivo'); return; } const months = (j.months || []) as { month: string; pieces: number }[]; const summary = months .map((m) => `${m.month}: ${m.pieces} piezas`) .join(' · '); setMsg(`Listo para ${j.tenant || tenantLabel}. ${summary}`); const first = months[0]?.month; router.refresh(); if (first) { router.push(`/dashboard/calendario?view=month&month=${first}`); } } catch (e) { setErr(e instanceof Error ? e.message : 'Error al subir'); } finally { setBusy(false); } } return (

Subir calendario (CSV, Excel o JSON)

Plantilla oficial: Excel por mes con filas SEMANA / Story / POST (como Brava Octubre). También CSV con columnas fecha + título. Si el mes ya existía, se reemplaza.

Plantilla Excel (oficial) CSV alternativo { const f = e.target.files?.[0]; e.target.value = ''; if (f) void onFile(f); }} />
{msg ? (

{msg}

) : null} {err ? (

{err}

) : null}
); }