|
1 | | -import { useState, useContext} from 'react'; |
| 1 | +import { useContext, useState} from 'react'; |
2 | 2 | import { Heart, ShoppingCart, Star, ChevronDown } from 'lucide-react'; |
3 | 3 | import { useLocation } from 'react-router-dom'; |
4 | 4 | import useAlert from '../utils/setAlert'; |
5 | 5 | import { addBook } from '../utils/bookOperation'; // Import the addBook function |
6 | 6 | import { AuthContext } from '../../context/AuthContext'; |
7 | 7 |
|
8 | 8 | const BookPreviewPage = () => { |
9 | | - const {isAuthenticated, user} = useContext(AuthContext) |
10 | | - const [email] = useState(user ? user.email : ""); |
| 9 | + const {isAuthenticated} = useContext(AuthContext) |
11 | 10 | const { handleError, handleSuccess } = useAlert(); |
12 | 11 | const location = useLocation(); |
13 | 12 | const book = location.state || {}; |
@@ -38,18 +37,16 @@ const BookPreviewPage = () => { |
38 | 37 | handleError("Please select a period"); |
39 | 38 | }else{ |
40 | 39 | const options = { |
41 | | - email, |
42 | | - rentalPeriod |
| 40 | + rentalPeriod, |
| 41 | + bookName : book.title |
43 | 42 | } |
44 | 43 | setIsSubmitting(true); |
45 | 44 | addBook(book.title,type, handleError, handleSuccess, options); |
46 | 45 | setIsSubmitting(false); |
47 | 46 | } |
48 | | - }else{ |
| 47 | + }else if(type === 'wishlist'){ |
49 | 48 | const options = { |
50 | 49 | bookName : book.title, |
51 | | - email, |
52 | | - rentalPeriod |
53 | 50 | } |
54 | 51 | setIsSubmitting(true); |
55 | 52 | addBook(book.title,type, handleError, handleSuccess, options); |
|
0 commit comments