(null);
+
+ async function onDelete() {
+ const label = monthLabel(month);
+ const ok = window.confirm(
+ `¿Borrar por completo el calendario de ${label}?\n\nSe elimina el mes del portal y las piezas de Pipeline RRSS en borrador vinculadas. Las ya publicadas en Meta no se borran de la red (solo se desvinculan).`
+ );
+ if (!ok) return;
+ const typed = window.prompt(
+ `Escribe ${month} para confirmar el borrado definitivo:`
+ );
+ if (typed?.trim() !== month) {
+ setErr('Confirmación cancelada o incorrecta.');
+ return;
+ }
+ setBusy(true);
+ setErr(null);
+ try {
+ const r = await fetch('/api/calendar/month', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ action: 'delete_month', month }),
+ });
+ const j = await r.json();
+ if (!r.ok) throw new Error(j.error || 'No se pudo borrar');
+ router.push('/dashboard/calendario?view=archive');
+ router.refresh();
+ } catch (e) {
+ setErr(e instanceof Error ? e.message : 'Error al borrar');
+ } finally {
+ setBusy(false);
+ }
+ }
+
+ return (
+
+
+ {err ?
{err}
: null}
+
+ );
+}
diff --git a/src/components/RrssArchiveYear.tsx b/src/components/RrssArchiveYear.tsx
index e01c72a..b943b87 100644
--- a/src/components/RrssArchiveYear.tsx
+++ b/src/components/RrssArchiveYear.tsx
@@ -3,6 +3,7 @@ import Link from 'next/link';
import type { RrssMonthPlan, RrssPiece } from '@/components/RrssMonthView';
import CalendarCreator from '@/components/CalendarCreator';
import CalendarUpload from '@/components/CalendarUpload';
+import DeleteCalendarMonthButton from '@/components/DeleteCalendarMonthButton';
const MONTH_NAMES = [
'Enero',
@@ -35,10 +36,12 @@ function MiniMonth({
year,
monthIndex,
plan,
+ canDelete = false,
}: {
year: number;
monthIndex: number; // 0-11
plan?: RrssMonthPlan;
+ canDelete?: boolean;
}) {
const monthKey = `${year}-${String(monthIndex + 1).padStart(2, '0')}`;
const first = new Date(Date.UTC(year, monthIndex, 1));
@@ -126,12 +129,17 @@ function MiniMonth({
if (live) {
return (
-
- {body}
-
+
+
+ {body}
+
+ {canDelete ? (
+
+ ) : null}
+
);
}
@@ -237,6 +245,7 @@ export default function RrssArchiveYear({
year={year}
monthIndex={i}
plan={byMonth.get(key)}
+ canDelete={canUpload}
/>
);
})}