Skip to content

Commit 7bec0c2

Browse files
committed
no more ads
1 parent 65103c5 commit 7bec0c2

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/components/AdminDashboard.tsx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import axios from 'axios';
55
import '../index.css';
66

77
const AdminDashboard: React.FC = () => {
8-
const [ads, setAds] = useState<any[]>([]);
8+
const [notifications, setNotifications] = useState<any[]>([]);
99
const [loading, setLoading] = useState<boolean>(true); // State for loading spinner
1010
const [error, setError] = useState<string | null>(null); // State for error handling
1111

@@ -20,7 +20,7 @@ const AdminDashboard: React.FC = () => {
2020
},
2121
});
2222
if (Array.isArray(response.data)) {
23-
setAds(response.data);
23+
setNotifications(response.data);
2424
} else {
2525
console.error('Unexpected data format:', response.data);
2626
setError('Unexpected data format received from the server.');
@@ -41,7 +41,7 @@ const AdminDashboard: React.FC = () => {
4141
return;
4242
}
4343

44-
const adToDelete = ads[index];
44+
const adToDelete = notifications[index];
4545
const response = await fetch(`https://api.contigosanmarcos.com/panel/notifications/${adToDelete.id}`, {
4646
method: 'DELETE',
4747
headers: {
@@ -50,7 +50,7 @@ const AdminDashboard: React.FC = () => {
5050
});
5151

5252
if (response.ok) {
53-
setAds((prevAds) => prevAds.filter((_, i) => i !== index));
53+
setNotifications((prevNotifications) => prevNotifications.filter((_, i) => i !== index));
5454
alert(`Se borró con éxito el banner`);
5555
} else {
5656
alert(`Necesitas iniciar sesión primero`);
@@ -64,25 +64,25 @@ const AdminDashboard: React.FC = () => {
6464
) : error ? (
6565
<p className="error-message">{error}</p> // Display error message if any
6666
) : (
67-
<div className="ad-list">
68-
{ads.length > 0 ? (
69-
ads.map((ad, index) => (
70-
<div key={ad.id} className={`ad ad-item ${ad.ad_type}`}>
71-
{ad.ad_type === 'banner' ? (
72-
<div className="ad-banner">
73-
{ad.image_url && <img src={ad.image_url} alt={ad.ad_title} />}
67+
<div className="notification-list">
68+
{notifications.length > 0 ? (
69+
notifications.map((notification, index) => (
70+
<div key={notification.id} className={`notification notification-item ${notification.ad_type}`}>
71+
{notification.ad_type === 'banner' ? (
72+
<div className="notification-banner">
73+
{notification.image_url && <img src={notification.image_url} alt={notification.ad_title} />}
7474
</div>
7575
) : (
76-
<div className="ad-post">
77-
{ad.image_url && (
76+
<div className="notification-post">
77+
{notification.image_url && (
7878
<div className="ad-post-image">
79-
<img src={ad.image_url} alt={ad.ad_title} />
79+
<img src={notification.image_url} alt={notification.ad_title} />
8080
</div>
8181
)}
82-
{ad.ad_title && <h3>{ad.ad_title}</h3>}
83-
{ad.ad_content && <p>{ad.ad_content}</p>}
84-
{ad.target_url && (
85-
<a href={ad.target_url} target="_blank" rel="noopener noreferrer">
82+
{notification.ad_title && <h3>{notification.ad_title}</h3>}
83+
{notification.ad_content && <p>{notification.ad_content}</p>}
84+
{notification.target_url && (
85+
<a href={notification.target_url} target="_blank" rel="noopener noreferrer">
8686
More Info
8787
</a>
8888
)}
@@ -100,7 +100,7 @@ const AdminDashboard: React.FC = () => {
100100
</div>
101101
))
102102
) : (
103-
<p>No ads available.</p>
103+
<p>No notifications available.</p>
104104
)}
105105
</div>
106106
)}

0 commit comments

Comments
 (0)