-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBestDeals.tsx
67 lines (57 loc) · 2.2 KB
/
BestDeals.tsx
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React, { useEffect, useState } from 'react';
const BestDeals: React.FC = () => {
const [imageUrl, setImageUrl] = useState<string | null>(null);
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<string | null>(null);
const productId = "084bfddb-c87a-42b0-aa27-2f71f39e7671";
useEffect(() => {
const fetchImage = async () => {
try {
setLoading(true);
const response = await fetch(`http://localhost:5000/readProduct/${productId}`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();
const imageUrl = data.image;
setImageUrl(imageUrl);
} catch (error: any) {
setError('Failed to load image');
} finally {
setLoading(false);
}
};
fetchImage();
}, [productId]);
return (
<section className="bg-primary text-white p-8 sm:p-16 md:pl-24 flex flex-col md:flex-row items-center justify-between sm:items-center justify-center gap-10 sm:gap-0 md:gap-10 font-outfit text-lg md:text-xl sm:text-sm min=-h-screen">
<div className="md:w-1/2 mb-8 md:mb-0 md:mr-8">
<h2 className="text-2xl sm:text-xl md:text-3xl font-bold mb-4 md:mb-8">
Best Samsung TV Deals
</h2>
<p className="text-base sm:text-sm md:text-xl mb-4 md:mb-6">
Discover the latest Samsung TV deals at unbeatable prices. Whether
you are upgrading your home entertainment setup or looking for the perfect gift,
we've got you covered.
</p>
<p className="text-base sm:text-sm md:text-xl font-semibold mb-4 md:mb-6">
From 678,453
<span className="bg-sky-400 text-black p-1 px-3 text-xs sm:text-sm rounded-xl">Rwf</span>
</p>
<button className="bg-secondary px-4 py-2 sm:px-6 sm:py-2 rounded-lg text-base sm:text-sm md:text-lg">
Shop Now
</button>
</div>
<div className="md:w-1/2">
{loading ? (
<div>Loading...</div>
) : error ? (
<div>Error: {error}</div>
) : (
<img src={imageUrl!} alt="Samsung TV" className="w-full h-full object-contain rounded-lg mx-auto sm:mx-0" />
)}
</div>
</section>
);
};
export default BestDeals;