the image of the website template(product) is not being used as my wrapper background. Fix this error and any error that may not agree with my general json product entry: Json entry: {
"id": "template-16",
"name": "3D Voyage",
"price": 50,
"image": "images/product/voyager.png",
"description": "This is a mesmerizing 3D Voyage.",
"category": "React Template",
"featured": true,
"redirect": "",
"link": "https://portfolio3js.netlify.app"
} productContext.js: import { createContext, useContext, useEffect, useReducer } from "react";
import productsData from "../context/products.json"; // Corrected import
import reducer from "../Reducer/productReducer";
const AppContext = createContext();
const initialState = {
isLoading: false,
isError: false,
products: [],
featureProducts: [],
isSingleLoading: false,
singleProduct: {},
};
const AppProvider = ({ children }) => {
const [state, dispatch] = useReducer(reducer, initialState);
const loadProductsData = () => {
dispatch({ type: "SET_LOADING" });
try {
// Assuming productsData is correctly structured as an array of products
dispatch({ type: "SET_API_DATA", payload: productsData });
} catch (error) {
dispatch({ type: "API_ERROR" });
}
};
const getSingleProduct = (id) => {
dispatch({ type: "SET_SINGLE_LOADING" });
try {
const singleProduct = state.products.find((product) => product.id === id);
if (!singleProduct) throw new Error('Product not found');
dispatch({ type: "SET_SINGLE_PRODUCT", payload: singleProduct });
} catch (error) {
dispatch({ type: "SET_SINGLE_ERROR" });
}
};
useEffect(() => {
loadProductsData();
}, []);
return (
<AppContext.Provider value={{...state, getSingleProduct }}>
{children}
</AppContext.Provider>
);
};
const useProductContext = () => {
return useContext(AppContext);
};
export { AppProvider, AppContext, useProductContext }; SingleProduct.js: import styled from "styled-components";
import React, { useEffect, useState } from 'react'
import { useParams } from "react-router-dom";
import { useProductContext } from "./context/productContext";
import FormatPrice from "./Helpers/FormatPrice";
import PageNavigation from "./components/PageNavigation";
import { Container } from "./Container";
import AddToCart from "./components/AddToCart";
import Modal from './Popup';
import { motion } from "framer-motion";
import { fadeIn } from "./components/variants";
const SingleProduct = () => {
const { getSingleProduct, isSingleLoading, singleProduct } = useProductContext();
const { id } = useParams();
useEffect(() => {
// Attempt to fetch product data as the component mounts
getSingleProduct(id);
}, [id, getSingleProduct]);
// React needs all hooks to be used in the same order
// between renders, even when the component returns early.
if (!singleProduct || isSingleLoading) {
// Early return should happen after all hooks have been called
return Loading...;
}
// Destructuring ‘singleProduct’ after the possibility of an early return has been checked
const { image, name, category, description, link, price } = singleProduct;
const transitionVariants = {
initial: {
x: "100%",
width: "100%",
},
animate: {
x: "0%",
width: "0%",
},
exit: {
x: ["0%", "100%"],
width: ["0%", "100%"],
},
};
return
<motion.div
className="singleProda"
variants={fadeIn("down", 0.4)}
initial="hidden"
animate="show"
exit="hidden"
>
{/* Product data */}
{name}
MRP:
<FormatPrice price={price + 250000}/>
Deal of the Day:
{description}
Available: "In Stock"
ID : {id}
Category : {category}
</motion.div>
;
}
const Wrapper = styled.section`
background-image: url(${(props) => props.image});
background-repeat: no-repeat;
background-size: cover; // Or whatever fits your design best
background-position: center;
box-shadow: inset 0 0 0 2000px rgba(0, 0, 0, 0.85);
.container {
padding: 9rem 0;
}
header {
border-radius:none!important;
}
.product_images{
display:flex;
align-items:center;
}
.product-data {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
gap: 2rem;
.product-data-warranty {
width: 100%;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid #ccc;
margin-bottom: 1rem;
.product-warranty-data {
text-align: center;
.warranty-icon {
background-color: rgba(220, 220, 220, 0.5);
border-radius: 50%;
width: 4rem;
height: 4rem;
padding: 0.6rem;
}
p {
font-size: 1.4rem;
padding-top: 0.4rem;
}
}
}
.product-data-price {
font-weight: bold;
}
.product-data-real-price {
color: ${({ theme }) => theme.colors.btn};
}
.product-data-info {
display: flex;
flex-direction: column;
gap: 1rem;
font-size: 1.8rem;
span {
font-weight: bold;
}
}
hr {
max-width: 100%;
width: 90%;
/* height: 0.2rem; */
border: 0.1rem solid #000;
color: red;
}
}
.product-images {
display: flex;
justify-content: center;
align-items: center;
}
@media (max-width: ${({ theme }) => theme.media.mobile}) {
padding: 0 2.4rem;
}
`;
export default SingleProduct;