31 lines
1.2 KiB
React
31 lines
1.2 KiB
React
|
|
import { useState, useEffect } from 'react';
|
||
|
|
import { useParams, Link } from 'react-router-dom';
|
||
|
|
import { getBookById } from '../api/books';
|
||
|
|
|
||
|
|
export default function BookDetail() {
|
||
|
|
const { bookId } = useParams();
|
||
|
|
const [book, setBook] = useState(null);
|
||
|
|
const [loading, setLoading] = useState(true);
|
||
|
|
const [error, setError] = useState(null);
|
||
|
|
|
||
|
|
useEffect(() => {getBookById(bookId).then((response) => setBook(response.data)).catch((err) => {console.error(err);setError('Livre introuvable.');}).finally(() => setLoading(false));}, [bookId]);
|
||
|
|
|
||
|
|
if (loading) return <main><p>Chargement…</p></main>;
|
||
|
|
if (error) return <main><p>{error}</p><Link to="/books">← Retour au catalogue</Link></main>;
|
||
|
|
|
||
|
|
return (
|
||
|
|
<main>
|
||
|
|
<Link to="/books">← Retour au catalogue</Link>
|
||
|
|
<h1>{book.title}</h1>
|
||
|
|
<p>Auteur : {book.author}</p>
|
||
|
|
<p>ISBN : {book.isbn}</p>
|
||
|
|
<p>Éditeur : {book.publisher}</p>
|
||
|
|
<p>Publié le : {book.publicationDate}</p>
|
||
|
|
<p>Prix : {book.price} €</p>
|
||
|
|
<p>Stock : {book.quantity}</p>
|
||
|
|
<p>Langue : {book.language}</p>
|
||
|
|
<p>Catégories : {book.categories?.join(', ')}</p>
|
||
|
|
{book.description && <p>{book.description}</p>}
|
||
|
|
</main>
|
||
|
|
);
|
||
|
|
}
|