import React, { useState } from "react"; import ModalComponent from './Modal'; import ProductDetailsPage from "./ProductDetailsPage"; function PriceHistoryTable({ priceHistory, onClose }) { const [isModalOpen, setIsModalOpen] = useState(false); const [currentProduct, setCurrentProduct] = useState({}) const openModal = (product) => { setCurrentProduct(product) setIsModalOpen(true); }; const closeModal = () => { setIsModalOpen(false); }; const getPriceData = (product) => { return product.priceHistory[0]; }; const getPriceChange = (product) => { if (product.priceHistory.length < 2) return 0; const currentPrice = product.priceHistory[0].price; const lastPrice = product.priceHistory[1].price; const change = 100 - (currentPrice / lastPrice) * 100; return Math.round(change * 100) / 100; }; return (
| Updated At | Name | Price | Price Change |
|---|---|---|---|
| {priceData.date} | openModal(product)}>{product.name} | ${priceData.price} | 0 ? { color: "red" } : { color: "green" }}> {change >= 0 && "+" } {change}% |