2024-05-13 00:33:13 +02:00
|
|
|
import React, { useEffect, useState } from "react";
|
2024-05-13 00:13:34 +02:00
|
|
|
import "../../assets/styles/modal.css";
|
|
|
|
import "../../assets/styles/itembox.css";
|
|
|
|
import FormUpdateItem from "../form/formUpdateItem";
|
|
|
|
import { Image } from "../parts/image";
|
2024-05-13 00:33:13 +02:00
|
|
|
import { Description } from "../parts/description";
|
|
|
|
import { Characteristic } from "../parts/characteristic";
|
2024-03-27 11:47:47 +01:00
|
|
|
|
2024-05-11 22:37:32 +02:00
|
|
|
export const ItemBox = ({ model, brand, purchaseDate, price, _id }) => {
|
2024-05-13 00:13:34 +02:00
|
|
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
2024-05-11 22:37:32 +02:00
|
|
|
|
2024-05-13 00:13:34 +02:00
|
|
|
const openModal = () => {
|
|
|
|
setIsModalOpen(true);
|
|
|
|
};
|
2024-05-11 22:37:32 +02:00
|
|
|
|
2024-05-13 00:13:34 +02:00
|
|
|
const closeModal = () => {
|
|
|
|
setIsModalOpen(false);
|
|
|
|
};
|
2024-05-11 22:37:32 +02:00
|
|
|
|
2024-05-13 00:13:34 +02:00
|
|
|
let productname = brand + " " + model;
|
|
|
|
let formatedPrice = price + "€";
|
|
|
|
let formatedDate = new Date(purchaseDate).toLocaleDateString("fr-FR");
|
2024-05-11 22:37:32 +02:00
|
|
|
|
2024-05-13 00:13:34 +02:00
|
|
|
let request = brand + " " + model;
|
2024-05-11 22:37:32 +02:00
|
|
|
|
2024-05-13 00:13:34 +02:00
|
|
|
return (
|
|
|
|
<div className="product-details">
|
|
|
|
<Description title={productname}>
|
|
|
|
<Image request={request} _id={_id} alt="Product" />
|
|
|
|
<Characteristic label="Model" value={model} />
|
|
|
|
<Characteristic label="Brand" value={brand} />
|
|
|
|
<Characteristic label="Purchase Date" value={formatedDate} />
|
|
|
|
<Characteristic label="Price" value={formatedPrice} />
|
|
|
|
{/* Bouton d'édition pour ouvrir la fenêtre modale */}
|
|
|
|
<button onClick={openModal}>Edit</button>
|
|
|
|
</Description>
|
2024-05-13 00:33:13 +02:00
|
|
|
{/* Fenêtre modale */}
|
2024-05-13 00:13:34 +02:00
|
|
|
{isModalOpen && (
|
|
|
|
<div className="modal">
|
|
|
|
<div className="modal-content">
|
|
|
|
<span className="close" onClick={closeModal}>
|
|
|
|
×
|
|
|
|
</span>
|
2024-05-13 00:33:13 +02:00
|
|
|
<FormUpdateItem itemId={_id}>
|
|
|
|
{console.log("item ID :" + _id)}
|
|
|
|
</FormUpdateItem>
|
2024-05-13 00:13:34 +02:00
|
|
|
</div>
|
2024-05-09 18:39:06 +02:00
|
|
|
</div>
|
2024-05-13 00:13:34 +02:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|