TypeError: Image constructor: 'new' is required I think the issue in the wishlistItem…
- User
TypeError: Image constructor: 'new' is required I think the issue in the wishlistItem component.. 'use client';
import React from "react"; import { useRouter } from "next/navigation"; import { X } from "lucide-react"; import ShoppingBag from "@/components/ShoppingBag"; const getCheapestPrice = (product) => { const prices = [ product.price && product.price !== '0.00' ? parseFloat(product.price) : Infinity, ...(product.sizes?.map((size) => parseFloat(size.price)) || []), ...(product.colors?.flatMap((color) => [ parseFloat(color.price), ...(color.sizes?.map((size) => parseFloat(size.price)) || []), ]) || []), ].filter((price) => !isNaN(price) && isFinite(price));
return prices.length > 0 ? Math.min(...prices) : null;}; const WishlistItem = ({ product, onRemove }) => { const router = useRouter();
const handleShoppingBagClick = () => { router.push(`/products/${product.id}`); }; const image = product.images > 0 ? `https://storage.naayiq.com/resources/${product.images[0]?.url}` : "https://storage.naayiq.com/resources/noimage.webp" return ( <div className="bg-white rounded-lg p-4 flex items-stretch space-x-4 mb-4"> <div className="relative w-[30%] min-h-[120px]"> <Image src={image} alt={product.name} fill={true} unoptimized={true} className="object-cover rounded-md" /> </div> <div className="flex-grow flex flex-col justify-center"> <h3 className="font-serif font-medium text-base text-center">{product.name}</h3> <h3 className="font-serif font-medium text-base text-center">{getCheapestPrice(product)}</h3> </div> <div className="flex flex-col justify-center items-center space-y-2"> <button onClick={() => onRemove(product.id)} className="p-1"> <X size={24} /> </button> <button onClick={handleShoppingBagClick} className="bg-[#3B5345] rounded-full p-2"> <ShoppingBag width={24} height={24} /> </button> </div> </div> );};
export default WishlistItem; 'use client';
import { useState, useEffect, useCallback } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { CircleArrowLeft } from "lucide-react"; import WishlistItem from "@/components/WishlistItem";
export const getToken = () => { if (typeof window === 'undefined') return null; return localStorage.getItem('token'); // Adjust based on your token storage strategy };
export const fetchWithAuth = async (url, options = {}) => { const token = getToken(); if (!token) { throw new Error('No authentication token found'); }
const headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${token}`, ...options.headers, }; const response = await fetch(url, { ...options, headers, }); if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.message || 'API request failed'); } return response.json(); - Assistant