diff --git a/src/components/Campana.jsx b/src/components/Campana.jsx index 4cb388f..ef9c1e1 100644 --- a/src/components/Campana.jsx +++ b/src/components/Campana.jsx @@ -1,13 +1,23 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import '../pages/users/campana.css'; const Campana = () => { const [isOpen, setIsOpen] = useState(false); + const [notificaciones, setNotificaciones] = useState([]); const toggleNotifications = () => { setIsOpen(!isOpen); }; + useEffect(() => { + if (isOpen && notificaciones.length === 0) { + fetch('http://localhost:8000/onesignal/notificaciones/') + .then((response) => response.json()) + .then((data) => setNotificaciones(data)) + .catch((error) => console.error('Error fetching notifications:', error)); + } + }, [isOpen]); + return (
{notificacion.message}
+