├── backend ├── Procfile ├── images │ ├── galaxyS.png │ ├── iphone12.jpg │ └── iphone12pro.jpg ├── .env.example ├── utils │ ├── cloudinary.js │ └── generateAuthToken.js ├── .gitignore ├── models │ ├── product.js │ ├── user.js │ └── order.js ├── package.json ├── products.js ├── routes │ ├── login.js │ ├── register.js │ ├── products.js │ ├── orders.js │ └── stripe.js ├── middleware │ └── auth.js └── index.js └── frontend ├── public ├── robots.txt ├── favicon.ico ├── logo192.png ├── logo512.png ├── manifest.json └── index.html ├── src ├── components │ ├── admin │ │ ├── Users.jsx │ │ ├── Summary.jsx │ │ ├── Oders.jsx │ │ ├── CommonStyled.js │ │ ├── Products.jsx │ │ ├── Dashboard.jsx │ │ └── CreateProduct.jsx │ ├── NotFound.jsx │ ├── auth │ │ ├── StyledForm.js │ │ ├── Login.jsx │ │ └── Register.jsx │ ├── PayButton.jsx │ ├── CheckoutSuccess.jsx │ ├── Home.jsx │ ├── NavBar.jsx │ └── Cart.jsx ├── slices │ ├── api.js │ ├── productsApi.js │ ├── productsSlice.js │ ├── cartSlice.js │ └── authSlice.js ├── index.js ├── App.js └── App.css ├── .gitignore ├── package.json └── README.md /backend/Procfile: -------------------------------------------------------------------------------- 1 | web: node index.js -------------------------------------------------------------------------------- /frontend/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /backend/images/galaxyS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaoocharles/complete-ecommerce-react-node/HEAD/backend/images/galaxyS.png -------------------------------------------------------------------------------- /backend/images/iphone12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaoocharles/complete-ecommerce-react-node/HEAD/backend/images/iphone12.jpg -------------------------------------------------------------------------------- /frontend/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaoocharles/complete-ecommerce-react-node/HEAD/frontend/public/favicon.ico -------------------------------------------------------------------------------- /frontend/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaoocharles/complete-ecommerce-react-node/HEAD/frontend/public/logo192.png -------------------------------------------------------------------------------- /frontend/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaoocharles/complete-ecommerce-react-node/HEAD/frontend/public/logo512.png -------------------------------------------------------------------------------- /frontend/src/components/admin/Users.jsx: -------------------------------------------------------------------------------- 1 | const Users = () => { 2 | return

Users

; 3 | }; 4 | 5 | export default Users; 6 | -------------------------------------------------------------------------------- /backend/images/iphone12pro.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chaoocharles/complete-ecommerce-react-node/HEAD/backend/images/iphone12pro.jpg -------------------------------------------------------------------------------- /frontend/src/components/admin/Summary.jsx: -------------------------------------------------------------------------------- 1 | const Summary = () => { 2 | return

Summary

; 3 | }; 4 | 5 | export default Summary; 6 | -------------------------------------------------------------------------------- /frontend/src/components/admin/Oders.jsx: -------------------------------------------------------------------------------- 1 | const Orders = () => { 2 | return

Orders

; 3 | }; 4 | 5 | export default Orders; 6 |

Orders

