diff --git a/client/src/Pages/Cart.jsx b/client/src/Pages/Cart.jsx index 61d501b..142b034 100644 --- a/client/src/Pages/Cart.jsx +++ b/client/src/Pages/Cart.jsx @@ -34,12 +34,18 @@ const Cart = () => { setLoading(false); } } + } else { + setLoading(false); } }; useEffect(() => { - fetchCartData(); - }, [dispatch]); + if (userLoggedIn) { + fetchCartData(); + } else { + setLoading(false); + } + }, [dispatch, userLoggedIn]); useEffect(() => { if (!loading) { @@ -53,54 +59,52 @@ const Cart = () => { ) : ( <> - {userLoggedIn && cart.length > 0 ? ( -
-
- {cart.map((item, index) => ( - - ))} -
-
-
-
-
Your Cart
-
Summary
-

- Total Items: {cart.length} + {userLoggedIn ? ( + cart.length > 0 ? ( +

+
+ {cart.map((item, index) => ( + + ))} +
+
+
+
+
Your Cart
+
Summary
+

+ Total Items: {cart.length} +

+
+
+
+

+ Total Amount: ${totalAmount}

+
-
-

- Total Amount: ${totalAmount} -

-
+ ) : ( +
+

Your cart is empty!

+ + -
+
-
+ ) ) : (
- {userLoggedIn ? ( - <> -

Your cart is empty!

- - - - - ) : ( - <> -

Please Login First!

- - - - - )} +

Please Login First!

+ + +
)} diff --git a/client/src/Pages/Profile.jsx b/client/src/Pages/Profile.jsx index 31d1ef4..13d7b70 100644 --- a/client/src/Pages/Profile.jsx +++ b/client/src/Pages/Profile.jsx @@ -1,11 +1,23 @@ import React, { useEffect, useState } from 'react'; import axios from 'axios'; -import { Avatar, Box, Typography, Button, CircularProgress, Paper } from '@mui/material'; +import { Avatar, Box, Typography, Button, CircularProgress, Paper, TextField, Grid, MenuItem,Rating } from '@mui/material'; import { deepPurple } from '@mui/material/colors'; const Profile = () => { const [user, setUser] = useState(null); const [loading, setLoading] = useState(true); + const [bookDetails, setBookDetails] = useState({ + name: '', + author: '', + price: '', + description: '', + category: '', + stock: 1, + ratings:0, + shareableLink: '', + image: { public_id: '', url: '' }, + }); + const [formLoading, setFormLoading] = useState(false); useEffect(() => { const fetchUserData = async () => { @@ -30,6 +42,43 @@ const Profile = () => { fetchUserData(); }, []); + const handleInputChange = (e) => { + const { name, value } = e.target; + setBookDetails({ + ...bookDetails, + [name]: value + }); + }; + + const handleSubmit = async (e) => { + e.preventDefault(); + setFormLoading(true); + const token = localStorage.getItem('token'); + try { + const response = await axios.post('http://localhost:8080/books/sell', bookDetails, { + headers: { + Authorization: `Bearer ${token}` + } + }); + console.log('Book listed successfully:', response.data); + setBookDetails({ + name: '', + author: '', + price: '', + description: '', + category: '', + stock: 1, + ratings:0, + shareableLink: '', + image: { public_id: '', url: '' }, + }); + } catch (error) { + console.error('Error listing book:', error); + } finally { + setFormLoading(false); + } + }; + if (loading) { return ( @@ -94,6 +143,124 @@ const Profile = () => { Edit Profile + + + + Sell Your Old Book + +
+ + + + + + + + + + + + + + + + {/* Add your categories here */} + Fiction + + Romance + Tech/ + {/* Add more categories as needed */} + + + + + + + + + + + + + + + + + + setBookDetails({ + ...bookDetails, + image: { ...bookDetails.image, url: e.target.value } + })} + fullWidth + required + /> + + + + + +
+
); };