Allow agency to fully delete an editorial calendar month.

Removes the calendar document and linked draft pipeline pieces, with confirm-by-typing the YYYY-MM code.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
4Ventures
2026-10-13 18:07:24 +02:00
parent fd2bd9582d
commit a225f8c2a6
5 changed files with 227 additions and 7 deletions

View File

@@ -361,6 +361,46 @@ export default function CalendarCreator({
}
}
async function deleteEntireMonth() {
if (!existingMonths.includes(month) && source !== 'existing') {
setErr('Este mes aún no está guardado en el portal.');
return;
}
const label = monthLabel(month);
if (
!confirm(
`¿Borrar por completo el calendario de ${label}?\n\nSe elimina el mes del portal y borradores de Pipeline RRSS vinculados.`
)
) {
return;
}
const typed = prompt(`Escribe ${month} para confirmar:`);
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 el mes');
setPlan(null);
setStep('pick');
setOpen(false);
router.push('/dashboard/calendario?view=archive');
router.refresh();
} catch (e) {
setErr(e instanceof Error ? e.message : 'Error al borrar');
} finally {
setBusy(false);
}
}
const dayPieces = dayZoom ? byDate.get(dayZoom) || [] : [];
return (
@@ -490,6 +530,17 @@ export default function CalendarCreator({
>
Guardar mes en portal
</button>
{existingMonths.includes(month) || source === 'existing' ? (
<button
type="button"
disabled={busy}
onClick={() => void deleteEntireMonth()}
className="inline-flex items-center gap-1.5 rounded-lg border border-red-200 bg-red-50 px-3 py-1.5 text-xs font-semibold text-red-700 hover:bg-red-100 disabled:opacity-60"
>
<Trash2 className="h-3.5 w-3.5" />
Borrar mes completo
</button>
) : null}
<span className="text-[11px] text-gray-500">
{plan?.pieces?.length || 0} piezas
{keepIds.size ? ` · ${keepIds.size} ✓` : ''}