Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Books cart and checkout page #138

Merged
merged 31 commits into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0fc62d1
added carts
s-orug Feb 16, 2023
cca93e5
new items can be added
s-orug Feb 19, 2023
d1d986e
cart changed
s-orug Feb 21, 2023
0a0f9f7
cart tracks the quantity
s-orug Feb 22, 2023
8b65738
cart contains items
s-orug Feb 22, 2023
dd27e17
update
s-orug Feb 22, 2023
d741084
cart contains the items with their corresponding data
s-orug Feb 22, 2023
88eeac5
price for the cart added
s-orug Feb 22, 2023
288cd62
price calculator for the cart page added
s-orug Feb 22, 2023
81afcee
checkout button added
s-orug Feb 22, 2023
8d6f569
changes to the cart for the backend integration
s-orug Feb 22, 2023
ac44d20
default values in the cart
s-orug Feb 23, 2023
a44c2c9
cart has added checkout feature for the backend
s-orug Feb 23, 2023
a6a1f79
checkpoint 1
s-orug Feb 23, 2023
a287bf2
uninstall react-use-cart
s-orug Feb 23, 2023
040ea2f
update
s-orug Feb 23, 2023
5da5bc3
Merge branch 'main' of https://github.com/SCCapstone/BufferOverload i…
s-orug Feb 23, 2023
d97419f
update
s-orug Feb 23, 2023
e32cf60
update
s-orug Feb 23, 2023
fedec6f
update
s-orug Feb 23, 2023
c15782a
update
s-orug Feb 24, 2023
b02f052
Merge branch 'main' of https://github.com/SCCapstone/BufferOverload i…
s-orug Feb 25, 2023
f5e5665
update
s-orug Feb 25, 2023
fce6b97
pulling main
s-orug Feb 25, 2023
8326a65
update
s-orug Feb 26, 2023
4f82751
able to retrieve user data
s-orug Feb 26, 2023
77667a5
balance deducted
s-orug Feb 26, 2023
eac6d83
it works
s-orug Feb 26, 2023
f757414
fixed a bug in the books page generator
s-orug Feb 26, 2023
5fa0b0c
update
s-orug Feb 26, 2023
6fd0f49
MongoDB's zero storing problem FIXED
s-orug Feb 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const userSchema = new mongoose.Schema({
password: { type: String, required: true },
role: { type: String, required: true, enum: ["admin", "customer"]},
balance: { type: mongoose.Schema.Types.Decimal128, required: false },

});

