1- import React from "react" ;
2- import { addToCart } from "../helpers/useCart" ;
3- import { ProductCard } from "../components/ProductCard" ;
4- import { listData } from "../data/listData" ;
5- import { Layout } from "../components/Layout" ;
6- import { CategoryList } from "../components/CategoryList" ;
7- import { CardDescriptor } from "../data/types" ;
8- import { CustomSection } from "../components/CustomizedSection" ;
1+ import React from 'react' ;
2+ import { ProductCard } from '../components/ProductCard' ;
3+ import { listData } from '../data/listData' ;
4+ import { Layout } from '../components/Layout' ;
5+ import { CategoryList } from '../components/CategoryList' ;
6+ import { CustomSection } from '../components/CustomizedSection' ;
97
108interface ProductDetailsProps {
11- id : string ;
9+ id : string ;
1210}
1311
1412export const ProductDetails : React . FC < ProductDetailsProps > = ( { id } ) => {
15- const productId = parseInt ( id , 10 ) ;
16-
17- console . log ( "Raw ID from props:" , id ) ;
18- console . log ( "Parsed Product ID:" , productId ) ;
19- console . log ( "List Data:" , listData ) ;
20-
13+ const productId = parseInt ( id , 10 ) ;
2114 const productToAdd = listData . find ( ( item ) => item . id === productId ) ;
2215
23- console . log ( "Matched Product:" , productToAdd ) ;
24-
25- const descriptionText =
26- "Elegant wedding bands featuring lustrous pearls, beautifully set in sleek, timeless bands." ;
27-
2816 const handleAddToCart = ( ) => {
2917 if ( productToAdd ) {
30- addToCart ( productToAdd ) ;
18+ const existingCart = JSON . parse ( localStorage . getItem ( 'cart' ) || '[]' ) ;
19+ const updatedCart = [ ...existingCart , productToAdd ] ;
20+ localStorage . setItem ( 'cart' , JSON . stringify ( updatedCart ) ) ;
21+ console . log ( 'Product added:' , productToAdd ) ;
22+ window . location . href = '/shoppingcart' ;
23+ } else {
24+ console . error ( 'Product not found' ) ;
3125 }
32- window . location . href = "/shoppingcart" ;
3326 } ;
3427
3528 const data : CardDescriptor [ ] = [
3629 {
37- img : " /homemadePinkDiamondRing.jpg" ,
38- collectionText : " Handmade Pink Diamond Ring" ,
30+ img : ' /homemadePinkDiamondRing.jpg' ,
31+ collectionText : ' Handmade Pink Diamond Ring' ,
3932 } ,
4033 {
41- img : " /diamondRingPinkRuby.jpg" ,
42- collectionText : " Diamond Ring with Pink Ruby" ,
34+ img : ' /diamondRingPinkRuby.jpg' ,
35+ collectionText : ' Diamond Ring with Pink Ruby' ,
4336 } ,
4437 {
45- img : " /whiteSandDiamondRing.jpg" ,
46- collectionText : " White Sand Diamond Ring" ,
38+ img : ' /whiteSandDiamondRing.jpg' ,
39+ collectionText : ' White Sand Diamond Ring' ,
4740 } ,
4841 ] ;
4942
@@ -56,14 +49,14 @@ export const ProductDetails: React.FC<ProductDetailsProps> = ({ id }) => {
5649 image = { productToAdd . img }
5750 subtitle = "In Platinum with Natural Diamond"
5851 breadCrumbItem = { [
59- { text : " Home" } ,
60- { text : " Jewelry" } ,
52+ { text : ' Home' } ,
53+ { text : ' Jewelry' } ,
6154 { text : productToAdd . category } ,
6255 ] }
6356 rating = { productToAdd . rating }
6457 reviews = "208 reviews"
6558 price = { productToAdd . newPrice }
66- description = { descriptionText }
59+ description = "Elegant wedding bands featuring lustrous pearls."
6760 addToCart = { handleAddToCart }
6861 />
6962 ) : (
0 commit comments