39 lines
1.4 KiB
JavaScript
39 lines
1.4 KiB
JavaScript
"use client";
|
|
import { useState, useTransition } from "react";
|
|
import { useRouter } from "next/navigation";
|
|
import { marcarPlanListo } from "../../plan/actions";
|
|
|
|
// Botón «Marcar plan como listo» + estado del plan cerrado de ese día. `marca` ya viene formateado
|
|
// desde el servidor (hora de Nicaragua). Fuera de hoy/futuro solo muestra el estado.
|
|
export default function PlanListoBoton({ fecha, ownerEmail, nombre, version, marca, puedeMarcar }) {
|
|
const router = useRouter();
|
|
const [pendiente, empezar] = useTransition();
|
|
const [error, setError] = useState(null);
|
|
|
|
function marcar() {
|
|
setError(null);
|
|
empezar(async () => {
|
|
const r = await marcarPlanListo(fecha, ownerEmail);
|
|
if (!r.ok) setError(r.error);
|
|
else router.refresh();
|
|
});
|
|
}
|
|
|
|
return (
|
|
<div className="plan-listo no-print">
|
|
{version ? (
|
|
<span className="plan-listo-estado ok" title={`Plan de ${nombre}`}>
|
|
✓ Plan listo · v{version} · {marca}
|
|
</span>
|
|
) : (
|
|
<span className="plan-listo-estado">Plan sin marcar</span>
|
|
)}
|
|
{puedeMarcar && (
|
|
<button type="button" className="rep-btn" onClick={marcar} disabled={pendiente}>
|
|
{pendiente ? "Guardando…" : version ? "↻ Volver a marcar" : "✓ Marcar plan como listo"}
|
|
</button>
|
|
)}
|
|
{error && <span className="plan-listo-error">{error}</span>}
|
|
</div>
|
|
);
|
|
}
|