userSchema.methods.generateAuthToken = function () {
Expand Down
260 changes: 142 additions & 118 deletions client/package-lock.json

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@mui/icons-material": "^5.11.0",
"@mui/material": "^5.11.6",
"@mui/material": "^5.11.10",
"@mui/styled-engine": "^5.11.0",
"@mui/styled-engine-sc": "^5.11.0",
"@testing-library/jest-dom": "^5.16.5",
Expand All @@ -24,6 +24,8 @@
"react-router-dom": "^6.6.1",
"react-scripts": "5.0.1",
"react-stars": "^2.2.5",
"react-use-cart": "^1.13.0",
"reactjs-popup": "^2.0.5",
"styled-components": "^5.3.6",
"sweetalert2": "^11.7.1",
"web-vitals": "^2.1.4"
Expand Down
2 changes: 2 additions & 0 deletions client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import "./App.css";
import CompleteNavbar from "./components/NavBar";
import { BrowserRouter, Routes } from "react-router-dom";
import { CartProvider } from "react-use-cart";
import Main_Cart from "./views/Cart/Cart";

function App() {
return (
Expand Down
21 changes: 17 additions & 4 deletions client/src/components/NavBar/NavBar.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { useNavigate } from "react-router-dom";
import { IoMdCart } from "react-icons/io";

const NavBar = ({ user }) => {
const navigate = useNavigate();
Expand All @@ -10,13 +11,12 @@ const NavBar = ({ user }) => {
localStorage.removeItem("userType");
localStorage.removeItem("userID");
window.location.reload();
navigate("/");
} else {
navigate("/login");
}
};



return (
<div>
<nav class="bg-persian_plum px-4 sm:px-6 py-2.5 dark:bg-gray-900 fixed w-full z-20 top-0 left-0 border-b-4 border-gray-200 dark:border-gray-600">
Expand All @@ -28,8 +28,21 @@ const NavBar = ({ user }) => {
</span>
</a>
</span>
<div class="flex md:order-2">
<button class="flex items-center" onClick={loginOrLogout}>
<div class="flex md:order-2 grid grid-cols-5">
<IoMdCart
onClick={() => navigate("/cart")}
className=""
style={{
position: "",
top: "10px",
right: "70px",
}}
size="40px"
color="white"
/>
<div />

<button class="" onClick={loginOrLogout}>
<span className="text-white text-xl">
{user && user.length !== 0 ? "Logout" : "Login"}
</span>
Expand Down
2 changes: 2 additions & 0 deletions client/src/components/NavBar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import BooksPageGenerator from "../../views/BooksPageGenerator";
import books from "../../views/Books";
import ValidatedUsers from "../../views/ValidatedUsers";
import CreateForum from "../../views/CreateForum";
import MainCart from "../../views/Cart/Cart";
import AddBook from "../../views/AddBook";
import EmployeeHomepage from "../../views/EmployeeHomePage";
import MyAccount from "../../views/MyAccount";
Expand All @@ -37,6 +38,7 @@ const CompleteNavbar = () => {
<Route path="/contact" element={<ContactUs />} />
<Route path="/browse" element={<Browse />} />
<Route path="/create_account" element={<Signup />} />
<Route path="/cart" element={<MainCart currentUser={localStorage.getItem("userID")} />} />

{/* Admin and Customer */}
<Route path="/my_account" element={<MyAccount currentUser={localStorage.getItem("userID")} />} />
Expand Down
1 change: 1 addition & 0 deletions client/src/components/UserRow.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";

const UserRow = ({ contact, handleEditClick, handleDelete }) => {
// console.log(contact)

const handleChange = (e) => {
const newUserType = e.target.value;
Expand Down
14 changes: 8 additions & 6 deletions client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";
import { CartProvider } from "react-use-cart";
import Main_Cart from "./views/Cart/Cart";

const root = ReactDOM.createRoot(document.getElementById('root'));
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<React.StrictMode>
<App />
Expand Down
2 changes: 2 additions & 0 deletions client/src/views/Aboutus.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import book_dispensary from "../assets/book_dispensary.jpg";
import { styles } from "../styles";

const Aboutus = () => {
var books_cart = JSON.parse(localStorage.getItem("books_cart"));
console.log(books_cart);
return (
<section>
<div class="py-4">
Expand Down
101 changes: 22 additions & 79 deletions client/src/views/Books.js
Original file line number Diff line number Diff line change
@@ -1,117 +1,60 @@
const books = [
{
name: "Steve Jobs",
title: "Steve Jobs",
author: "Walter Issacson",
image: require("./Books/stevejobs.png"),
review:
imageId: require("./Books/stevejobs.png"),
summary:
"SJ A genius book about an incredible mind, yadda yadda blah blah blah lots of gushing and awing because I like books.",
link: "/Walter Issacson/Steve Jobs",
stars: 3,
price: 12.5,
qty: "40+",
stock: 40,
genre: "",
sold: "6",
quantitySold: "6",
date: "2006-08-25",
},
{
name: "Go-To-Dinners",
title: "Go-To-Dinners",
author: "Ina Garten",
image: require("./Books/gotodinners.png"),
review:
imageId: require("./Books/gotodinners.png"),
summary:
"GTD A genius book about an incredible mind, yadda yadda blah blah blah lots of gushing and awing because I like books.",
link: "/Ina Garten/Go-To-Dinners",
stars: 3,
price: 120.99,
qty: "40+",
stock: 40,
genre: "",
sold: "3",
quantitySold: "3",
date: "2020-03-23",
},
{
name: "How Easy is That?",
title: "How Easy is That?",
author: "Ina Garten",
image: require("./Books/howeasyisthat.png"),
review:
imageId: require("./Books/howeasyisthat.png"),
summary:
"HET A genius book about an incredible mind, yadda yadda blah blah blah lots of gushing and awing because I like books.",
link: "/Ina Garten/How Easy is That",
stars: 3,
price: 15.99,
qty: "40+",
stock: 40,
genre: "",
sold: "23",
quantitySold: "23",
date: "2022-04-11",
},
{
name: "Jane Eyre",
title: "Jane Eyre",
author: "Charlotte Bronte",
image: require("./Books/janeeyre.png"),
review:
imageId: require("./Books/janeeyre.png"),
summary:
"JE A genius book about an incredible mind, yadda yadda blah blah blah lots of gushing and awing because I like books.",
link: "/Charlotte Bronte/Jane Eyre",
stars: 3,
price: 16.99,
qty: "40+",
stock: 40,
genre: "",
sold: "43",
quantitySold: "43",
date: "2016-06-01",
},

{
name: "Steve Jobs",
author: "Walter Issacson",
image: require("./Books/stevejobs.png"),
review:
"SJ A genius book about an incredible mind, yadda yadda blah blah blah lots of gushing and awing because I like books.",
link: "/Walter Issacson/Steve Jobs2",
stars: 3.5,
price: 12.99,
qty: "40+",
genre: "",
sold: "12",
date: "2014-11-05",
},
{
name: "Go-To-Dinners",
author: "Ina Garten",
image: require("./Books/gotodinners.png"),
review:
"GTD A genius book about an incredible mind, yadda yadda blah blah blah lots of gushing and awing because I like books.",
link: "/Ina Garten/Go-To-Dinners2",
stars: 3,
price: 12.99,
qty: "40+",
genre: "",
sold: "12",
date: "2006-08-25",
},
{
name: "How Easy is That?",
author: "Ina Garten",
image: require("./Books/howeasyisthat.png"),
review:
"HET A genius book about an incredible mind, yadda yadda blah blah blah lots of gushing and awing because I like books.",
link: "/Ina Garten/How Easy is That2",
stars: 3,
price: 12.99,
qty: "40+",
genre: "",
sold: "56",
date: "2016-01-19",
},
{
name: "Jane Eyre",
author: "Charlotte Bronte",
image: require("./Books/janeeyre.png"),
review:
"JE A genius book about an incredible mind, yadda yadda blah blah blah lots of gushing and awing because I like books.",
link: "/Charlotte Bronte/Jane Eyre2",
stars: 3,
price: 1.99,
qty: "40+",
genre: "",
sold: "0",
date: "2010-10-26",
},
}
];

export default books;
export default books;
Loading