; 7 | -------------------------------------------------------------------------------- /backend/.env.example: -------------------------------------------------------------------------------- 1 | DB_URI = <> 2 | JWT_SECRET_KEY = <> 3 | STRIPE_KEY = <> 4 | STRIPE_WEB_HOOK = <> 5 | CLIENT_URL = <> 6 | CLOUDINARY_NAME = <> 7 | CLOUDINARY_API_KEY = <> 8 | CLOUDINARY_API_SECRET = <> -------------------------------------------------------------------------------- /frontend/src/components/NotFound.jsx: -------------------------------------------------------------------------------- 1 | const NotFound = () => { 2 | return ( 3 |
4 |

404

5 |

Page not found

6 |
7 | ); 8 | }; 9 | 10 | export default NotFound; 11 | -------------------------------------------------------------------------------- /frontend/src/slices/api.js: -------------------------------------------------------------------------------- 1 | export const url = "http://localhost:5000/api"; 2 | 3 | export const setHeaders = () => { 4 | const headers = { 5 | headers: { 6 | "x-auth-token": localStorage.getItem("token"), 7 | }, 8 | }; 9 | 10 | return headers; 11 | }; 12 | -------------------------------------------------------------------------------- /backend/utils/cloudinary.js: -------------------------------------------------------------------------------- 1 | const dotenv = require("dotenv"); 2 | const cloudinaryModule = require("cloudinary"); 3 | 4 | dotenv.config(); 5 | const cloudinary = cloudinaryModule.v2; 6 | 7 | cloudinary.config({ 8 | cloud_name: process.env.CLOUDINARY_NAME, 9 | api_key: process.env.CLOUDINARY_API_KEY, 10 | api_secret: process.env.CLOUDINARY_API_SECRET, 11 | }); 12 | 13 | module.exports = cloudinary; 14 | -------------------------------------------------------------------------------- /frontend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /backend/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env 17 | .env.local 18 | .env.development.local 19 | .env.test.local 20 | .env.production.local 21 | 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | -------------------------------------------------------------------------------- /backend/utils/generateAuthToken.js: -------------------------------------------------------------------------------- 1 | const jwt = require("jsonwebtoken"); 2 | 3 | const generateAuthToken = (user) => { 4 | const jwtSecretKey = process.env.JWT_SECRET_KEY; 5 | const token = jwt.sign( 6 | { 7 | _id: user._id, 8 | name: user.name, 9 | email: user.email, 10 | isAdmin: user.isAdmin, 11 | }, 12 | jwtSecretKey 13 | ); 14 | 15 | return token; 16 | }; 17 | 18 | module.exports = generateAuthToken; 19 | -------------------------------------------------------------------------------- /backend/models/product.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const productSchema = new mongoose.Schema( 4 | { 5 | name: { type: String, required: true }, 6 | brand: { type: String, required: true }, 7 | desc: { type: String, required: true }, 8 | price: { type: Number, required: true }, 9 | image: { type: Object, required: true }, 10 | }, 11 | { timestamps: true } 12 | ); 13 | 14 | const Product = mongoose.model("Product", productSchema); 15 | 16 | exports.Product = Product; 17 | -------------------------------------------------------------------------------- /frontend/src/components/admin/CommonStyled.js: -------------------------------------------------------------------------------- 1 | import styled from "styled-components"; 2 | 3 | export const AdminHeaders = styled.div` 4 | display: flex; 5 | justify-content: space-between; 6 | `; 7 | 8 | export const PrimaryButton = styled.button` 9 | padding: 9px 12px; 10 | border-radius: 5px; 11 | font-weight: 400; 12 | letter-spacing: 1.15px; 13 | background-color: #4b70e2; 14 | color: #f9f9f9; 15 | border: none; 16 | outline: none; 17 | cursor: pointer; 18 | margin: 0.5rem 0; 19 | `; 20 | -------------------------------------------------------------------------------- /frontend/src/components/admin/Products.jsx: -------------------------------------------------------------------------------- 1 | import { Outlet, useNavigate } from "react-router-dom"; 2 | import { AdminHeaders, PrimaryButton } from "./CommonStyled"; 3 | 4 | const Products = () => { 5 | const navigate = useNavigate(); 6 | 7 | return ( 8 | <> 9 | 10 |

Products

11 | navigate("/admin/products/create-product")} 13 | > 14 | Create 15 | 16 |
17 | 18 | 19 | ); 20 | }; 21 | 22 | export default Products; 23 | -------------------------------------------------------------------------------- /backend/models/user.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const userSchema = new mongoose.Schema( 4 | { 5 | name: { type: String, required: true, minlength: 3, maxlength: 30 }, 6 | email: { 7 | type: String, 8 | required: true, 9 | minlength: 3, 10 | maxlength: 200, 11 | unique: true, 12 | }, 13 | password: { type: String, required: true, minlength: 3, maxlength: 1024 }, 14 | isAdmin: { type: Boolean, default: false }, 15 | }, 16 | { timestamps: true } 17 | ); 18 | 19 | const User = mongoose.model("User", userSchema); 20 | 21 | exports.User = User; 22 | -------------------------------------------------------------------------------- /backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backend", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "bcrypt": "^5.0.1", 14 | "cloudinary": "^1.29.1", 15 | "cors": "^2.8.5", 16 | "dotenv": "^16.0.0", 17 | "express": "^4.17.1", 18 | "joi": "^17.6.0", 19 | "jsonwebtoken": "^8.5.1", 20 | "mongoose": "^6.2.10", 21 | "nodemon": "^2.0.12", 22 | "stripe": "^8.218.0" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /frontend/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /backend/models/order.js: -------------------------------------------------------------------------------- 1 | const mongoose = require("mongoose"); 2 | 3 | const orderSchema = new mongoose.Schema( 4 | { 5 | userId: { type: String, required: true }, 6 | products: [ 7 | { productId: { type: String }, quantity: { type: Number, default: 1 } }, 8 | ], 9 | subtotal: { type: Number, required: true }, 10 | total: { type: Number, required: true }, 11 | shipping: { type: Object, required: true }, 12 | delivery_status: { type: String, default: "pending" }, 13 | payment_status: { type: String, required: true }, 14 | }, 15 | { timestamps: true } 16 | ); 17 | 18 | const Order = mongoose.model("Order", orderSchema); 19 | 20 | exports.Order = Order; 21 | -------------------------------------------------------------------------------- /frontend/src/slices/productsApi.js: -------------------------------------------------------------------------------- 1 | // Need to use the React-specific entry point to import createApi 2 | import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react"; 3 | import { url } from "./api"; 4 | 5 | // Define a service using a base URL and expected endpoints 6 | export const productsApi = createApi({ 7 | reducerPath: "productsApi", 8 | baseQuery: fetchBaseQuery({ baseUrl: `${url}` }), 9 | endpoints: (builder) => ({ 10 | getAllProducts: builder.query({ 11 | query: () => `products`, 12 | }), 13 | }), 14 | }); 15 | 16 | // Export hooks for usage in functional components, which are 17 | // auto-generated based on the defined endpoints 18 | export const { useGetAllProductsQuery } = productsApi; 19 | -------------------------------------------------------------------------------- /frontend/src/components/auth/StyledForm.js: -------------------------------------------------------------------------------- 1 | import styled from "styled-components"; 2 | 3 | export const StyledForm = styled.form` 4 | max-width: 350px; 5 | width: 100%; 6 | margin: 2rem auto; 7 | 8 | h2 { 9 | margin-bottom: 1rem; 10 | } 11 | 12 | button, 13 | input { 14 | height: 35px; 15 | width: 100%; 16 | padding: 7px; 17 | outline: none; 18 | border-radius: 5px; 19 | border: 1px solid rgb(220, 220, 220); 20 | margin-bottom: 1rem; 21 | 22 | &:focus { 23 | border: 1px solid rgb(0, 208, 255); 24 | } 25 | } 26 | 27 | button { 28 | cursor: pointer; 29 | 30 | &:focus { 31 | border: none; 32 | } 33 | } 34 | 35 | p { 36 | font-size: 14px; 37 | color: red; 38 | } 39 | `; 40 | -------------------------------------------------------------------------------- /frontend/src/components/PayButton.jsx: -------------------------------------------------------------------------------- 1 | import axios from "axios"; 2 | import { useSelector } from "react-redux"; 3 | import { url } from "../slices/api"; 4 | 5 | const PayButton = ({ cartItems }) => { 6 | const user = useSelector((state) => state.auth); 7 | 8 | const handleCheckout = () => { 9 | axios 10 | .post(`${url}/stripe/create-checkout-session`, { 11 | cartItems, 12 | userId: user._id, 13 | }) 14 | .then((response) => { 15 | if (response.data.url) { 16 | window.location.href = response.data.url; 17 | } 18 | }) 19 | .catch((err) => console.log(err.message)); 20 | }; 21 | 22 | return ( 23 | <> 24 | 25 | 26 | ); 27 | }; 28 | 29 | export default PayButton; 30 | -------------------------------------------------------------------------------- /backend/products.js: -------------------------------------------------------------------------------- 1 | const products = [ 2 | { 3 | id: 1, 4 | name: "iPhone 12 Pro", 5 | brand: "Apple", 6 | desc: "6.1-inch display", 7 | price: 999, 8 | image: 9 | "https://res.cloudinary.com/chaoocharles/image/upload/v1629289889/online-shop/iphone12pro_e09phn.jpg", 10 | }, 11 | { 12 | id: 2, 13 | name: "iPhone 12", 14 | brand: "Apple", 15 | desc: "5.4-inch mini display", 16 | price: 699, 17 | image: 18 | "https://res.cloudinary.com/chaoocharles/image/upload/v1629289889/online-shop/iphone12_efhrcp.jpg", 19 | }, 20 | { 21 | id: 3, 22 | name: "Galaxy S", 23 | brand: "Samsung", 24 | desc: "6.5-inch display", 25 | price: 399, 26 | image: 27 | "https://res.cloudinary.com/chaoocharles/image/upload/v1629289889/online-shop/galaxyS_dvjf5w.png", 28 | }, 29 | ]; 30 | 31 | module.exports = products; 32 | -------------------------------------------------------------------------------- /frontend/src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import App from "./App"; 4 | 5 | import { Provider } from "react-redux"; 6 | import { configureStore } from "@reduxjs/toolkit"; 7 | 8 | import productsReducer, { productsFetch } from "./slices/productsSlice"; 9 | import cartReducer, { getTotals } from "./slices/cartSlice"; 10 | import authReducer from "./slices/authSlice"; 11 | import { productsApi } from "./slices/productsApi"; 12 | 13 | const store = configureStore({ 14 | reducer: { 15 | products: productsReducer, 16 | cart: cartReducer, 17 | auth: authReducer, 18 | [productsApi.reducerPath]: productsApi.reducer, 19 | }, 20 | middleware: (getDefaultMiddleware) => 21 | getDefaultMiddleware().concat(productsApi.middleware), 22 | }); 23 | 24 | store.dispatch(productsFetch()); 25 | store.dispatch(getTotals()); 26 | 27 | ReactDOM.render( 28 | 29 | 30 | 31 | 32 | , 33 | document.getElementById("root") 34 | ); 35 | -------------------------------------------------------------------------------- /backend/routes/login.js: -------------------------------------------------------------------------------- 1 | const bcrypt = require("bcrypt"); 2 | const { User } = require("../models/user"); 3 | const Joi = require("joi"); 4 | const express = require("express"); 5 | const generateAuthToken = require("../utils/generateAuthToken"); 6 | const router = express.Router(); 7 | 8 | router.post("/", async (req, res) => { 9 | const schema = Joi.object({ 10 | email: Joi.string().min(3).max(200).required().email(), 11 | password: Joi.string().min(6).max(200).required(), 12 | }); 13 | 14 | const { error } = schema.validate(req.body); 15 | 16 | if (error) return res.status(400).send(error.details[0].message); 17 | 18 | let user = await User.findOne({ email: req.body.email }); 19 | if (!user) return res.status(400).send("Invalid email or password..."); 20 | 21 | const validPassword = await bcrypt.compare(req.body.password, user.password); 22 | if (!validPassword) 23 | return res.status(400).send("Invalid email or password..."); 24 | 25 | const token = generateAuthToken(user); 26 | 27 | res.send(token); 28 | }); 29 | 30 | module.exports = router; 31 | -------------------------------------------------------------------------------- /backend/middleware/auth.js: -------------------------------------------------------------------------------- 1 | const jwt = require("jsonwebtoken"); 2 | 3 | const auth = (req, res, next) => { 4 | const token = req.header("x-auth-token"); 5 | if (!token) 6 | return res.status(401).send("Access denied. Not authenticated..."); 7 | try { 8 | const jwtSecretKey = process.env.JWT_SECRET_KEY; 9 | const decoded = jwt.verify(token, jwtSecretKey); 10 | 11 | req.user = decoded; 12 | next(); 13 | } catch (ex) { 14 | res.status(400).send("Invalid auth token..."); 15 | } 16 | }; 17 | 18 | // For User Profile 19 | const isUser = (req, res, next) => { 20 | auth(req, res, () => { 21 | if (req.user._id === req.params.id || req.user.isAdmin) { 22 | next(); 23 | } else { 24 | res.status(403).send("Access denied. Not authorized..."); 25 | } 26 | }); 27 | }; 28 | 29 | // For Admin 30 | const isAdmin = (req, res, next) => { 31 | auth(req, res, () => { 32 | if (req.user.isAdmin) { 33 | next(); 34 | } else { 35 | res.status(403).send("Access denied. Not authorized..."); 36 | } 37 | }); 38 | }; 39 | 40 | module.exports = { auth, isUser, isAdmin }; 41 | -------------------------------------------------------------------------------- /backend/routes/register.js: -------------------------------------------------------------------------------- 1 | const bcrypt = require("bcrypt"); 2 | const { User } = require("../models/user"); 3 | const Joi = require("joi"); 4 | const express = require("express"); 5 | const generateAuthToken = require("../utils/generateAuthToken"); 6 | const router = express.Router(); 7 | 8 | router.post("/", async (req, res) => { 9 | const schema = Joi.object({ 10 | name: Joi.string().min(3).max(30).required(), 11 | email: Joi.string().min(3).max(200).required().email(), 12 | password: Joi.string().min(6).max(200).required(), 13 | }); 14 | 15 | const { error } = schema.validate(req.body); 16 | 17 | if (error) return res.status(400).send(error.details[0].message); 18 | 19 | let user = await User.findOne({ email: req.body.email }); 20 | if (user) return res.status(400).send("User already exists..."); 21 | 22 | console.log("here"); 23 | 24 | const { name, email, password } = req.body; 25 | 26 | user = new User({ name, email, password }); 27 | 28 | const salt = await bcrypt.genSalt(10); 29 | user.password = await bcrypt.hash(user.password, salt); 30 | 31 | await user.save(); 32 | 33 | const token = generateAuthToken(user); 34 | 35 | res.send(token); 36 | }); 37 | 38 | module.exports = router; 39 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@reduxjs/toolkit": "^1.6.1", 7 | "@testing-library/jest-dom": "^5.14.1", 8 | "@testing-library/react": "^11.2.7", 9 | "@testing-library/user-event": "^12.8.3", 10 | "axios": "^0.21.1", 11 | "jwt-decode": "^3.1.2", 12 | "react": "^17.0.2", 13 | "react-dom": "^17.0.2", 14 | "react-redux": "^7.2.4", 15 | "react-router-dom": "^6.3.0", 16 | "react-scripts": "4.0.3", 17 | "react-stripe-checkout": "^2.6.3", 18 | "react-toastify": "^7.0.4", 19 | "styled-components": "^5.3.5", 20 | "web-vitals": "^1.1.2" 21 | }, 22 | "scripts": { 23 | "start": "react-scripts start", 24 | "build": "react-scripts build", 25 | "test": "react-scripts test", 26 | "eject": "react-scripts eject" 27 | }, 28 | "eslintConfig": { 29 | "extends": [ 30 | "react-app", 31 | "react-app/jest" 32 | ] 33 | }, 34 | "browserslist": { 35 | "production": [ 36 | ">0.2%", 37 | "not dead", 38 | "not op_mini all" 39 | ], 40 | "development": [ 41 | "last 1 chrome version", 42 | "last 1 firefox version", 43 | "last 1 safari version" 44 | ] 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /frontend/src/components/CheckoutSuccess.jsx: -------------------------------------------------------------------------------- 1 | import { useEffect } from "react"; 2 | import { useDispatch, useSelector } from "react-redux"; 3 | import styled from "styled-components"; 4 | import { clearCart, getTotals } from "../slices/cartSlice"; 5 | 6 | const CheckoutSuccess = () => { 7 | const dispatch = useDispatch(); 8 | const cart = useSelector((state) => state.cart); 9 | 10 | useEffect(() => { 11 | dispatch(clearCart()); 12 | }, [dispatch]); 13 | 14 | useEffect(() => { 15 | dispatch(getTotals()); 16 | }, [cart, dispatch]); 17 | 18 | return ( 19 | 20 |

