import React, { useState, useEffect } from 'react'; import { useParams, useNavigate, Link } from 'react-router-dom'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faChevronLeft } from '@fortawesome/free-solid-svg-icons'; import Sidebar from '../sidebar/Sidebar'; import '../../styles/Customize.css'; const Customize = () => { const { id } = useParams(); const navigate = useNavigate(); const [style, setStyle] = useState(''); const [material, setMaterial] = useState(''); const [productImage, setProductImage] = useState(''); useEffect(() => { // Fetch the product image URL based on the product ID const fetchProductImage = async () => { try { const response = await fetch(`/api/products/${id}`); const data = await response.json(); setProductImage(data.imageUrl); // Assume `data.imageUrl` is the URL of the product image } catch (error) { console.error('Error fetching product image:', error); } }; fetchProductImage(); }, [id]); const handleStyleChange = (event) => { setStyle(event.target.value); }; const handleMaterialChange = (event) => { setMaterial(event.target.value); }; const handleSave = () => { const customization = { productId: id, style, material, }; navigate('/setmeasurements'); fetch('/api/saveCustomization', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(customization), }) .then(response => response.json()) .then(data => { console.log('Success:', data); navigate('/setmeasurements'); // Redirect to the Set Measurements page }) .catch((error) => { console.error('Error:', error); }); }; return (
Loading image...
)}