Skip to content

Commit

Permalink
add "Delete" button to the Details page.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSta95 committed Aug 14, 2024
1 parent 61ec448 commit 4219b65
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,19 @@ export default function BookDetailsPage() {
fetchBook();
},[])

const deleteBook = (id: string) => {
axios.delete("/api/books/" + id)
}


return (
<>
<article>
<h3>Title: {book.title}</h3>
<p>Author: {book.author}</p>
<p>More details...</p>
<Link to={"/"}>Back</Link>
<button onClick={() => {deleteBook(book.id)}}>Delete</button>
</article>
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@ import "./BookCard.css"

import {Book} from "../../../../types/types.ts";
import {Link} from "react-router-dom";
import {Book} from "../../types/types.ts";
import axios from "axios";

type BookCardProps = {
book: Book
}

const deleteBook = (id: string) => {
axios.delete("api/books/" + id)
.catch((error) => alert(error.message))
}

export default function BookCard({book}: BookCardProps) {

return (
Expand All @@ -22,7 +15,6 @@ export default function BookCard({book}: BookCardProps) {
<p>Id: {book.id}</p>
<p>Title: {book.title}</p>
<p>Author:{book.author}</p>
<button onClick={() => deleteBook(book.id)}>Delete</button>
<Link to={`/books/${book.id}`}>Details</Link>
</li>

Expand Down

0 comments on commit 4219b65

Please sign in to comment.