blob: 88fc3b0be2e340080648152205ec2a8eea5e542d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
import React, { useState, useEffect } from 'react';
import AdCard from '../components/AdCard';
import AdForm from '../components/AdForm';
import UploadForm from '../components/UploadForm';
import { fetchAds, addAd } from '../utils/api';
const ManageAds = () => {
const [ads, setAds] = useState([]);
useEffect(() => {
const getAds = async () => {
const adsData = await fetchAds();
setAds(adsData);
};
getAds();
}, []);
const handleAddAd = async (ad) => {
await addAd(ad);
setAds([...ads, ad]);
};
const handleUploadComplete = (url) => {
console.log('Uploaded file URL:', url);
// You can add logic here to save the uploaded file URL to your backend if needed
};
return (
<div>
<h1>Manage Ads</h1>
<AdForm onAddAd={handleAddAd} />
<UploadForm onUploadComplete={handleUploadComplete} />
<div>
{ads.map((ad) => (
<AdCard key={ad.id} ad={ad} />
))}
</div>
</div>
);
};
export default ManageAds;
|