Checkout Successful

21 |

Your order might take some time to process.

22 |

Check your order status at your profile after about 10mins.

23 |

24 | Incase of any inqueries contact the support at{" "} 25 | support@onlineshop.com 26 |

27 |
28 | ); 29 | }; 30 | 31 | export default CheckoutSuccess; 32 | 33 | const Container = styled.div` 34 | min-height: 80vh; 35 | max-width: 800px; 36 | width: 100%; 37 | margin: auto; 38 | display: flex; 39 | flex-direction: column; 40 | align-items: center; 41 | justify-content: center; 42 | 43 | h2 { 44 | margin-bottom: 0.5rem; 45 | color: #029e02; 46 | } 47 | `; 48 | -------------------------------------------------------------------------------- /backend/index.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const cors = require("cors"); 3 | const mongoose = require("mongoose"); 4 | const register = require("./routes/register"); 5 | const login = require("./routes/login"); 6 | const orders = require("./routes/orders"); 7 | const stripe = require("./routes/stripe"); 8 | const productsRoute = require("./routes/products"); 9 | 10 | const products = require("./products"); 11 | 12 | const app = express(); 13 | 14 | require("dotenv").config(); 15 | 16 | app.use(express.json()); 17 | app.use(cors()); 18 | 19 | app.use("/api/register", register); 20 | app.use("/api/login", login); 21 | app.use("/api/orders", orders); 22 | app.use("/api/stripe", stripe); 23 | app.use("/api/products", productsRoute); 24 | 25 | app.get("/", (req, res) => { 26 | res.send("Welcome our to online shop API..."); 27 | }); 28 | 29 | app.get("/products", (req, res) => { 30 | res.send(products); 31 | }); 32 | 33 | const uri = process.env.DB_URI; 34 | const port = process.env.PORT || 5000; 35 | 36 | app.listen(port, () => { 37 | console.log(`Server running on port: ${port}...`); 38 | }); 39 | 40 | mongoose 41 | .connect(uri, { 42 | useNewUrlParser: true, 43 | useUnifiedTopology: true, 44 | }) 45 | .then(() => console.log("MongoDB connection established...")) 46 | .catch((error) => console.error("MongoDB connection failed:", error.message)); 47 | -------------------------------------------------------------------------------- /frontend/src/components/auth/Login.jsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import { useDispatch, useSelector } from "react-redux"; 3 | import { loginUser } from "../../slices/authSlice"; 4 | import { useNavigate } from "react-router-dom"; 5 | import { StyledForm } from "./StyledForm"; 6 | 7 | const Login = () => { 8 | const navigate = useNavigate(); 9 | const dispatch = useDispatch(); 10 | const auth = useSelector((state) => state.auth); 11 | 12 | const [user, setUser] = useState({ 13 | email: "", 14 | password: "", 15 | }); 16 | 17 | useEffect(() => { 18 | if (auth._id) { 19 | navigate("/cart"); 20 | } 21 | }, [auth._id, navigate]); 22 | 23 | const handleSubmit = (e) => { 24 | e.preventDefault(); 25 | 26 | console.log(user); 27 | dispatch(loginUser(user)); 28 | }; 29 | 30 | return ( 31 | <> 32 | 33 |

Login

34 | setUser({ ...user, email: e.target.value })} 38 | /> 39 | setUser({ ...user, password: e.target.value })} 43 | /> 44 | 47 | {auth.loginStatus === "rejected" ?

{auth.loginError}

: null} 48 |
49 | 50 | ); 51 | }; 52 | 53 | export default Login; 54 | -------------------------------------------------------------------------------- /frontend/src/components/Home.jsx: -------------------------------------------------------------------------------- 1 | import { useDispatch, useSelector } from "react-redux"; 2 | import { useNavigate } from "react-router"; 3 | import { addToCart } from "../slices/cartSlice"; 4 | // import { useGetAllProductsQuery } from "../slices/productsApi"; 5 | 6 | const Home = () => { 7 | const { items: data, status } = useSelector((state) => state.products); 8 | const dispatch = useDispatch(); 9 | const navigate = useNavigate(); 10 | 11 | // const { data, error, isLoading } = useGetAllProductsQuery(); 12 | 13 | const handleAddToCart = (product) => { 14 | dispatch(addToCart(product)); 15 | navigate("/cart"); 16 | }; 17 | 18 | return ( 19 |
20 | {status === "success" ? ( 21 | <> 22 |

New Arrivals

23 |
24 | {data && 25 | data?.map((product) => ( 26 |
27 |

{product.name}

28 | {product.name} 29 |
30 | {product.desc} 31 | ${product.price} 32 |
33 | 36 |
37 | ))} 38 |
39 | 40 | ) : status === "pending" ? ( 41 |

Loading...

42 | ) : ( 43 |

Unexpected error occured...

44 | )} 45 |
46 | ); 47 | }; 48 | 49 | export default Home; 50 | -------------------------------------------------------------------------------- /frontend/src/components/auth/Register.jsx: -------------------------------------------------------------------------------- 1 | import { useState, useEffect } from "react"; 2 | import { useNavigate } from "react-router-dom"; 3 | import { useDispatch, useSelector } from "react-redux"; 4 | import { registerUser } from "../../slices/authSlice"; 5 | import { StyledForm } from "./StyledForm"; 6 | 7 | const Register = () => { 8 | const dispatch = useDispatch(); 9 | const navigate = useNavigate(); 10 | const auth = useSelector((state) => state.auth); 11 | 12 | const [user, setUser] = useState({ 13 | name: "", 14 | email: "", 15 | password: "", 16 | }); 17 | 18 | useEffect(() => { 19 | if (auth._id) { 20 | navigate("/cart"); 21 | } 22 | }, [auth._id, navigate]); 23 | 24 | const handleSubmit = (e) => { 25 | e.preventDefault(); 26 | 27 | console.log(user); 28 | dispatch(registerUser(user)); 29 | }; 30 | 31 | return ( 32 | <> 33 | 34 |

Register

35 | setUser({ ...user, name: e.target.value })} 39 | /> 40 | setUser({ ...user, email: e.target.value })} 44 | /> 45 | setUser({ ...user, password: e.target.value })} 49 | /> 50 | 53 | {auth.registerStatus === "rejected" ? ( 54 |

{auth.registerError}

55 | ) : null} 56 |
57 | 58 | ); 59 | }; 60 | 61 | export default Register; 62 | -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | OnlineShop 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /frontend/src/slices/productsSlice.js: -------------------------------------------------------------------------------- 1 | import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; 2 | import axios from "axios"; 3 | import { url, setHeaders } from "./api"; 4 | import { toast } from "react-toastify"; 5 | 6 | const initialState = { 7 | items: [], 8 | status: null, 9 | createStatus: null, 10 | }; 11 | 12 | export const productsFetch = createAsyncThunk( 13 | "products/productsFetch", 14 | async () => { 15 | try { 16 | const response = await axios.get(`${url}/products`); 17 | 18 | return response.data; 19 | } catch (error) { 20 | console.log(error); 21 | } 22 | } 23 | ); 24 | 25 | export const productsCreate = createAsyncThunk( 26 | "products/productsCreate", 27 | async (values) => { 28 | try { 29 | const response = await axios.post( 30 | `${url}/products`, 31 | values, 32 | setHeaders() 33 | ); 34 | 35 | return response.data; 36 | } catch (error) { 37 | console.log(error); 38 | toast.error(error.response?.data); 39 | } 40 | } 41 | ); 42 | 43 | const productsSlice = createSlice({ 44 | name: "products", 45 | initialState, 46 | reducers: {}, 47 | extraReducers: { 48 | [productsFetch.pending]: (state, action) => { 49 | state.status = "pending"; 50 | }, 51 | [productsFetch.fulfilled]: (state, action) => { 52 | state.items = action.payload; 53 | state.status = "success"; 54 | }, 55 | [productsFetch.rejected]: (state, action) => { 56 | state.status = "rejected"; 57 | }, 58 | [productsCreate.pending]: (state, action) => { 59 | state.createStatus = "pending"; 60 | }, 61 | [productsCreate.fulfilled]: (state, action) => { 62 | state.items.push(action.payload); 63 | state.createStatus = "success"; 64 | toast.success("Product Created!"); 65 | }, 66 | [productsCreate.rejected]: (state, action) => { 67 | state.createStatus = "rejected"; 68 | }, 69 | }, 70 | }); 71 | 72 | export default productsSlice.reducer; 73 | -------------------------------------------------------------------------------- /frontend/src/components/admin/Dashboard.jsx: -------------------------------------------------------------------------------- 1 | import styled from "styled-components"; 2 | import { Outlet, NavLink } from "react-router-dom"; 3 | import { useSelector } from "react-redux"; 4 | 5 | const Dashboard = () => { 6 | const auth = useSelector((state) => state.auth); 7 | 8 | if (!auth.isAdmin) return

Access denied. Not an Admin!

; 9 | 10 | return ( 11 | 12 | 13 |

Quick Links

14 | 16 | isActive ? "link-active" : "link-inactive" 17 | } 18 | to="/admin/summary" 19 | > 20 | Summary 21 | 22 | 24 | isActive ? "link-active" : "link-inactive" 25 | } 26 | to="/admin/products" 27 | > 28 | Products 29 | 30 | 32 | isActive ? "link-active" : "link-inactive" 33 | } 34 | to="/admin/orders" 35 | > 36 | Orders 37 | 38 | 40 | isActive ? "link-active" : "link-inactive" 41 | } 42 | to="/admin/users" 43 | > 44 | Users 45 | 46 |
47 | 48 | 49 | 50 |
51 | ); 52 | }; 53 | 54 | export default Dashboard; 55 | 56 | const StyledDashboard = styled.div` 57 | display: flex; 58 | height: 100vh; 59 | `; 60 | 61 | const SideNav = styled.div` 62 | border-right: 1px solid gray; 63 | height: calc(100vh - 70px); 64 | position: fixed; 65 | overflow-y: auto; 66 | width: 200px; 67 | display: flex; 68 | flex-direction: column; 69 | padding: 2rem; 70 | 71 | h3 { 72 | margin: 0 0 1rem 0; 73 | padding: 0; 74 | text-transform: uppercase; 75 | font-size: 17px; 76 | } 77 | 78 | a { 79 | text-decoration: none; 80 | margin-bottom: 1rem; 81 | font-size: 14px; 82 | } 83 | `; 84 | 85 | const Content = styled.div` 86 | margin-left: 200px; 87 | padding: 2rem 3rem; 88 | width: 100%; 89 | `; 90 | -------------------------------------------------------------------------------- /frontend/src/App.js: -------------------------------------------------------------------------------- 1 | import "./App.css"; 2 | import { BrowserRouter, Routes, Route } from "react-router-dom"; 3 | import { ToastContainer } from "react-toastify"; 4 | 5 | import Home from "./components/Home"; 6 | import NavBar from "./components/NavBar"; 7 | import NotFound from "./components/NotFound"; 8 | import Cart from "./components/Cart"; 9 | 10 | import "react-toastify/dist/ReactToastify.css"; 11 | import Register from "./components/auth/Register"; 12 | import Login from "./components/auth/Login"; 13 | import { useEffect } from "react"; 14 | import { useDispatch } from "react-redux"; 15 | import { loadUser } from "./slices/authSlice"; 16 | import CheckoutSuccess from "./components/CheckoutSuccess"; 17 | import Dashboard from "./components/admin/Dashboard"; 18 | import Products from "./components/admin/Products"; 19 | import Users from "./components/admin/Users"; 20 | import Orders from "./components/admin/Oders"; 21 | import Summary from "./components/admin/Summary"; 22 | import CreateProduct from "./components/admin/CreateProduct"; 23 | 24 | function App() { 25 | const dispatch = useDispatch(); 26 | 27 | useEffect(() => { 28 | dispatch(loadUser(null)); 29 | }, [dispatch]); 30 | 31 | return ( 32 |
33 | 34 | 35 | 36 |
37 | 38 | } /> 39 | } /> 40 | } /> 41 | } /> 42 | } /> 43 | }> 44 | } /> 45 | }> 46 | } /> 47 | 48 | } /> 49 | } /> 50 | 51 | } /> 52 | 53 |
54 |
55 |
56 | ); 57 | } 58 | 59 | export default App; 60 | -------------------------------------------------------------------------------- /frontend/src/components/NavBar.jsx: -------------------------------------------------------------------------------- 1 | import { Link } from "react-router-dom"; 2 | import { useSelector, useDispatch } from "react-redux"; 3 | import styled from "styled-components"; 4 | import { logoutUser } from "../slices/authSlice"; 5 | import { toast } from "react-toastify"; 6 | 7 | const NavBar = () => { 8 | const dispatch = useDispatch(); 9 | const { cartTotalQuantity } = useSelector((state) => state.cart); 10 | const auth = useSelector((state) => state.auth); 11 | 12 | console.log(auth); 13 | 14 | return ( 15 | 59 | ); 60 | }; 61 | 62 | export default NavBar; 63 | 64 | const AuthLinks = styled.div` 65 | a { 66 | &:last-child { 67 | margin-left: 2rem; 68 | } 69 | } 70 | `; 71 | 72 | const Links = styled.div` 73 | color: white; 74 | display: flex; 75 | 76 | div { 77 | cursor: pointer; 78 | 79 | &:last-child { 80 | margin-left: 2rem; 81 | } 82 | } 83 | `; 84 | -------------------------------------------------------------------------------- /backend/routes/products.js: -------------------------------------------------------------------------------- 1 | const { Product } = require("../models/Product"); 2 | const { auth, isUser, isAdmin } = require("../middleware/auth"); 3 | const cloudinary = require("../utils/cloudinary"); 4 | 5 | const router = require("express").Router(); 6 | 7 | //CREATE 8 | 9 | router.post("/", isAdmin, async (req, res) => { 10 | const { name, brand, desc, price, image } = req.body; 11 | 12 | try { 13 | if (image) { 14 | const uploadedResponse = await cloudinary.uploader.upload(image, { 15 | upload_preset: "online-shop", 16 | }); 17 | 18 | if (uploadedResponse) { 19 | const product = new Product({ 20 | name, 21 | brand, 22 | desc, 23 | price, 24 | image: uploadedResponse, 25 | }); 26 | 27 | const savedProduct = await product.save(); 28 | res.status(200).send(savedProduct); 29 | } 30 | } 31 | } catch (error) { 32 | console.log(error); 33 | res.status(500).send(error); 34 | } 35 | }); 36 | 37 | //DELETE 38 | 39 | router.delete("/:id", isAdmin, async (req, res) => { 40 | try { 41 | await Product.findByIdAndDelete(req.params.id); 42 | res.status(200).send("Product has been deleted..."); 43 | } catch (error) { 44 | res.status(500).send(error); 45 | } 46 | }); 47 | 48 | //GET ALL PRODUCTS 49 | 50 | router.get("/", async (req, res) => { 51 | const qbrand = req.query.brand; 52 | try { 53 | let products; 54 | 55 | if (qbrand) { 56 | products = await Product.find({ 57 | brand: qbrand, 58 | }); 59 | } else { 60 | products = await Product.find(); 61 | } 62 | 63 | res.status(200).send(products); 64 | } catch (error) { 65 | res.status(500).send(error); 66 | } 67 | }); 68 | 69 | //GET PRODUCT 70 | 71 | router.get("/find/:id", async (req, res) => { 72 | try { 73 | const product = await Product.findById(req.params.id); 74 | res.status(200).send(product); 75 | } catch (error) { 76 | res.status(500).send(error); 77 | } 78 | }); 79 | 80 | //UPDATE 81 | 82 | router.put("/:id", isAdmin, async (req, res) => { 83 | try { 84 | const updatedProduct = await Product.findByIdAndUpdate( 85 | req.params.id, 86 | { 87 | $set: req.body, 88 | }, 89 | { new: true } 90 | ); 91 | res.status(200).send(updatedProduct); 92 | } catch (error) { 93 | res.status(500).send(error); 94 | } 95 | }); 96 | 97 | module.exports = router; 98 | -------------------------------------------------------------------------------- /backend/routes/orders.js: -------------------------------------------------------------------------------- 1 | const { Order } = require("../models/Order"); 2 | const { auth, isUser, isAdmin } = require("../middleware/auth"); 3 | 4 | const router = require("express").Router(); 5 | 6 | //CREATE 7 | 8 | // createOrder is fired by stripe webhook 9 | // example endpoint 10 | 11 | router.post("/", auth, async (req, res) => { 12 | const newOrder = new Order(req.body); 13 | 14 | try { 15 | const savedOrder = await newOrder.save(); 16 | res.status(200).send(savedOrder); 17 | } catch (err) { 18 | res.status(500).send(err); 19 | } 20 | }); 21 | 22 | //UPDATE 23 | router.put("/:id", isAdmin, async (req, res) => { 24 | try { 25 | const updatedOrder = await Order.findByIdAndUpdate( 26 | req.params.id, 27 | { 28 | $set: req.body, 29 | }, 30 | { new: true } 31 | ); 32 | res.status(200).send(updatedOrder); 33 | } catch (err) { 34 | res.status(500).send(err); 35 | } 36 | }); 37 | 38 | //DELETE 39 | router.delete("/:id", isAdmin, async (req, res) => { 40 | try { 41 | await Order.findByIdAndDelete(req.params.id); 42 | res.status(200).send("Order has been deleted..."); 43 | } catch (err) { 44 | res.status(500).send(err); 45 | } 46 | }); 47 | 48 | //GET USER ORDERS 49 | router.get("/find/:userId", isUser, async (req, res) => { 50 | try { 51 | const orders = await Order.find({ userId: req.params.userId }); 52 | res.status(200).send(orders); 53 | } catch (err) { 54 | res.status(500).send(err); 55 | } 56 | }); 57 | 58 | //GET ALL ORDERS 59 | 60 | router.get("/", isAdmin, async (req, res) => { 61 | try { 62 | const orders = await Order.find(); 63 | res.status(200).send(orders); 64 | } catch (err) { 65 | res.status(500).send(err); 66 | } 67 | }); 68 | 69 | // GET MONTHLY INCOME 70 | 71 | router.get("/income", isAdmin, async (req, res) => { 72 | const date = new Date(); 73 | const lastMonth = new Date(date.setMonth(date.getMonth() - 1)); 74 | const previousMonth = new Date(new Date().setMonth(lastMonth.getMonth() - 1)); 75 | 76 | try { 77 | const income = await Order.aggregate([ 78 | { $match: { createdAt: { $gte: previousMonth } } }, 79 | { 80 | $project: { 81 | month: { $month: "$createdAt" }, 82 | sales: "$amount", 83 | }, 84 | }, 85 | { 86 | $group: { 87 | _id: "$month", 88 | total: { $sum: "$sales" }, 89 | }, 90 | }, 91 | ]); 92 | res.status(200).send(income); 93 | } catch (err) { 94 | res.status(500).send(err); 95 | } 96 | }); 97 | 98 | module.exports = router; 99 | -------------------------------------------------------------------------------- /frontend/README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `npm start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `npm test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `npm run build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `npm run eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | 48 | ### Code Splitting 49 | 50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting) 51 | 52 | ### Analyzing the Bundle Size 53 | 54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size) 55 | 56 | ### Making a Progressive Web App 57 | 58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app) 59 | 60 | ### Advanced Configuration 61 | 62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration) 63 | 64 | ### Deployment 65 | 66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment) 67 | 68 | ### `npm run build` fails to minify 69 | 70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify) 71 | -------------------------------------------------------------------------------- /frontend/src/slices/cartSlice.js: -------------------------------------------------------------------------------- 1 | import { createSlice } from "@reduxjs/toolkit"; 2 | import { toast } from "react-toastify"; 3 | 4 | const initialState = { 5 | cartItems: localStorage.getItem("cartItems") 6 | ? JSON.parse(localStorage.getItem("cartItems")) 7 | : [], 8 | cartTotalQuantity: 0, 9 | cartTotalAmount: 0, 10 | }; 11 | 12 | const cartSlice = createSlice({ 13 | name: "cart", 14 | initialState, 15 | reducers: { 16 | addToCart(state, action) { 17 | const existingIndex = state.cartItems.findIndex( 18 | (item) => item._id === action.payload._id 19 | ); 20 | 21 | if (existingIndex >= 0) { 22 | state.cartItems[existingIndex] = { 23 | ...state.cartItems[existingIndex], 24 | cartQuantity: state.cartItems[existingIndex].cartQuantity + 1, 25 | }; 26 | toast.info("Increased product quantity", { 27 | position: "bottom-left", 28 | }); 29 | } else { 30 | let tempProductItem = { ...action.payload, cartQuantity: 1 }; 31 | state.cartItems.push(tempProductItem); 32 | toast.success("Product added to cart", { 33 | position: "bottom-left", 34 | }); 35 | } 36 | localStorage.setItem("cartItems", JSON.stringify(state.cartItems)); 37 | }, 38 | decreaseCart(state, action) { 39 | const itemIndex = state.cartItems.findIndex( 40 | (item) => item._id === action.payload._id 41 | ); 42 | 43 | if (state.cartItems[itemIndex].cartQuantity > 1) { 44 | state.cartItems[itemIndex].cartQuantity -= 1; 45 | 46 | toast.info("Decreased product quantity", { 47 | position: "bottom-left", 48 | }); 49 | } else if (state.cartItems[itemIndex].cartQuantity === 1) { 50 | const nextCartItems = state.cartItems.filter( 51 | (item) => item._id !== action.payload._id 52 | ); 53 | 54 | state.cartItems = nextCartItems; 55 | 56 | toast.error("Product removed from cart", { 57 | position: "bottom-left", 58 | }); 59 | } 60 | 61 | localStorage.setItem("cartItems", JSON.stringify(state.cartItems)); 62 | }, 63 | removeFromCart(state, action) { 64 | state.cartItems.map((cartItem) => { 65 | if (cartItem._id === action.payload._id) { 66 | const nextCartItems = state.cartItems.filter( 67 | (item) => item._id !== cartItem._id 68 | ); 69 | 70 | state.cartItems = nextCartItems; 71 | 72 | toast.error("Product removed from cart", { 73 | position: "bottom-left", 74 | }); 75 | } 76 | localStorage.setItem("cartItems", JSON.stringify(state.cartItems)); 77 | return state; 78 | }); 79 | }, 80 | getTotals(state, action) { 81 | let { total, quantity } = state.cartItems.reduce( 82 | (cartTotal, cartItem) => { 83 | const { price, cartQuantity } = cartItem; 84 | const itemTotal = price * cartQuantity; 85 | 86 | cartTotal.total += itemTotal; 87 | cartTotal.quantity += cartQuantity; 88 | 89 | return cartTotal; 90 | }, 91 | { 92 | total: 0, 93 | quantity: 0, 94 | } 95 | ); 96 | total = parseFloat(total.toFixed(2)); 97 | state.cartTotalQuantity = quantity; 98 | state.cartTotalAmount = total; 99 | }, 100 | clearCart(state, action) { 101 | state.cartItems = []; 102 | localStorage.setItem("cartItems", JSON.stringify(state.cartItems)); 103 | toast.error("Cart cleared", { position: "bottom-left" }); 104 | }, 105 | }, 106 | }); 107 | 108 | export const { addToCart, decreaseCart, removeFromCart, getTotals, clearCart } = 109 | cartSlice.actions; 110 | 111 | export default cartSlice.reducer; 112 | -------------------------------------------------------------------------------- /frontend/src/components/admin/CreateProduct.jsx: -------------------------------------------------------------------------------- 1 | import { useState } from "react"; 2 | import { useDispatch, useSelector } from "react-redux"; 3 | import { useNavigate } from "react-router-dom"; 4 | import styled from "styled-components"; 5 | import { PrimaryButton } from "./CommonStyled"; 6 | import { productsCreate } from "../../slices/productsSlice"; 7 | 8 | const CreateProduct = () => { 9 | const dispatch = useDispatch(); 10 | const { createStatus } = useSelector((state) => state.products); 11 | 12 | const [productImg, setProductImg] = useState(""); 13 | const [brand, setBrand] = useState(""); 14 | const [name, setName] = useState(""); 15 | const [price, setPrice] = useState(""); 16 | const [desc, setDesc] = useState(""); 17 | 18 | const handleProductImageUpload = (e) => { 19 | const file = e.target.files[0]; 20 | 21 | TransformFileData(file); 22 | }; 23 | 24 | const TransformFileData = (file) => { 25 | const reader = new FileReader(); 26 | 27 | if (file) { 28 | reader.readAsDataURL(file); 29 | reader.onloadend = () => { 30 | setProductImg(reader.result); 31 | }; 32 | } else { 33 | setProductImg(""); 34 | } 35 | }; 36 | 37 | const handleSubmit = async (e) => { 38 | e.preventDefault(); 39 | 40 | dispatch( 41 | productsCreate({ 42 | name, 43 | brand, 44 | price, 45 | desc, 46 | image: productImg, 47 | }) 48 | ); 49 | }; 50 | 51 | return ( 52 | 53 | 54 |

