const { useState } = React; window.AdminAvisos = function({ globalUsers, reminders, showToast, refreshData }) { const [title, setTitle] = useState(''); const [message, setMessage] = useState(''); const [targetUsers, setTargetUsers] = useState([]); const [selectAll, setSelectAll] = useState(true); const [isMandatory, setIsMandatory] = useState(false); const [auditModalReminder, setAuditModalReminder] = useState(null); const [auditData, setAuditData] = useState(null); const [loadingAudit, setLoadingAudit] = useState(false); const handleSendNotice = async (e) => { e.preventDefault(); if (!title.trim() || !message.trim()) return showToast("Título y mensaje son requeridos."); const usersToSend = selectAll ? globalUsers.map(u => u.id) : targetUsers; if (usersToSend.length === 0) return showToast("Debes seleccionar al menos un usuario."); try { const res = await window.apiCall('save_reminder', { title: title.trim(), message: message.trim(), targetUsers: usersToSend, is_mandatory: isMandatory ? 1 : 0, createdAt: Date.now() }); if (res && res.success) { setTitle(''); setMessage(''); setSelectAll(true); setTargetUsers([]); setIsMandatory(false); showToast("Aviso difundido con éxito."); if (refreshData) await refreshData(); } else { showToast("Error al difundir: " + (res.error || "Desconocido")); } } catch (err) { showToast("Error de conexión al enviar aviso."); } }; const handleOpenAudit = async (reminder) => { setAuditModalReminder(reminder); setLoadingAudit(true); setAuditData(null); try { const res = await window.apiCall('get_reminder_audit', { id: reminder.id }); if (res && res.success) { setAuditData(res); } else { showToast("Error al cargar auditoría: " + (res?.error || "")); } } catch (err) { showToast("Error de red al consultar auditoría."); } finally { setLoadingAudit(false); } }; const handleDeleteReminder = async (id) => { await window.apiCall('delete_reminder', { id }); showToast("Aviso eliminado."); if (refreshData) await refreshData(); }; return (
{/* FORMULARIO DE DIFUSIÓN */}

Nuevo Aviso General

Llegará a las notificaciones de los colaboradores seleccionados

setTitle(e.target.value)} placeholder="Título del comunicado..." className="w-full p-3 bg-slate-50 border border-slate-200 rounded-xl font-medium text-slate-800 outline-none focus:border-slate-400 focus:bg-white text-xs min-h-[42px] transition-all" required />