"use client"; import { useCallback, useEffect, useState } from "react"; import { useCan } from "@/lib/abilities"; import { getNotificationAdminEmails, setNotificationAdminEmails, type NotificationAdminEmails, } from "@/lib/api"; import { formatDateTime } from "@/lib/labels"; /** * Who receives the per-job summary email. * * This used to be NOTIFICATION_ADMIN_EMAILS in the deployment environment, * which made "add Beto to the summaries" a redeploy. It is now a stored * setting; the env var still acts as the fallback until someone saves here, * so nothing changes for a deployment that never touches this screen. */ const SOURCE_NOTE: Record = { db: "Guardado desde esta pantalla.", env: "Viene de la configuración del despliegue (NOTIFICATION_ADMIN_EMAILS). Al guardar aquí, este valor toma precedencia.", default: "Nadie lo ha configurado; se están usando los valores por omisión.", }; export function AdminEmailsSetting() { const canEdit = useCan("setting:manage"); const [setting, setSetting] = useState(null); const [draft, setDraft] = useState(""); const [editing, setEditing] = useState(false); const [saving, setSaving] = useState(false); const [error, setError] = useState(null); const [saved, setSaved] = useState(false); const load = useCallback(async () => { try { const data = await getNotificationAdminEmails(); setSetting(data); setDraft(data.value.join(", ")); setError(null); } catch (e) { setError(e instanceof Error ? e.message : String(e)); } }, []); useEffect(() => { void load(); }, [load]); async function save() { setSaving(true); setError(null); setSaved(false); try { const emails = draft .split(",") .map((s) => s.trim()) .filter(Boolean); const data = await setNotificationAdminEmails(emails); setSetting(data); setDraft(data.value.join(", ")); setEditing(false); setSaved(true); } catch (e) { setError(e instanceof Error ? e.message : String(e)); } finally { setSaving(false); } } function cancel() { setDraft(setting?.value.join(", ") ?? ""); setEditing(false); setError(null); } if (!setting) { return (

Destinatarios del resumen

{error ? (
{error}
) : (

Cargando…

)}
); } return (

Destinatarios del resumen

Después de cada envío se manda un correo interno con el resultado (enviados, omitidos, fallidos). Estas son las direcciones que lo reciben. No afecta a los correos que reciben los clientes.

{canEdit && !editing && ( )}
{error && (
{error}
)} {editing ? (
) : (
{setting.value.length === 0 ? ( Nadie recibe el resumen de los envíos. ) : (
    {setting.value.map((email) => (
  • {email}
  • ))}
)}

{SOURCE_NOTE[setting.source]} {setting.updatedAt && ` Última edición: ${formatDateTime(setting.updatedAt)}.`} {saved && " Guardado."}

{!canEdit && (

Solo un ADMIN puede cambiar esta lista.

)}
)}
); }