Create a Product

55 | 62 | 69 | setName(e.target.value)} 73 | required 74 | /> 75 | setPrice(e.target.value)} 79 | required 80 | /> 81 | setDesc(e.target.value)} 85 | required 86 | /> 87 | 88 | 89 | {createStatus === "pending" ? "Submitting" : "Submit"} 90 | 91 |
92 | 93 | {productImg ? ( 94 | <> 95 | error! 96 | 97 | ) : ( 98 |

Product image upload preview will appear here!

99 | )} 100 |
101 |
102 | ); 103 | }; 104 | 105 | export default CreateProduct; 106 | 107 | const StyledForm = styled.form` 108 | display: flex; 109 | flex-direction: column; 110 | max-width: 300px; 111 | margin-top: 2rem; 112 | 113 | select, 114 | input { 115 | padding: 7px; 116 | min-height: 30px; 117 | outline: none; 118 | border-radius: 5px; 119 | border: 1px solid rgb(182, 182, 182); 120 | margin: 0.3rem 0; 121 | 122 | &:focus { 123 | border: 2px solid rgb(0, 208, 255); 124 | } 125 | } 126 | 127 | select { 128 | color: rgb(95, 95, 95); 129 | } 130 | `; 131 | 132 | const StyledCreateProduct = styled.div` 133 | display: flex; 134 | justify-content: space-between; 135 | `; 136 | 137 | const ImagePreview = styled.div` 138 | margin: 2rem 0 2rem 2rem; 139 | padding: 2rem; 140 | border: 1px solid rgb(183, 183, 183); 141 | max-width: 300px; 142 | width: 100%; 143 | display: flex; 144 | align-items: center; 145 | justify-content: center; 146 | padding: 2rem; 147 | color: rgb(78, 78, 78); 148 | 149 | img { 150 | max-width: 100%; 151 | } 152 | `; 153 | -------------------------------------------------------------------------------- /frontend/src/components/Cart.jsx: -------------------------------------------------------------------------------- 1 | import { useEffect } from "react"; 2 | import { useNavigate } from "react-router-dom"; 3 | import { useDispatch, useSelector } from "react-redux"; 4 | import { 5 | addToCart, 6 | clearCart, 7 | decreaseCart, 8 | getTotals, 9 | removeFromCart, 10 | } from "../slices/cartSlice"; 11 | 12 | import { Link } from "react-router-dom"; 13 | import PayButton from "./PayButton"; 14 | 15 | const Cart = () => { 16 | const cart = useSelector((state) => state.cart); 17 | const auth = useSelector((state) => state.auth); 18 | 19 | const dispatch = useDispatch(); 20 | const navigate = useNavigate(); 21 | 22 | useEffect(() => { 23 | dispatch(getTotals()); 24 | }, [cart, dispatch]); 25 | 26 | const handleAddToCart = (product) => { 27 | dispatch(addToCart(product)); 28 | }; 29 | const handleDecreaseCart = (product) => { 30 | dispatch(decreaseCart(product)); 31 | }; 32 | const handleRemoveFromCart = (product) => { 33 | dispatch(removeFromCart(product)); 34 | }; 35 | const handleClearCart = () => { 36 | dispatch(clearCart()); 37 | }; 38 | return ( 39 |
40 |

Shopping Cart

41 | {cart.cartItems.length === 0 ? ( 42 |
43 |

Your cart is currently empty

44 |
45 | 46 | 54 | 58 | 59 | Start Shopping 60 | 61 |
62 |
63 | ) : ( 64 |
65 |
66 |

Product

67 |

Price

68 |

Quantity

69 |

Total

70 |
71 |
72 | {cart.cartItems && 73 | cart.cartItems.map((cartItem) => ( 74 |
75 |
76 | {cartItem.name} 77 |
78 |

{cartItem.name}

79 |

{cartItem.desc}

80 | 83 |
84 |
85 |
${cartItem.price}
86 |
87 | 90 |
{cartItem.cartQuantity}
91 | 92 |
93 |
94 | ${cartItem.price * cartItem.cartQuantity} 95 |
96 |
97 | ))} 98 |
99 |
100 | 103 |
104 |
105 | Subtotal 106 | ${cart.cartTotalAmount} 107 |
108 |

Taxes and shipping calculated at checkout

109 | {auth._id ? ( 110 | 111 | ) : ( 112 | 118 | )} 119 | 120 |
121 | 122 | 130 | 134 | 135 | Continue Shopping 136 | 137 |
138 |
139 |
140 |
141 | )} 142 |
143 | ); 144 | }; 145 | 146 | export default Cart; 147 | -------------------------------------------------------------------------------- /backend/routes/stripe.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const Stripe = require("stripe"); 3 | const { Order } = require("../models/Order"); 4 | 5 | require("dotenv").config(); 6 | 7 | const stripe = Stripe(process.env.STRIPE_KEY); 8 | 9 | const router = express.Router(); 10 | 11 | router.post("/create-checkout-session", async (req, res) => { 12 | const customer = await stripe.customers.create({ 13 | metadata: { 14 | userId: req.body.userId, 15 | cart: JSON.stringify(req.body.cartItems), 16 | }, 17 | }); 18 | 19 | const line_items = req.body.cartItems.map((item) => { 20 | return { 21 | price_data: { 22 | currency: "usd", 23 | product_data: { 24 | name: item.name, 25 | images: [item.image], 26 | description: item.desc, 27 | metadata: { 28 | id: item.id, 29 | }, 30 | }, 31 | unit_amount: item.price * 100, 32 | }, 33 | quantity: item.cartQuantity, 34 | }; 35 | }); 36 | 37 | const session = await stripe.checkout.sessions.create({ 38 | payment_method_types: ["card"], 39 | shipping_address_collection: { 40 | allowed_countries: ["US", "CA", "KE"], 41 | }, 42 | shipping_options: [ 43 | { 44 | shipping_rate_data: { 45 | type: "fixed_amount", 46 | fixed_amount: { 47 | amount: 0, 48 | currency: "usd", 49 | }, 50 | display_name: "Free shipping", 51 | // Delivers between 5-7 business days 52 | delivery_estimate: { 53 | minimum: { 54 | unit: "business_day", 55 | value: 5, 56 | }, 57 | maximum: { 58 | unit: "business_day", 59 | value: 7, 60 | }, 61 | }, 62 | }, 63 | }, 64 | { 65 | shipping_rate_data: { 66 | type: "fixed_amount", 67 | fixed_amount: { 68 | amount: 1500, 69 | currency: "usd", 70 | }, 71 | display_name: "Next day air", 72 | // Delivers in exactly 1 business day 73 | delivery_estimate: { 74 | minimum: { 75 | unit: "business_day", 76 | value: 1, 77 | }, 78 | maximum: { 79 | unit: "business_day", 80 | value: 1, 81 | }, 82 | }, 83 | }, 84 | }, 85 | ], 86 | phone_number_collection: { 87 | enabled: true, 88 | }, 89 | line_items, 90 | mode: "payment", 91 | customer: customer.id, 92 | success_url: `${process.env.CLIENT_URL}/checkout-success`, 93 | cancel_url: `${process.env.CLIENT_URL}/cart`, 94 | }); 95 | 96 | // res.redirect(303, session.url); 97 | res.send({ url: session.url }); 98 | }); 99 | 100 | // Create order function 101 | 102 | const createOrder = async (customer, data) => { 103 | const Items = JSON.parse(customer.metadata.cart); 104 | 105 | const products = Items.map((item) => { 106 | return { 107 | productId: item.id, 108 | quantity: item.cartQuantity, 109 | }; 110 | }); 111 | 112 | const newOrder = new Order({ 113 | userId: customer.metadata.userId, 114 | customerId: data.customer, 115 | paymentIntentId: data.payment_intent, 116 | products, 117 | subtotal: data.amount_subtotal, 118 | total: data.amount_total, 119 | shipping: data.customer_details, 120 | payment_status: data.payment_status, 121 | }); 122 | 123 | try { 124 | const savedOrder = await newOrder.save(); 125 | console.log("Processed Order:", savedOrder); 126 | } catch (err) { 127 | console.log(err); 128 | } 129 | }; 130 | 131 | // Stripe webhoook 132 | 133 | router.post( 134 | "/webhook", 135 | express.json({ type: "application/json" }), 136 | async (req, res) => { 137 | let data; 138 | let eventType; 139 | 140 | // Check if webhook signing is configured. 141 | let webhookSecret; 142 | //webhookSecret = process.env.STRIPE_WEB_HOOK; 143 | 144 | if (webhookSecret) { 145 | // Retrieve the event by verifying the signature using the raw body and secret. 146 | let event; 147 | let signature = req.headers["stripe-signature"]; 148 | 149 | try { 150 | event = stripe.webhooks.constructEvent( 151 | req.body, 152 | signature, 153 | webhookSecret 154 | ); 155 | } catch (err) { 156 | console.log(`⚠️ Webhook signature verification failed: ${err}`); 157 | return res.sendStatus(400); 158 | } 159 | // Extract the object from the event. 160 | data = event.data.object; 161 | eventType = event.type; 162 | } else { 163 | // Webhook signing is recommended, but if the secret is not configured in `config.js`, 164 | // retrieve the event data directly from the request body. 165 | data = req.body.data.object; 166 | eventType = req.body.type; 167 | } 168 | 169 | // Handle the checkout.session.completed event 170 | if (eventType === "checkout.session.completed") { 171 | stripe.customers 172 | .retrieve(data.customer) 173 | .then(async (customer) => { 174 | try { 175 | // CREATE ORDER 176 | createOrder(customer, data); 177 | } catch (err) { 178 | console.log(typeof createOrder); 179 | console.log(err); 180 | } 181 | }) 182 | .catch((err) => console.log(err.message)); 183 | } 184 | 185 | res.status(200).end(); 186 | } 187 | ); 188 | 189 | module.exports = router; 190 | -------------------------------------------------------------------------------- /frontend/src/slices/authSlice.js: -------------------------------------------------------------------------------- 1 | import { createSlice, createAsyncThunk } from "@reduxjs/toolkit"; 2 | import jwtDecode from "jwt-decode"; 3 | import axios from "axios"; 4 | import { url, setHeaders } from "./api"; 5 | 6 | const initialState = { 7 | token: localStorage.getItem("token"), 8 | name: "", 9 | email: "", 10 | _id: "", 11 | isAdmin: false, 12 | registerStatus: "", 13 | registerError: "", 14 | loginStatus: "", 15 | loginError: "", 16 | userLoaded: false, 17 | }; 18 | 19 | export const registerUser = createAsyncThunk( 20 | "auth/registerUser", 21 | async (values, { rejectWithValue }) => { 22 | try { 23 | const token = await axios.post(`${url}/register`, { 24 | name: values.name, 25 | email: values.email, 26 | password: values.password, 27 | }); 28 | 29 | localStorage.setItem("token", token.data); 30 | 31 | return token.data; 32 | } catch (error) { 33 | console.log(error.response.data); 34 | return rejectWithValue(error.response.data); 35 | } 36 | } 37 | ); 38 | 39 | export const loginUser = createAsyncThunk( 40 | "auth/loginUser", 41 | async (values, { rejectWithValue }) => { 42 | try { 43 | const token = await axios.post(`${url}/login`, { 44 | email: values.email, 45 | password: values.password, 46 | }); 47 | 48 | localStorage.setItem("token", token.data); 49 | return token.data; 50 | } catch (error) { 51 | console.log(error.response); 52 | return rejectWithValue(error.response.data); 53 | } 54 | } 55 | ); 56 | 57 | export const getUser = createAsyncThunk( 58 | "auth/getUser", 59 | async (id, { rejectWithValue }) => { 60 | try { 61 | const token = await axios.get(`${url}/user/${id}`, setHeaders()); 62 | 63 | localStorage.setItem("token", token.data); 64 | 65 | return token.data; 66 | } catch (error) { 67 | console.log(error.response); 68 | return rejectWithValue(error.response.data); 69 | } 70 | } 71 | ); 72 | 73 | const authSlice = createSlice({ 74 | name: "auth", 75 | initialState, 76 | reducers: { 77 | loadUser(state, action) { 78 | const token = state.token; 79 | 80 | if (token) { 81 | const user = jwtDecode(token); 82 | return { 83 | ...state, 84 | token, 85 | name: user.name, 86 | email: user.email, 87 | _id: user._id, 88 | isAdmin: user.isAdmin, 89 | userLoaded: true, 90 | }; 91 | } else return { ...state, userLoaded: true }; 92 | }, 93 | logoutUser(state, action) { 94 | localStorage.removeItem("token"); 95 | 96 | return { 97 | ...state, 98 | token: "", 99 | name: "", 100 | email: "", 101 | _id: "", 102 | isAdmin: false, 103 | registerStatus: "", 104 | registerError: "", 105 | loginStatus: "", 106 | loginError: "", 107 | }; 108 | }, 109 | }, 110 | extraReducers: (builder) => { 111 | builder.addCase(registerUser.pending, (state, action) => { 112 | return { ...state, registerStatus: "pending" }; 113 | }); 114 | builder.addCase(registerUser.fulfilled, (state, action) => { 115 | if (action.payload) { 116 | const user = jwtDecode(action.payload); 117 | return { 118 | ...state, 119 | token: action.payload, 120 | name: user.name, 121 | email: user.email, 122 | _id: user._id, 123 | isAdmin: user.isAdmin, 124 | registerStatus: "success", 125 | }; 126 | } else return state; 127 | }); 128 | builder.addCase(registerUser.rejected, (state, action) => { 129 | return { 130 | ...state, 131 | registerStatus: "rejected", 132 | registerError: action.payload, 133 | }; 134 | }); 135 | builder.addCase(loginUser.pending, (state, action) => { 136 | return { ...state, loginStatus: "pending" }; 137 | }); 138 | builder.addCase(loginUser.fulfilled, (state, action) => { 139 | if (action.payload) { 140 | const user = jwtDecode(action.payload); 141 | return { 142 | ...state, 143 | token: action.payload, 144 | name: user.name, 145 | email: user.email, 146 | _id: user._id, 147 | isAdmin: user.isAdmin, 148 | loginStatus: "success", 149 | }; 150 | } else return state; 151 | }); 152 | builder.addCase(loginUser.rejected, (state, action) => { 153 | return { 154 | ...state, 155 | loginStatus: "rejected", 156 | loginError: action.payload, 157 | }; 158 | }); 159 | builder.addCase(getUser.pending, (state, action) => { 160 | return { 161 | ...state, 162 | getUserStatus: "pending", 163 | }; 164 | }); 165 | builder.addCase(getUser.fulfilled, (state, action) => { 166 | if (action.payload) { 167 | const user = jwtDecode(action.payload); 168 | return { 169 | ...state, 170 | token: action.payload, 171 | name: user.name, 172 | email: user.email, 173 | _id: user._id, 174 | isAdmin: user.isAdmin, 175 | getUserStatus: "success", 176 | }; 177 | } else return state; 178 | }); 179 | builder.addCase(getUser.rejected, (state, action) => { 180 | return { 181 | ...state, 182 | getUserStatus: "rejected", 183 | getUserError: action.payload, 184 | }; 185 | }); 186 | }, 187 | }); 188 | 189 | export const { loadUser, logoutUser } = authSlice.actions; 190 | 191 | export default authSlice.reducer; 192 | -------------------------------------------------------------------------------- /frontend/src/App.css: -------------------------------------------------------------------------------- 1 | @import url("https://fonts.googleapis.com/css2?family=Nunito:wght@200;400;700&display=swap"); 2 | 3 | * { 4 | padding: 0; 5 | margin: 0; 6 | box-sizing: border-box; 7 | font-family: "Nunito", sans-serif; 8 | } 9 | 10 | /* Not Found */ 11 | .not-found { 12 | display: flex; 13 | flex-direction: column; 14 | align-items: center; 15 | justify-content: center; 16 | color: rgb(68, 68, 68); 17 | min-height: 80vh; 18 | } 19 | .not-found h2 { 20 | font-size: 55px; 21 | } 22 | .not-found p { 23 | font-size: 20px; 24 | } 25 | 26 | /* NavBar */ 27 | 28 | .nav-bar { 29 | position: sticky; 30 | top: 0; 31 | height: 70px; 32 | background: black; 33 | display: flex; 34 | justify-content: space-between; 35 | align-items: center; 36 | padding: 0 4rem; 37 | } 38 | .nav-bar a { 39 | text-decoration: none; 40 | color: white; 41 | } 42 | .nav-bar h2 { 43 | font-size: 40px; 44 | } 45 | .nav-bag { 46 | display: flex; 47 | align-items: center; 48 | } 49 | .bag-quantity { 50 | display: flex; 51 | align-items: center; 52 | justify-content: center; 53 | height: 25px; 54 | width: 25px; 55 | border-radius: 50%; 56 | background: yellow; 57 | font-size: 14px; 58 | font-weight: 700; 59 | color: black; 60 | margin-left: 5px; 61 | } 62 | 63 | /* Home */ 64 | 65 | .home-container { 66 | padding: 2rem 4rem; 67 | } 68 | .home-container h2 { 69 | font-size: 40px; 70 | font-weight: 400; 71 | text-align: center; 72 | } 73 | .products { 74 | display: flex; 75 | justify-content: space-between; 76 | flex-wrap: wrap; 77 | margin-top: 2rem; 78 | } 79 | .product { 80 | display: flex; 81 | flex-direction: column; 82 | justify-content: space-between; 83 | margin: 1rem auto; 84 | padding: 1rem; 85 | border-radius: 15px; 86 | width: 250px; 87 | max-width: 100%; 88 | height: 400px; 89 | box-shadow: -5px -5px 10px rgba(255, 255, 255, 0.5), 90 | 2px 2px 5px rgba(94, 104, 121, 0.3); 91 | } 92 | .product h3 { 93 | font-size: 25px; 94 | font-weight: 400; 95 | } 96 | .product img { 97 | width: 80%; 98 | margin-top: 1rem; 99 | margin-left: auto; 100 | margin-right: auto; 101 | } 102 | .product .details { 103 | display: flex; 104 | justify-content: space-between; 105 | align-items: center; 106 | } 107 | .product .details .price { 108 | font-size: 20px; 109 | font-weight: 700; 110 | } 111 | .product button { 112 | width: 100%; 113 | height: 40px; 114 | border-radius: 5px; 115 | margin-top: 2rem; 116 | font-weight: 400; 117 | letter-spacing: 1.15px; 118 | background-color: #4b70e2; 119 | color: #f9f9f9; 120 | border: none; 121 | outline: none; 122 | cursor: pointer; 123 | } 124 | 125 | /* Cart */ 126 | .cart-container { 127 | padding: 2rem 4rem; 128 | } 129 | .cart-container h2 { 130 | font-weight: 400; 131 | font-size: 30px; 132 | text-align: center; 133 | } 134 | .cart-container .titles { 135 | margin: 2rem 0 1rem 0; 136 | } 137 | .cart-container .titles h3 { 138 | font-size: 14px; 139 | font-weight: 400; 140 | text-transform: uppercase; 141 | } 142 | .cart-item, 143 | .cart-container .titles { 144 | display: grid; 145 | align-items: center; 146 | grid-template-columns: 3fr 1fr 1fr 1fr; 147 | column-gap: 0.5rem; 148 | } 149 | .cart-item { 150 | border-top: 1px solid rgb(187, 187, 187); 151 | padding: 1rem 0; 152 | } 153 | .cart-container .titles .product-title { 154 | padding-left: 0.5rem; 155 | } 156 | .cart-container .titles .total { 157 | padding-right: 0.5rem; 158 | justify-self: right; 159 | } 160 | .cart-item .cart-product { 161 | display: flex; 162 | } 163 | .cart-item .cart-product img { 164 | width: 100px; 165 | max-width: 100%; 166 | margin-right: 1rem; 167 | } 168 | .cart-item .cart-product h3 { 169 | font-weight: 400; 170 | } 171 | .cart-item .cart-product button { 172 | border: none; 173 | outline: none; 174 | margin-top: 0.7rem; 175 | cursor: pointer; 176 | background: none; 177 | color: gray; 178 | } 179 | .cart-item .cart-product button:hover { 180 | color: black; 181 | } 182 | 183 | .cart-item .cart-product-quantity { 184 | display: flex; 185 | align-items: flex-start; 186 | justify-content: center; 187 | width: 130px; 188 | max-width: 100%; 189 | border: 0.5px solid rgb(177, 177, 177); 190 | border-radius: 5px; 191 | } 192 | .cart-item .cart-product-quantity button { 193 | border: none; 194 | outline: none; 195 | background: none; 196 | padding: 0.7rem 1.5rem; 197 | cursor: pointer; 198 | } 199 | .cart-item .cart-product-quantity .count { 200 | padding: 0.7rem 0; 201 | } 202 | .cart-item .cart-product-total-price { 203 | padding-right: 0.5rem; 204 | justify-self: right; 205 | font-weight: 700; 206 | } 207 | 208 | /* cart summary */ 209 | .cart-summary { 210 | display: flex; 211 | justify-content: space-between; 212 | align-items: flex-start; 213 | border-top: 1px solid rgb(187, 187, 187); 214 | padding-top: 2rem; 215 | } 216 | .cart-summary .clear-btn { 217 | width: 130px; 218 | height: 40px; 219 | border-radius: 5px; 220 | font-weight: 400; 221 | letter-spacing: 1.15px; 222 | border: 0.5px solid rgb(177, 177, 177); 223 | color: gray; 224 | background: none; 225 | outline: none; 226 | cursor: pointer; 227 | } 228 | .cart-checkout { 229 | width: 270px; 230 | max-width: 100%; 231 | } 232 | .cart-checkout .subtotal { 233 | display: flex; 234 | justify-content: space-between; 235 | font-size: 20px; 236 | } 237 | .cart-checkout .amount { 238 | font-weight: 700; 239 | } 240 | .cart-checkout p { 241 | font-size: 14px; 242 | font-weight: 200; 243 | margin: 0.5rem 0; 244 | } 245 | .cart-checkout button { 246 | width: 100%; 247 | height: 40px; 248 | border-radius: 5px; 249 | font-weight: 400; 250 | letter-spacing: 1.15px; 251 | background-color: #4b70e2; 252 | color: #f9f9f9; 253 | border: none; 254 | outline: none; 255 | cursor: pointer; 256 | } 257 | 258 | .cart-checkout .cart-login { 259 | background-color: yellow; 260 | color: black; 261 | } 262 | 263 | .continue-shopping, 264 | .start-shopping { 265 | margin-top: 1rem; 266 | } 267 | .continue-shopping a, 268 | .start-shopping a { 269 | color: gray; 270 | text-decoration: none; 271 | display: flex; 272 | align-items: center; 273 | } 274 | .continue-shopping a span, 275 | .start-shopping a span { 276 | margin-left: 0.5rem; 277 | } 278 | .cart-empty { 279 | font-size: 20px; 280 | margin-top: 2rem; 281 | color: rgb(84, 84, 84); 282 | display: flex; 283 | flex-direction: column; 284 | align-items: center; 285 | } 286 | 287 | /* Admin */ 288 | 289 | .link-active { 290 | color: #4b70e2; 291 | } 292 | .link-inactive { 293 | color: rgb(97, 97, 97); 294 | } 295 | 296 | /* Responsive */ 297 | 298 | @media (max-width: 665px) { 299 | /* NavBar */ 300 | .nav-bar { 301 | padding: 0 1rem; 302 | } 303 | .nav-bar h2 { 304 | font-size: 30px; 305 | } 306 | 307 | /* Cart */ 308 | .cart-container { 309 | padding: 2rem; 310 | } 311 | .cart-container .titles { 312 | display: none; 313 | } 314 | .cart-item, 315 | .cart-container .titles { 316 | grid-template-columns: 1fr; 317 | row-gap: 1rem; 318 | } 319 | .cart-item .cart-product-total-price { 320 | justify-self: left; 321 | } 322 | .cart-summary { 323 | flex-direction: column; 324 | } 325 | .cart-summary .clear-btn { 326 | margin-bottom: 2rem; 327 | } 328 | } 329 | --------------------------------------------------------------------------------